zhjwpku commented on code in PR #790:
URL: https://github.com/apache/iceberg-cpp/pull/790#discussion_r3497529844
##########
src/iceberg/test/avro_test.cc:
##########
@@ -806,6 +882,108 @@ TEST_P(AvroWriterTest, WritePrimitiveTypes) {
VerifyWrittenData(test_data);
}
+TEST_P(AvroWriterTest, WriteUuidType) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "uuid_col", iceberg::uuid())});
+
+ auto uuid_array = MakeUuidArray({&kUuidBytes1, &kUuidBytes2});
+ auto array =
+ ::arrow::StructArray::Make(
+ {uuid_array},
+ {::arrow::field("uuid_col", ::arrow::extension::uuid(),
/*nullable=*/false)})
+ .ValueOrDie();
+
+ ArrowArray arrow_array;
+ ASSERT_TRUE(::arrow::ExportArray(*array, &arrow_array).ok());
+
+ WriterProperties writer_properties;
+ writer_properties.Set(WriterProperties::kAvroSkipDatum, skip_datum_);
+
+ ICEBERG_UNWRAP_OR_FAIL(
+ writer_, WriterFactoryRegistry::Open(FileFormatType::kAvro,
+ {.path = temp_avro_file_,
+ .schema = schema,
+ .io = file_io_,
+ .properties =
std::move(writer_properties)}));
+ ASSERT_THAT(writer_->Write(&arrow_array), IsOk());
+ ASSERT_THAT(writer_->Close(), IsOk());
+
+ auto avro_schema = PhysicalAvroSchema();
+ auto root = avro_schema.root();
+ ASSERT_EQ(root->type(), ::avro::AVRO_RECORD);
+ ASSERT_EQ(root->leaves(), 1);
+ auto uuid_node = root->leafAt(0);
+ EXPECT_EQ(uuid_node->type(), ::avro::AVRO_FIXED);
+ EXPECT_EQ(uuid_node->logicalType().type(), ::avro::LogicalType::UUID);
+ EXPECT_EQ(uuid_node->fixedSize(), Uuid::kLength);
+
+ ICEBERG_UNWRAP_OR_FAIL(auto written_length, writer_->length());
+ ICEBERG_UNWRAP_OR_FAIL(
+ auto reader,
+ ReaderFactoryRegistry::Open(FileFormatType::kAvro, {.path =
temp_avro_file_,
+ .length =
written_length,
+ .io = file_io_,
+ .projection =
schema}));
+ ICEBERG_UNWRAP_OR_FAIL(auto data, reader->Next());
+ ASSERT_TRUE(data.has_value());
+
+ ICEBERG_UNWRAP_OR_FAIL(auto arrow_c_schema, reader->Schema());
+ auto read_array = ::arrow::ImportArray(&data.value(),
&arrow_c_schema).ValueOrDie();
+ ASSERT_TRUE(read_array->Equals(*array)) << "actual:\n"
+ << read_array->ToString() <<
"\nexpected:\n"
+ << array->ToString();
+ ASSERT_NO_FATAL_FAILURE(VerifyExhausted(*reader));
+}
+
+TEST_P(AvroWriterTest, WriteUuidListType) {
+ auto schema = std::make_shared<iceberg::Schema>(std::vector<SchemaField>{
+ SchemaField::MakeRequired(1, "uuid_list",
+
std::make_shared<ListType>(SchemaField::MakeRequired(
+ 2, ListType::kElementName,
iceberg::uuid())))});
+
+ auto list_values = MakeUuidArray({&kUuidBytes1, &kUuidBytes2, &kUuidBytes1});
+ auto list_offsets = MakeInt32Array({0, 2, 3});
+ auto list_type =
::arrow::list(::arrow::field(std::string(ListType::kElementName),
+ ::arrow::extension::uuid(),
+ /*nullable=*/false));
+ auto list_array =
+ ::arrow::ListArray::FromArrays(list_type, *list_offsets,
*list_values).ValueOrDie();
+
+ auto array =
+ ::arrow::StructArray::Make(
+ {list_array}, {::arrow::field("uuid_list", list_type,
/*nullable=*/false)})
+ .ValueOrDie();
+
+ ASSERT_NO_FATAL_FAILURE(WriteArrowArrayAndVerify(schema, array));
+}
+
+TEST_P(AvroWriterTest, WriteUuidMapType) {
+ auto schema = std::make_shared<iceberg::Schema>(
+ std::vector<SchemaField>{SchemaField::MakeRequired(
+ 1, "uuid_map",
+ std::make_shared<MapType>(
+ SchemaField::MakeRequired(2, MapType::kKeyName,
iceberg::string()),
+ SchemaField::MakeRequired(3, MapType::kValueName,
iceberg::uuid())))});
+
+ auto map_offsets = MakeInt32Array({0, 2, 3});
+ auto map_keys = MakeStringArray({"first", "second", "only"});
Review Comment:
Add a case, thanks.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]