FANNG1 commented on code in PR #4096:
URL: https://github.com/apache/gravitino/pull/4096#discussion_r1667865401


##########
flink-connector/src/main/java/com/datastrato/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -77,7 +78,7 @@
  * The BaseCatalog that provides a default implementation for all methods in 
the {@link
  * org.apache.flink.table.catalog.Catalog} interface.
  */
-public abstract class BaseCatalog extends AbstractCatalog {
+public abstract class BaseCatalog extends AbstractCatalog implements 
TransformConverter {

Review Comment:
   better to use a specific `transformConverter` like `propertiesConverter`?



##########
flink-connector/src/main/java/com/datastrato/gravitino/flink/connector/TransformConverter.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.datastrato.gravitino.flink.connector;
+
+import com.datastrato.gravitino.rel.expressions.transforms.Transform;
+import com.datastrato.gravitino.rel.expressions.transforms.Transforms;
+import com.google.common.base.Preconditions;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * The TransformConverter is used to convert the partition between Flink and 
Gravitino. The Flink
+ * only support identity transform. Some of the table like Apache Paimon will 
use the table
+ * properties to store the partition transform, so we can implement this 
interface to achieve more
+ * partition transform.
+ */
+public interface TransformConverter {
+  default List<String> toFlinkPartitionKeys(Transform[] transforms) {
+    List<String> partitionKeys =
+        Arrays.stream(transforms)
+            .filter(t -> t instanceof Transforms.IdentityTransform)
+            .map(Transform::name)
+            .collect(Collectors.toList());
+    Preconditions.checkArgument(
+        partitionKeys.size() == transforms.length,
+        "Flink only support identity transform for now.");
+    return partitionKeys;
+  }
+
+  default Transform[] toGravitinoTransforms(List<String> partitionsKey) {

Review Comment:
   `toGravitinoPartitions` to make it more clear?



##########
flink-connector/src/test/java/com/datastrato/gravitino/flink/connector/integration/test/hive/FlinkHiveCatalogIT.java:
##########
@@ -281,6 +291,59 @@ public void testGetCatalogFromGravitino() {
         numCatalogs, tableEnv.listCatalogs().length, "The created catalog 
should be dropped.");
   }
 
+  @Test
+  public void testHivePartitionTable() {
+    String databaseName = "test_create_hive_partition_table_db";
+    String tableName = "test_create_hive_partition_table";
+    String comment = "test comment";
+    String key = "test key";
+    String value = "test value";
+
+    doWithSchema(
+        currentCatalog(),
+        databaseName,
+        catalog -> {
+          TableResult result =
+              sql(
+                  "CREATE TABLE %s "
+                      + "(string_type STRING COMMENT 'string_type', "
+                      + " double_type DOUBLE COMMENT 'double_type')"
+                      + " PARTITIONED BY (string_type, double_type)"
+                      + " COMMENT '%s' WITH ("
+                      + "'%s' = '%s')",
+                  tableName, comment, key, value);
+          TestUtils.assertTableResult(result, ResultKind.SUCCESS);
+
+          Table table =
+              
catalog.asTableCatalog().loadTable(NameIdentifier.of(databaseName, tableName));
+          Assertions.assertNotNull(table);
+          Assertions.assertEquals(comment, table.comment());
+          Assertions.assertEquals(value, table.properties().get(key));
+          Column[] columns =
+              new Column[] {
+                Column.of("string_type", Types.StringType.get(), 
"string_type", true, false, null),
+                Column.of("double_type", Types.DoubleType.get(), "double_type")
+              };
+          assertColumns(columns, table.columns());
+          Transform[] partitions =
+              new Transform[] {
+                Transforms.identity("string_type"), 
Transforms.identity("double_type")
+              };
+          Assertions.assertArrayEquals(partitions, table.partitioning());
+
+          TestUtils.assertTableResult(

Review Comment:
   could you check the partition dir exists?



##########
flink-connector/src/test/java/com/datastrato/gravitino/flink/connector/integration/test/hive/FlinkHiveCatalogIT.java:
##########
@@ -281,6 +291,59 @@ public void testGetCatalogFromGravitino() {
         numCatalogs, tableEnv.listCatalogs().length, "The created catalog 
should be dropped.");
   }
 
+  @Test
+  public void testHivePartitionTable() {
+    String databaseName = "test_create_hive_partition_table_db";
+    String tableName = "test_create_hive_partition_table";
+    String comment = "test comment";
+    String key = "test key";
+    String value = "test value";
+
+    doWithSchema(
+        currentCatalog(),
+        databaseName,
+        catalog -> {
+          TableResult result =
+              sql(
+                  "CREATE TABLE %s "
+                      + "(string_type STRING COMMENT 'string_type', "
+                      + " double_type DOUBLE COMMENT 'double_type')"
+                      + " PARTITIONED BY (string_type, double_type)"
+                      + " COMMENT '%s' WITH ("
+                      + "'%s' = '%s')",
+                  tableName, comment, key, value);
+          TestUtils.assertTableResult(result, ResultKind.SUCCESS);
+
+          Table table =

Review Comment:
   The test covers `create hive partition table path`, but not covers the `load 
hive partition table path` in flink connector, YES?



-- 
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]

Reply via email to