|
25 | 25 | import static org.apache.iceberg.util.DateTimeUtil.timestampFromMicros; |
26 | 26 | import static org.hamcrest.MatcherAssert.assertThat; |
27 | 27 | import static org.junit.Assert.assertEquals; |
| 28 | +import static org.junit.Assert.assertTrue; |
28 | 29 | import static org.junit.Assume.assumeTrue; |
29 | 30 |
|
30 | 31 | import java.time.LocalDate; |
|
62 | 63 | import org.apache.iceberg.CatalogUtil; |
63 | 64 | import org.apache.iceberg.DistributionMode; |
64 | 65 | import org.apache.iceberg.PartitionSpec; |
| 66 | +import org.apache.iceberg.SortDirection; |
| 67 | +import org.apache.iceberg.SortOrder; |
65 | 68 | import org.apache.iceberg.Table; |
66 | 69 | import org.apache.iceberg.catalog.TableIdentifier; |
67 | 70 | import org.apache.iceberg.data.IcebergGenerics; |
@@ -693,4 +696,64 @@ public void testWriteCreateTableWithTableProperties() { |
693 | 696 | assertEquals("5", table.properties().get("commit.retry.num-retries")); |
694 | 697 | assertEquals("134217728", table.properties().get("read.split.target-size")); |
695 | 698 | } |
| 699 | + |
| 700 | + @Test |
| 701 | + public void testDynamicWriteCreateTableWithTableProperties() { |
| 702 | + String identifier = "default.table_" + Long.toString(UUID.randomUUID().hashCode(), 16); |
| 703 | + Schema schema = Schema.builder().addStringField("str").addInt32Field("int").build(); |
| 704 | + |
| 705 | + String customDataPath = warehouse.location + "/custom_data_path"; |
| 706 | + |
| 707 | + Map<String, Object> config = |
| 708 | + ImmutableMap.of( |
| 709 | + "table", |
| 710 | + identifier, |
| 711 | + "catalog_properties", |
| 712 | + ImmutableMap.of("type", "hadoop", "warehouse", warehouse.location), |
| 713 | + "table_properties", |
| 714 | + ImmutableMap.of( |
| 715 | + "write.data.path", |
| 716 | + customDataPath, |
| 717 | + "write.parquet.bloom-filter-enabled.column.int", |
| 718 | + "true"), |
| 719 | + "sort_fields", |
| 720 | + Collections.singletonList("str desc"), |
| 721 | + "partition_fields", |
| 722 | + Collections.singletonList("int")); |
| 723 | + |
| 724 | + List<Row> rows = new ArrayList<>(); |
| 725 | + for (int i = 0; i < 10; i++) { |
| 726 | + Row row = Row.withSchema(schema).addValues("str_" + i, i).build(); |
| 727 | + rows.add(row); |
| 728 | + } |
| 729 | + |
| 730 | + PCollection<Row> result = |
| 731 | + testPipeline |
| 732 | + .apply("Records To Add", Create.of(rows)) |
| 733 | + .setRowSchema(schema) |
| 734 | + .apply(Managed.write(Managed.ICEBERG).withConfig(config)) |
| 735 | + .get(SNAPSHOTS_TAG); |
| 736 | + |
| 737 | + PAssert.that(result) |
| 738 | + .satisfies(new VerifyOutputs(Collections.singletonList(identifier), "append")); |
| 739 | + testPipeline.run().waitUntilFinish(); |
| 740 | + |
| 741 | + Table table = warehouse.loadTable(TableIdentifier.parse(identifier)); |
| 742 | + |
| 743 | + PartitionSpec spec = table.spec(); |
| 744 | + assertTrue(spec.isPartitioned()); |
| 745 | + assertEquals(1, spec.fields().size()); |
| 746 | + assertEquals("int", spec.fields().get(0).name()); |
| 747 | + |
| 748 | + SortOrder sortOrder = table.sortOrder(); |
| 749 | + assertTrue(sortOrder.isSorted()); |
| 750 | + assertEquals(1, sortOrder.fields().size()); |
| 751 | + assertEquals(SortDirection.DESC, sortOrder.fields().get(0).direction()); |
| 752 | + |
| 753 | + assertEquals(customDataPath, table.properties().get("write.data.path")); |
| 754 | + assertEquals("true", table.properties().get("write.parquet.bloom-filter-enabled.column.int")); |
| 755 | + |
| 756 | + List<Record> writtenRecords = ImmutableList.copyOf(IcebergGenerics.read(table).build()); |
| 757 | + assertEquals(10, writtenRecords.size()); |
| 758 | + } |
696 | 759 | } |
0 commit comments