Skip to content

Commit 140c2c6

Browse files
committed
[iceberg] add a test case and make minor documentation fixes
1 parent 33f5fb9 commit 140c2c6

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

docs/content/iceberg/rest-catalog.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ If the two are incompatible, we take the metadata stored in the separate directo
9494

9595
There are some cases when committing to iceberg rest catalog:
9696
1. table not exists in iceberg rest-catalog. It'll create the table in rest catalog first, and commit metadata.
97-
2. table exists in iceberg rest-catalog and is compatible with the base metadata stored in the separate directory. It'll directly get the table and commit metadata.
98-
3. table exists, and last-sequence-number is 0 and current-snapshot-id is -1. It'll treat the table as a new table, directly get the table and commit metadata.
99-
4. table exists, and isn't compatible with the base metadata stored in the separate directory. It'll **drop the table and recreate the table**, then commit metadata.
97+
2. table exists in iceberg rest-catalog and is compatible with the base metadata stored in the separate directory. It'll directly get the table and commit metadata.
98+
3. table exists, and isn't compatible with the base metadata stored in the separate directory. It'll **drop the table and recreate the table**, then commit metadata.
10099

paimon-iceberg/src/test/java/org/apache/paimon/iceberg/IcebergRestMetadataCommitterTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,57 @@ public void testWithIncorrectBase() throws Exception {
557557
commit.close();
558558
}
559559

560+
@Test
561+
public void testWithExistedTableLocation() throws Exception {
562+
RowType rowType =
563+
RowType.of(
564+
new DataType[] {DataTypes.INT(), DataTypes.INT()}, new String[] {"k", "v"});
565+
Map<String, String> dynamicOptions = new HashMap<>();
566+
dynamicOptions.put(
567+
IcebergOptions.METADATA_ICEBERG_STORAGE_LOCATION.key(),
568+
IcebergOptions.StorageLocation.TABLE_LOCATION.toString());
569+
dynamicOptions.put(IcebergOptions.METADATA_ICEBERG_STORAGE.key(), "table-location");
570+
571+
FileStoreTable table =
572+
createPaimonTable(
573+
rowType,
574+
Collections.emptyList(),
575+
Collections.singletonList("k"),
576+
1,
577+
"avro",
578+
Collections.emptyMap())
579+
.copy(dynamicOptions);
580+
581+
String commitUser = UUID.randomUUID().toString();
582+
TableWriteImpl<?> write = table.newWrite(commitUser);
583+
TableCommitImpl commit = table.newCommit(commitUser);
584+
585+
write.write(GenericRow.of(1, 10));
586+
write.write(GenericRow.of(2, 20));
587+
commit.commit(1, write.prepareCommit(false, 1));
588+
assertThat(table.fileIO().exists(new Path(table.location(), "metadata/v1.metadata.json")))
589+
.isTrue();
590+
591+
dynamicOptions.put(IcebergOptions.METADATA_ICEBERG_STORAGE.key(), "rest-catalog");
592+
table = table.copy(dynamicOptions);
593+
write.close();
594+
write = table.newWrite(commitUser);
595+
commit.close();
596+
commit = table.newCommit(commitUser);
597+
598+
write.write(GenericRow.of(1, 11));
599+
write.write(GenericRow.of(3, 30));
600+
write.compact(BinaryRow.EMPTY_ROW, 0, true);
601+
commit.commit(2, write.prepareCommit(true, 2));
602+
assertThat(table.fileIO().exists(new Path(table.location(), "metadata/v3.metadata.json")))
603+
.isTrue();
604+
assertThat(getIcebergResult())
605+
.containsExactlyInAnyOrder("Record(1, 11)", "Record(2, 20)", "Record(3, 30)");
606+
607+
write.close();
608+
commit.close();
609+
}
610+
560611
private static class TestRecord {
561612
private final BinaryRow partition;
562613
private final GenericRow record;

0 commit comments

Comments
 (0)