Skip to content

Commit 14c3fb6

Browse files
committed
feat: add ut for avro
1 parent f914ed7 commit 14c3fb6

6 files changed

Lines changed: 717 additions & 9 deletions

File tree

src/paimon/format/avro/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ if(PAIMON_ENABLE_AVRO)
5050
if(PAIMON_BUILD_TESTS)
5151
add_paimon_test(avro_format_test
5252
SOURCES
53+
avro_direct_encoder_decoder_test.cpp
5354
avro_file_batch_reader_test.cpp
5455
avro_file_format_test.cpp
5556
avro_format_writer_test.cpp

src/paimon/format/avro/avro_direct_decoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ Status DecodeFieldToBuilder(const ::avro::NodePtr& avro_node,
418418

419419
const auto& branch_node = avro_node->leafAt(branch_index);
420420
if (branch_node->type() == ::avro::AVRO_NULL) {
421+
decoder->decodeNull();
421422
PAIMON_RETURN_NOT_OK_FROM_ARROW(array_builder->AppendNull());
422423
return Status::OK();
423424
} else {

src/paimon/format/avro/avro_direct_encoder.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Result<UnionBranches> ValidateUnion(const ::avro::NodePtr& union_node) {
5757
return UnionBranches{.null_index = 0, .value_index = 1, .value_node = branch_1};
5858
}
5959
if (branch_1->type() == ::avro::AVRO_NULL && branch_0->type() != ::avro::AVRO_NULL) {
60-
return UnionBranches{.null_index = 1, .value_index = 0, .value_node = branch_0};
60+
return Status::Invalid(
61+
"Unexpected: In paimon, we expect the null branch to be the first branch in a union.");
6162
}
6263
return Status::Invalid("Union must have exactly one null branch");
6364
}
@@ -92,10 +93,6 @@ Status AvroDirectEncoder::EncodeArrowToAvro(const ::avro::NodePtr& avro_node,
9293
}
9394

9495
switch (avro_node->type()) {
95-
case ::avro::AVRO_NULL:
96-
encoder->encodeNull();
97-
return Status::OK();
98-
9996
case ::avro::AVRO_BOOL: {
10097
const auto& bool_array =
10198
arrow::internal::checked_cast<const arrow::BooleanArray&>(array);
@@ -294,7 +291,7 @@ Status AvroDirectEncoder::EncodeArrowToAvro(const ::avro::NodePtr& avro_node,
294291
element_node->leaves() != 2)) {
295292
return Status::Invalid(
296293
fmt::format("Expected AVRO_RECORD for map key-value pair, got {}",
297-
::avro::toString(element_node->type())));
294+
AvroUtils::ToString(avro_node)));
298295
}
299296

300297
const auto& map_array =
@@ -366,9 +363,11 @@ Status AvroDirectEncoder::EncodeArrowToAvro(const ::avro::NodePtr& avro_node,
366363
return Status::OK();
367364
}
368365

366+
case ::avro::AVRO_NULL:
369367
case ::avro::AVRO_UNION:
370368
// Already handled above
371-
return Status::Invalid("Unexpected union handling");
369+
return Status::Invalid(fmt::format("Unexpected Avro type handling: {}",
370+
::avro::toString(avro_node->type())));
372371
default:
373372
return Status::Invalid(
374373
fmt::format("Unsupported Avro type: {}", ::avro::toString(avro_node->type())));

0 commit comments

Comments
 (0)