gh-yzou commented on code in PR #1231:
URL: https://github.com/apache/polaris/pull/1231#discussion_r2008337714
##########
service/common/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalog.java:
##########
@@ -159,4 +160,44 @@ public GenericTableEntity loadGenericTable(TableIdentifier
tableIdentifier) {
return entity;
}
}
+
+ @SuppressWarnings("FormatStringAnnotation")
Review Comment:
we seems not putting this for other functions, which part of this code is
causing the warning? will we be able to get rid of this suppress?
##########
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/GenericTableCatalogTest.java:
##########
@@ -306,4 +336,166 @@ public void testGenericTableRoundTrip() {
Assertions.assertThat(resultEntity.getPropertiesAsMap()).isEqualTo(properties);
Assertions.assertThat(resultEntity.getName()).isEqualTo(tableName);
}
+
+ @Test
+ public void testLoadNonExistentTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", "t1")))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadIcebergTableAsGeneric() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ icebergCatalog.createTable(TableIdentifier.of("ns", tableName), SCHEMA);
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadIcebergViewAsGeneric() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ icebergCatalog.buildView(TableIdentifier.of("ns", tableName));
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadGenericAsIcebergTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns",
tableName), "format", Map.of());
+ Assertions.assertThatCode(() ->
icebergCatalog.loadTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadGenericAsIcebergView() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns",
tableName), "format", Map.of());
+ Assertions.assertThatCode(() ->
icebergCatalog.loadView(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testListTables() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ for (int i = 0; i < 10; i++) {
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns", "t" +
i), "format", Map.of());
+ }
+
+ List<TableIdentifier> listResult =
genericTableCatalog.listGenericTables(namespace);
+
+ Assertions.assertThat(listResult.size()).isEqualTo(10);
+
Assertions.assertThat(listResult.stream().map(TableIdentifier::toString).toList())
+
.isEqualTo(listResult.stream().map(TableIdentifier::toString).sorted().toList());
+
+ Assertions.assertThat(icebergCatalog.listTables(namespace)).isEmpty();
+ }
+
+ @Test
+ public void testListTablesEmpty() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ for (int i = 0; i < 10; i++) {
+ icebergCatalog.createTable(TableIdentifier.of("ns", "t" + i), SCHEMA);
+ }
+
+
Assertions.assertThat(icebergCatalog.listTables(namespace).size()).isEqualTo(10);
+
Assertions.assertThat(genericTableCatalog.listGenericTables(namespace)).isEmpty();
+ }
+
+ @Test
+ public void testListIcebergTables() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ for (int i = 0; i < 10; i++) {
+ icebergCatalog.createTable(TableIdentifier.of("ns", "t" + i), SCHEMA);
+ }
+
+ List<TableIdentifier> listResult = icebergCatalog.listTables(namespace);
+
+ Assertions.assertThat(listResult.size()).isEqualTo(10);
+
Assertions.assertThat(listResult.stream().map(TableIdentifier::toString).toList())
+
.isEqualTo(listResult.stream().map(TableIdentifier::toString).sorted().toList());
+
+
Assertions.assertThat(genericTableCatalog.listGenericTables(namespace)).isEmpty();
+ }
+
+ @Test
+ public void testDropNonExistentTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.dropGenericTable(TableIdentifier.of("ns", "t1")))
+ .hasMessageContaining("Table does not exist: ns.t1");
+ }
+
+ @Test
+ public void testDropNonExistentNamespace() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.dropGenericTable(TableIdentifier.of("ns2", "t1")))
+ .hasMessageContaining("Table does not exist: ns2.t1");
+ }
+
+ @Test
+ public void testDropIcebergTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+ icebergCatalog.createTable(TableIdentifier.of("ns", "t1"), SCHEMA);
+
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.dropGenericTable(TableIdentifier.of("ns", "t1")))
+ .hasMessageContaining("Table does not exist: ns.t1");
Review Comment:
add a drop with icebergTable to be more clear that the table can be dropped
with iceberg endpoint
##########
service/common/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalog.java:
##########
@@ -159,4 +160,44 @@ public GenericTableEntity loadGenericTable(TableIdentifier
tableIdentifier) {
return entity;
}
}
+
+ @SuppressWarnings("FormatStringAnnotation")
+ public boolean dropGenericTable(TableIdentifier tableIdentifier) {
+ PolarisResolvedPathWrapper resolvedEntities =
+ resolvedEntityView.getPassthroughResolvedPath(
+ tableIdentifier, PolarisEntityType.GENERIC_TABLE,
PolarisEntitySubType.ANY_SUBTYPE);
+
+ if (resolvedEntities == null) {
+ throw new NoSuchTableException("Table does not exist: %s",
tableIdentifier);
Review Comment:
Maybe we can say "Generic table does not exist", so that it is more clear to
the user that it is the generic table does not exist, and it may in the iceberg
tables.
##########
service/common/src/main/java/org/apache/polaris/service/catalog/generic/GenericTableCatalog.java:
##########
@@ -159,4 +160,44 @@ public GenericTableEntity loadGenericTable(TableIdentifier
tableIdentifier) {
return entity;
}
}
+
+ @SuppressWarnings("FormatStringAnnotation")
+ public boolean dropGenericTable(TableIdentifier tableIdentifier) {
+ PolarisResolvedPathWrapper resolvedEntities =
+ resolvedEntityView.getPassthroughResolvedPath(
+ tableIdentifier, PolarisEntityType.GENERIC_TABLE,
PolarisEntitySubType.ANY_SUBTYPE);
+
+ if (resolvedEntities == null) {
+ throw new NoSuchTableException("Table does not exist: %s",
tableIdentifier);
+ }
+
+ List<PolarisEntity> catalogPath = resolvedEntities.getRawParentPath();
+ PolarisEntity leafEntity = resolvedEntities.getRawLeafEntity();
+
+ DropEntityResult dropEntityResult =
+ this.metaStoreManager.dropEntityIfExists(
+ this.callContext.getPolarisCallContext(),
+ PolarisEntity.toCoreList(catalogPath),
+ leafEntity,
+ Map.of(),
+ false);
+
+ return dropEntityResult.isSuccess();
+ }
+
+ public List<TableIdentifier> listGenericTables(Namespace namespace) {
+ PolarisResolvedPathWrapper resolvedEntities =
resolvedEntityView.getResolvedPath(namespace);
Review Comment:
shall we do similar check as iceberg list tables check if resolvedEntities
== null, and throw an namespace not exist error ?
##########
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/GenericTableCatalogTest.java:
##########
@@ -120,6 +136,11 @@ public Map<String, String> getConfigOverrides() {
private PolarisEntity catalogEntity;
private SecurityContext securityContext;
+ protected static final Schema SCHEMA =
+ new Schema(
+ required(3, "id", Types.IntegerType.get(), "unique ID 🤪"),
Review Comment:
Can we remove the emoji?
##########
quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/GenericTableCatalogTest.java:
##########
@@ -306,4 +336,166 @@ public void testGenericTableRoundTrip() {
Assertions.assertThat(resultEntity.getPropertiesAsMap()).isEqualTo(properties);
Assertions.assertThat(resultEntity.getName()).isEqualTo(tableName);
}
+
+ @Test
+ public void testLoadNonExistentTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", "t1")))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadIcebergTableAsGeneric() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ icebergCatalog.createTable(TableIdentifier.of("ns", tableName), SCHEMA);
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadIcebergViewAsGeneric() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ icebergCatalog.buildView(TableIdentifier.of("ns", tableName));
+ Assertions.assertThatCode(
+ () ->
genericTableCatalog.loadGenericTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadGenericAsIcebergTable() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns",
tableName), "format", Map.of());
+ Assertions.assertThatCode(() ->
icebergCatalog.loadTable(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testReadGenericAsIcebergView() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ String tableName = "t1";
+
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns",
tableName), "format", Map.of());
+ Assertions.assertThatCode(() ->
icebergCatalog.loadView(TableIdentifier.of("ns", tableName)))
+ .hasMessageContaining("does not exist: ns.t1");
+ }
+
+ @Test
+ public void testListTables() {
+ Namespace namespace = Namespace.of("ns");
+ icebergCatalog.createNamespace(namespace);
+
+ for (int i = 0; i < 10; i++) {
+ genericTableCatalog.createGenericTable(TableIdentifier.of("ns", "t" +
i), "format", Map.of());
Review Comment:
can we also create some iceberg tables in the catalog, so that it is more
clear that it is only listing the Generic tables?
--
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]