dongxiao1198 commented on code in PR #105:
URL: https://github.com/apache/iceberg-cpp/pull/105#discussion_r2099742048


##########
src/iceberg/avro/avro_stream_internal.cc:
##########
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "avro_stream_internal.h"
+
+#include <format>
+
+#include <arrow/result.h>
+
+#include "iceberg/exception.h"
+
+namespace iceberg::avro {
+
+AvroInputStream::AvroInputStream(
+    std::shared_ptr<arrow::io::RandomAccessFile> input_stream, int64_t 
buffer_size)
+    : input_stream_(std::move(input_stream)),
+      buffer_size_(buffer_size),
+      buffer_(buffer_size) {}
+
+AvroInputStream::~AvroInputStream() = default;
+
+bool AvroInputStream::next(const uint8_t** data, size_t* len) {
+  // Return all unconsumed data in the buffer
+  if (buffer_pos_ < available_bytes_) {
+    *data = buffer_.data() + buffer_pos_;
+    *len = available_bytes_ - buffer_pos_;
+    byte_count_ += available_bytes_ - buffer_pos_;
+    buffer_pos_ = available_bytes_;
+    return true;
+  }
+
+  // Read from the input stream when the buffer is empty
+  auto result = input_stream_->Read(buffer_.size(), buffer_.data());
+  if (!result.ok()) {
+    throw IcebergError(

Review Comment:
   I found this doc in avro header:
       /**
        * Returns some of available data.
        *
        * Returns true if some data is available, false if no more data is
        * available or an error has occurred.
        */
       virtual bool next(const uint8_t **data, size_t *len) = 0;
   
   that's right ,i will fix this. 
   But since we have no logging system now, just return false will ignore the 
error msg and nobody can find out the root cause, so i will leave a TODO here 
to add some error log to debug error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to