Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/iceberg/avro/avro_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class AvroReader::Impl {
read_schema_ = options.projection;

// Open the input stream and adapt to the avro interface.
// TODO(gangwu): make this configurable
constexpr int64_t kDefaultBufferSize = 1024 * 1024;
ICEBERG_ASSIGN_OR_RAISE(auto input_stream,
CreateInputStream(options, kDefaultBufferSize));
ICEBERG_ASSIGN_OR_RAISE(
auto input_stream,
CreateInputStream(options,
options.properties->Get(ReaderProperties::kAvroBufferSize)));

::avro::ValidSchema file_schema;

Expand Down
3 changes: 3 additions & 0 deletions src/iceberg/file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class ReaderProperties : public ConfigBase<ReaderProperties> {
/// Default: true (skip GenericDatum for better performance).
inline static Entry<bool> kAvroSkipDatum{"read.avro.skip-datum", true};

/// \brief The buffer size used by Avro input stream.
inline static Entry<int64_t> kAvroBufferSize{"read.avro.buffer-size", 1024 * 1024};

/// \brief Create a default ReaderProperties instance.
static std::unique_ptr<ReaderProperties> default_properties();

Expand Down
23 changes: 23 additions & 0 deletions src/iceberg/test/avro_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,27 @@ INSTANTIATE_TEST_SUITE_P(DirectDecoderModes, AvroReaderParameterizedTest,
return info.param ? "DirectDecoder" : "GenericDatum";
});

TEST_F(AvroReaderTest, BufferSizeConfiguration) {
// Test default buffer size
auto properties1 = ReaderProperties::default_properties();
ASSERT_EQ(properties1->Get(ReaderProperties::kAvroBufferSize), 1024 * 1024);

// Test setting custom buffer size
auto properties2 = ReaderProperties::default_properties();
constexpr int64_t kCustomBufferSize = 2 * 1024 * 1024; // 2MB
properties2->Set(ReaderProperties::kAvroBufferSize, kCustomBufferSize);
ASSERT_EQ(properties2->Get(ReaderProperties::kAvroBufferSize), kCustomBufferSize);

// Test setting via FromMap
std::unordered_map<std::string, std::string> config_map = {
{"read.avro.buffer-size", "4194304"} // 4MB
};
auto properties3 = ReaderProperties::FromMap(config_map);
ASSERT_EQ(properties3->Get(ReaderProperties::kAvroBufferSize), 4194304);

// Test that unset returns to default
properties2->Unset(ReaderProperties::kAvroBufferSize);
ASSERT_EQ(properties2->Get(ReaderProperties::kAvroBufferSize), 1024 * 1024);
}

} // namespace iceberg::avro
Loading