caican00 commented on code in PR #4288:
URL: https://github.com/apache/gravitino/pull/4288#discussion_r1696217613
##########
catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java:
##########
@@ -283,6 +286,109 @@ void testCreateAndLoadPaimonTable()
sortOrders));
}
+ @Test
+ void testCreateAndLoadPaimonPartitionedTable()
+ throws org.apache.paimon.catalog.Catalog.TableNotExistException {
+ // Create table from Gravitino API
+ Column[] columns = createColumns();
+
+ NameIdentifier tableIdentifier = NameIdentifier.of(schemaName, tableName);
+ Distribution distribution = Distributions.NONE;
+
+ Transform[] partitioning =
+ new Transform[] {identity(PAIMON_COL_NAME1),
identity(PAIMON_COL_NAME3)};
+ String[] partitionKeys = new String[] {PAIMON_COL_NAME1, PAIMON_COL_NAME3};
+ SortOrder[] sortOrders = SortOrders.NONE;
+ Map<String, String> properties = createProperties();
+ TableCatalog tableCatalog = catalog.asTableCatalog();
+ Table createdTable =
+ tableCatalog.createTable(
+ tableIdentifier,
+ columns,
+ table_comment,
+ properties,
+ partitioning,
+ distribution,
+ sortOrders);
+ Assertions.assertEquals(createdTable.name(), tableName);
+ Map<String, String> resultProp = createdTable.properties();
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ Assertions.assertTrue(resultProp.containsKey(entry.getKey()));
+ Assertions.assertEquals(entry.getValue(),
resultProp.get(entry.getKey()));
+ }
+ Assertions.assertEquals(createdTable.comment(), table_comment);
+ Assertions.assertArrayEquals(partitioning, createdTable.partitioning());
+ Assertions.assertEquals(createdTable.columns().length, columns.length);
+
+ for (int i = 0; i < columns.length; i++) {
+ Assertions.assertEquals(DTOConverters.toDTO(columns[i]),
createdTable.columns()[i]);
+ }
+
+ Table loadTable = tableCatalog.loadTable(tableIdentifier);
+ Assertions.assertEquals(tableName, loadTable.name());
+ Assertions.assertEquals(table_comment, loadTable.comment());
+ resultProp = loadTable.properties();
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ Assertions.assertTrue(resultProp.containsKey(entry.getKey()));
+ Assertions.assertEquals(entry.getValue(),
resultProp.get(entry.getKey()));
+ }
+ Assertions.assertArrayEquals(partitioning, loadTable.partitioning());
+ String[] loadedPartitionKeys =
+ Arrays.stream(loadTable.partitioning())
+ .map(
+ transform -> {
+ NamedReference[] references = transform.references();
+ Assertions.assertTrue(
+ references.length == 1
+ && references[0] instanceof
NamedReference.FieldReference);
+ NamedReference.FieldReference fieldReference =
+ (NamedReference.FieldReference) references[0];
+ return fieldReference.fieldName()[0];
+ })
+ .toArray(String[]::new);
+ Assertions.assertArrayEquals(partitionKeys, loadedPartitionKeys);
+ Assertions.assertEquals(loadTable.columns().length, columns.length);
+ for (int i = 0; i < columns.length; i++) {
+ Assertions.assertEquals(DTOConverters.toDTO(columns[i]),
loadTable.columns()[i]);
+ }
+
+ // catalog load check
+ org.apache.paimon.table.Table table =
+ paimonCatalog.getTable(Identifier.create(schemaName, tableName));
+ Assertions.assertEquals(tableName, table.name());
+ Assertions.assertTrue(table.comment().isPresent());
+ Assertions.assertEquals(table_comment, table.comment().get());
+ resultProp = table.options();
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ Assertions.assertTrue(resultProp.containsKey(entry.getKey()));
+ Assertions.assertEquals(entry.getValue(),
resultProp.get(entry.getKey()));
+ }
+ Assertions.assertArrayEquals(partitionKeys,
table.partitionKeys().toArray(new String[0]));
+ Assertions.assertInstanceOf(FileStoreTable.class, table);
+ FileStoreTable fileStoreTable = (FileStoreTable) table;
+
+ TableSchema schema = fileStoreTable.schema();
+ Assertions.assertEquals(schema.fields().size(), columns.length);
+ for (int i = 0; i < columns.length; i++) {
+ Assertions.assertEquals(columns[i].name(), schema.fieldNames().get(i));
+ }
+ Assertions.assertArrayEquals(partitionKeys,
schema.partitionKeys().toArray(new String[0]));
+
+ Assertions.assertThrows(
Review Comment:
updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]