|
24 | 24 | #include "arrow/api.h" |
25 | 25 | #include "gtest/gtest.h" |
26 | 26 | #include "paimon/common/data/blob_utils.h" |
| 27 | +#include "paimon/common/data/variant/variant_type_utils.h" |
27 | 28 | #include "paimon/core/schema/table_schema.h" |
28 | 29 | #include "paimon/defs.h" |
29 | 30 | #include "paimon/testing/utils/testharness.h" |
@@ -109,6 +110,74 @@ TEST(SchemaValidationTest, TestVectorType) { |
109 | 110 | "VECTOR fields in data-evolution tables are not implemented yet."); |
110 | 111 | } |
111 | 112 |
|
| 113 | +#ifdef PAIMON_ENABLE_MOSAIC |
| 114 | +TEST(SchemaValidationTest, TestMosaicDataTypes) { |
| 115 | + std::map<std::string, std::string> options = {{Options::BUCKET, "-1"}, |
| 116 | + {Options::FILE_FORMAT, "mosaic"}}; |
| 117 | + arrow::FieldVector supported_fields = { |
| 118 | + arrow::field("f0", arrow::boolean()), |
| 119 | + arrow::field("f1", arrow::int8()), |
| 120 | + arrow::field("f2", arrow::int16()), |
| 121 | + arrow::field("f3", arrow::int32()), |
| 122 | + arrow::field("f4", arrow::int64()), |
| 123 | + arrow::field("f5", arrow::float32()), |
| 124 | + arrow::field("f6", arrow::float64()), |
| 125 | + arrow::field("f7", arrow::utf8()), |
| 126 | + arrow::field("f8", arrow::binary()), |
| 127 | + arrow::field("f9", arrow::date32()), |
| 128 | + arrow::field("f10", arrow::timestamp(arrow::TimeUnit::NANO)), |
| 129 | + arrow::field("f11", arrow::decimal128(38, 2)), |
| 130 | + arrow::field("f12", arrow::list(arrow::float32())), |
| 131 | + arrow::field("f13", arrow::map(arrow::int8(), arrow::int16())), |
| 132 | + }; |
| 133 | + ASSERT_OK_AND_ASSIGN(std::shared_ptr<TableSchema> table_schema, |
| 134 | + TableSchema::Create(/*schema_id=*/0, arrow::schema(supported_fields), |
| 135 | + /*partition_keys=*/{}, /*primary_keys=*/{}, options)); |
| 136 | + ASSERT_OK(SchemaValidation::ValidateTableSchema(*table_schema)); |
| 137 | + |
| 138 | + arrow::FieldVector unsupported_fields = { |
| 139 | + arrow::field("row", arrow::struct_({arrow::field("value", arrow::int32())})), |
| 140 | + VariantTypeUtils::ToArrowField("variant"), |
| 141 | + arrow::field("vector", arrow::fixed_size_list(arrow::float32(), 3)), |
| 142 | + arrow::field("nested_row", |
| 143 | + arrow::list(arrow::struct_({arrow::field("value", arrow::int32())}))), |
| 144 | + }; |
| 145 | + std::vector<std::string> expected_errors = {"type ROW", "type VARIANT", "type VECTOR", |
| 146 | + "type ROW"}; |
| 147 | + for (size_t i = 0; i < unsupported_fields.size(); ++i) { |
| 148 | + SCOPED_TRACE("field=" + unsupported_fields[i]->name()); |
| 149 | + ASSERT_OK_AND_ASSIGN( |
| 150 | + table_schema, |
| 151 | + TableSchema::Create(/*schema_id=*/0, arrow::schema({unsupported_fields[i]}), |
| 152 | + /*partition_keys=*/{}, /*primary_keys=*/{}, options)); |
| 153 | + ASSERT_NOK_WITH_MSG(SchemaValidation::ValidateTableSchema(*table_schema), |
| 154 | + expected_errors[i]); |
| 155 | + } |
| 156 | + |
| 157 | + std::shared_ptr<arrow::Field> blob_field = BlobUtils::ToArrowField("blob", false); |
| 158 | + std::map<std::string, std::string> blob_options = { |
| 159 | + {Options::BUCKET, "-1"}, |
| 160 | + {Options::FILE_FORMAT, "mosaic"}, |
| 161 | + {Options::ROW_TRACKING_ENABLED, "true"}, |
| 162 | + {Options::DATA_EVOLUTION_ENABLED, "true"}, |
| 163 | + }; |
| 164 | + ASSERT_OK_AND_ASSIGN( |
| 165 | + table_schema, |
| 166 | + TableSchema::Create(/*schema_id=*/0, |
| 167 | + arrow::schema({arrow::field("id", arrow::int32()), blob_field}), |
| 168 | + /*partition_keys=*/{}, /*primary_keys=*/{}, blob_options)); |
| 169 | + ASSERT_OK(SchemaValidation::ValidateTableSchema(*table_schema)); |
| 170 | + |
| 171 | + blob_options[Options::BLOB_DESCRIPTOR_FIELD] = "blob"; |
| 172 | + ASSERT_OK_AND_ASSIGN( |
| 173 | + table_schema, |
| 174 | + TableSchema::Create(/*schema_id=*/0, |
| 175 | + arrow::schema({arrow::field("id", arrow::int32()), blob_field}), |
| 176 | + /*partition_keys=*/{}, /*primary_keys=*/{}, blob_options)); |
| 177 | + ASSERT_NOK_WITH_MSG(SchemaValidation::ValidateTableSchema(*table_schema), "type BLOB"); |
| 178 | +} |
| 179 | +#endif |
| 180 | + |
112 | 181 | TEST(SchemaValidationTest, TestRowTracking) { |
113 | 182 | auto f0 = arrow::field("f0", arrow::utf8()); |
114 | 183 | auto f1 = arrow::field("f1", arrow::int32()); |
|
0 commit comments