|
24 | 24 |
|
25 | 25 | #include <gmock/gmock.h> |
26 | 26 | #include <gtest/gtest.h> |
| 27 | +#include <nlohmann/json.hpp> |
27 | 28 |
|
| 29 | +#include "iceberg/json_internal.h" |
28 | 30 | #include "iceberg/partition_field.h" |
29 | 31 | #include "iceberg/schema.h" |
30 | 32 | #include "iceberg/schema_field.h" |
@@ -106,4 +108,54 @@ TEST(PartitionSpecTest, PartitionSchemaTest) { |
106 | 108 | EXPECT_EQ(pt_field2.name(), partition_schema.value()->fields()[1].name()); |
107 | 109 | EXPECT_EQ(pt_field2.field_id(), partition_schema.value()->fields()[1].field_id()); |
108 | 110 | } |
| 111 | + |
| 112 | +TEST(PartitionSpecTest, PartitionTypeTest) { |
| 113 | + nlohmann::json json = R"( |
| 114 | + { |
| 115 | + "spec-id": 1, |
| 116 | + "fields": [ { |
| 117 | + "source-id": 4, |
| 118 | + "field-id": 1000, |
| 119 | + "name": "ts_day", |
| 120 | + "transform": "day" |
| 121 | + }, { |
| 122 | + "source-id": 1, |
| 123 | + "field-id": 1001, |
| 124 | + "name": "id_bucket", |
| 125 | + "transform": "bucket[16]" |
| 126 | + }, { |
| 127 | + "source-id": 2, |
| 128 | + "field-id": 1002, |
| 129 | + "name": "id_truncate", |
| 130 | + "transform": "truncate[4]" |
| 131 | + } ] |
| 132 | + })"_json; |
| 133 | + |
| 134 | + SchemaField field1(1, "id", int32(), false); |
| 135 | + SchemaField field2(2, "name", string(), false); |
| 136 | + SchemaField field3(3, "ts", timestamp(), false); |
| 137 | + SchemaField field4(4, "ts_day", timestamp(), false); |
| 138 | + SchemaField field5(5, "id_bucket", int32(), false); |
| 139 | + SchemaField field6(6, "id_truncate", int32(), false); |
| 140 | + auto const schema = std::make_shared<Schema>( |
| 141 | + std::vector<SchemaField>{field1, field2, field3, field4, field5, field6}, |
| 142 | + Schema::kInitialSchemaId); |
| 143 | + |
| 144 | + auto parsed_spec_result = PartitionSpecFromJson(schema, json); |
| 145 | + ASSERT_TRUE(parsed_spec_result.has_value()) << parsed_spec_result.error().message; |
| 146 | + |
| 147 | + auto partition_schema = parsed_spec_result.value()->PartitionType(); |
| 148 | + |
| 149 | + SchemaField pt_field1(1000, "ts_day", date(), true); |
| 150 | + SchemaField pt_field2(1001, "id_bucket", int32(), true); |
| 151 | + SchemaField pt_field3(1002, "id_truncate", string(), true); |
| 152 | + |
| 153 | + ASSERT_TRUE(partition_schema.has_value()); |
| 154 | + ASSERT_EQ(3, partition_schema.value()->fields().size()); |
| 155 | + |
| 156 | + EXPECT_EQ(pt_field1, partition_schema.value()->fields()[0]); |
| 157 | + EXPECT_EQ(pt_field2, partition_schema.value()->fields()[1]); |
| 158 | + EXPECT_EQ(pt_field3, partition_schema.value()->fields()[2]); |
| 159 | +} |
| 160 | + |
109 | 161 | } // namespace iceberg |
0 commit comments