|
28 | 28 |
|
29 | 29 | #include "iceberg/json_internal.h" |
30 | 30 | #include "iceberg/partition_field.h" |
| 31 | +#include "iceberg/row/partition_values.h" |
31 | 32 | #include "iceberg/schema.h" |
32 | 33 | #include "iceberg/schema_field.h" |
33 | 34 | #include "iceberg/test/matchers.h" |
@@ -425,4 +426,52 @@ TEST(PartitionSpecTest, ValidateRedundantPartitionsIdentityTransforms) { |
425 | 426 | } |
426 | 427 | } |
427 | 428 |
|
| 429 | +TEST(PartitionSpecTest, PartitionPath) { |
| 430 | + // Create a schema with different field types |
| 431 | + auto id_field = SchemaField::MakeRequired(1, "id", int64()); |
| 432 | + auto name_field = SchemaField::MakeRequired(2, "name", string()); |
| 433 | + auto ts_field = SchemaField::MakeRequired(3, "ts", timestamp()); |
| 434 | + Schema schema({id_field, name_field, ts_field}, Schema::kInitialSchemaId); |
| 435 | + |
| 436 | + // Create partition fields |
| 437 | + PartitionField id_field_partition(1, 1000, "id_partition", Transform::Identity()); |
| 438 | + PartitionField name_field_partition(2, 1001, "name_partition", Transform::Identity()); |
| 439 | + PartitionField ts_field_partition(3, 1002, "ts_partition", Transform::Day()); |
| 440 | + |
| 441 | + // Create partition spec |
| 442 | + ICEBERG_UNWRAP_OR_FAIL( |
| 443 | + auto spec, |
| 444 | + PartitionSpec::Make(schema, 1, |
| 445 | + {id_field_partition, name_field_partition, ts_field_partition}, |
| 446 | + false)); |
| 447 | + |
| 448 | + { |
| 449 | + // Invalid partition values |
| 450 | + PartitionValues part_data({Literal::Int(123)}); |
| 451 | + auto result = spec->PartitionPath(part_data); |
| 452 | + EXPECT_THAT(result, IsError(ErrorKind::kInvalidArgument)); |
| 453 | + EXPECT_THAT(result, HasErrorMessage("Partition spec and data mismatch")); |
| 454 | + } |
| 455 | + |
| 456 | + { |
| 457 | + // Normal partition values |
| 458 | + PartitionValues part_data( |
| 459 | + {Literal::Int(123), Literal::String("val2"), Literal::Date(19489)}); |
| 460 | + ICEBERG_UNWRAP_OR_FAIL(auto path, spec->PartitionPath(part_data)); |
| 461 | + std::string expected = |
| 462 | + "id_partition=123/name_partition=%22val2%22/ts_partition=19489"; |
| 463 | + EXPECT_EQ(expected, path); |
| 464 | + } |
| 465 | + |
| 466 | + { |
| 467 | + // Partition values with special characters |
| 468 | + PartitionValues part_data( |
| 469 | + {Literal::Int(123), Literal::String("val#2"), Literal::Date(19489)}); |
| 470 | + ICEBERG_UNWRAP_OR_FAIL(auto path, spec->PartitionPath(part_data)); |
| 471 | + std::string expected = |
| 472 | + "id_partition=123/name_partition=%22val%232%22/ts_partition=19489"; |
| 473 | + EXPECT_EQ(expected, path); |
| 474 | + } |
| 475 | +} |
| 476 | + |
428 | 477 | } // namespace iceberg |
0 commit comments