You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "hdygxsj (via GitHub)" <gi...@apache.org> on 2025/01/23 16:46:39 UTC

[PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

hdygxsj opened a new pull request, #6362:
URL: https://github.com/apache/gravitino/pull/6362

   
   ### What changes were proposed in this pull request?
   
   Support specifying primary keys during create paimon table by flink
   
   ### Why are the changes needed?
   
   
   Fix: #6361 
   
   ### Does this PR introduce _any_ user-facing change?
   
   None
   
   ### How was this patch tested?
   
   Add testCreateTableWithPrimaryKey case in org.apache.gravitino.flink.connector.integration.test.FlinkCommonIT
   


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "tengqm (via GitHub)" <gi...@apache.org>.
tengqm commented on PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#issuecomment-2653082160

   No objections from me.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929706278


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java:
##########
@@ -137,21 +137,10 @@ private List<String> getPrimaryKeysFromIndexes(Index[] indexes) {
     if (indexes == null || indexes.length == 0) {
       return Collections.emptyList();
     }
-
     Preconditions.checkArgument(
         indexes.length == 1, "Paimon only supports no more than one Index.");
-
     Index primaryKeyIndex = indexes[0];
-    Arrays.stream(primaryKeyIndex.fieldNames())

Review Comment:
   any reason to remove this? does Paimon support the nested column as the Primary key?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929704262


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -289,6 +308,18 @@ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ig
     }
   }
 
+  private static Index[] getIndices(ResolvedCatalogBaseTable<?> resolvedTable) {
+    Optional<UniqueConstraint> primaryKey = resolvedTable.getResolvedSchema().getPrimaryKey();
+    List<String> primaryColumns = primaryKey.map(UniqueConstraint::getColumns).orElse(null);
+    if (primaryColumns == null) {
+      return new Index[0];
+    }
+    String[][] primaryField =
+        primaryColumns.stream().map(e -> new String[] {e}).toArray(String[][]::new);

Review Comment:
   replace `e` with `primaryColumn`?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929705552


##########
flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/FlinkCommonIT.java:
##########
@@ -80,6 +81,10 @@ protected boolean supportGetSchemaWithoutCommentAndOption() {
 
   protected abstract boolean supportDropCascade();
 
+  protected boolean supportCreateTableWithPrimaryKey() {

Review Comment:
   rename to supportsPrimaryKey?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929705476


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,6 +552,11 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    Index[] indices = table.index();
+    if (indices != null && indices.length == 1) {
+      builder.primaryKey(
+          Arrays.stream(indices[0].fieldNames()).map(arr -> arr[0]).collect(Collectors.toList()));

Review Comment:
   Please use an more meaningful name for `arr`



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 merged PR #6362:
URL: https://github.com/apache/gravitino/pull/6362


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1950845159


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -554,28 +554,31 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
-    handleFlinkPrimaryKey(table, builder);
+    Optional<List<String>> flinkPrimaryKey = getFlinkPrimaryKey(table);
+    flinkPrimaryKey.ifPresent(builder::primaryKey);
     Map<String, String> flinkTableProperties =
         propertiesConverter.toFlinkTableProperties(table.properties());
     List<String> partitionKeys = partitionConverter.toFlinkPartitionKeys(table.partitioning());
     return CatalogTable.of(builder.build(), table.comment(), partitionKeys, flinkTableProperties);
   }
 
-  private static void handleFlinkPrimaryKey(
-      Table table, org.apache.flink.table.api.Schema.Builder builder) {
+  private static Optional<List<String>> getFlinkPrimaryKey(Table table) {
     List<Index> primaryKeyList =
         Arrays.stream(table.index())
             .filter(index -> index.type() == Index.IndexType.PRIMARY_KEY)
             .collect(Collectors.toList());
     if (primaryKeyList.isEmpty()) {
-      return;
+      return Optional.empty();
     }
     Preconditions.checkArgument(
         primaryKeyList.size() == 1, "More than one primary key is not supported.");
-    builder.primaryKey(
+    List<String> primaryKeyFieldList =
         Arrays.stream(primaryKeyList.get(0).fieldNames())
             .map(fieldNames -> fieldNames[0])

Review Comment:
   done



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929703127


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java:
##########
@@ -137,21 +137,10 @@ private List<String> getPrimaryKeysFromIndexes(Index[] indexes) {
     if (indexes == null || indexes.length == 0) {
       return Collections.emptyList();
     }
-
     Preconditions.checkArgument(
         indexes.length == 1, "Paimon only supports no more than one Index.");
-
     Index primaryKeyIndex = indexes[0];
-    Arrays.stream(primaryKeyIndex.fieldNames())

Review Comment:
   any reason for removing the check?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929677883


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,6 +552,11 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    Index[] indices = table.index();
+    if (indices != null && indices.length == 1) {

Review Comment:
   No. His meaning is that only one primary key is supported. The Index object also stores field information and there can be multiple fields.
   ![image](https://github.com/user-attachments/assets/22e2d49a-edae-40f2-aad1-6bb9a6b2f1f4)
   



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1950099772


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,12 +554,30 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    handleFlinkPrimaryKey(table, builder);
     Map<String, String> flinkTableProperties =
         propertiesConverter.toFlinkTableProperties(table.properties());
     List<String> partitionKeys = partitionConverter.toFlinkPartitionKeys(table.partitioning());
     return CatalogTable.of(builder.build(), table.comment(), partitionKeys, flinkTableProperties);
   }
 
+  private static void handleFlinkPrimaryKey(

Review Comment:
   done



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#issuecomment-2655284596

   merged to main, thanks @hdygxsj for the PR and @tengqm for the review.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1928269016


##########
flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/FlinkCommonIT.java:
##########
@@ -280,6 +281,69 @@ public void testCreateSimpleTable() {
         supportDropCascade());
   }
 
+  @Test
+  @EnabledIf("supportTableOperation")
+  public void testCreateTableWithPrimaryKey() {

Review Comment:
   I'm afraid Hive or Iceberg doesn't support Specifying Primary key.  maybe we could move this test to Paimon IT only. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#issuecomment-2652376661

   LGTM


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929703127


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java:
##########
@@ -137,21 +137,10 @@ private List<String> getPrimaryKeysFromIndexes(Index[] indexes) {
     if (indexes == null || indexes.length == 0) {
       return Collections.emptyList();
     }
-
     Preconditions.checkArgument(
         indexes.length == 1, "Paimon only supports no more than one Index.");
-
     Index primaryKeyIndex = indexes[0];
-    Arrays.stream(primaryKeyIndex.fieldNames())

Review Comment:
   any reason for removing the check?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#issuecomment-2614685563

   LGTM except minior comments


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929705331


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,6 +552,11 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    Index[] indices = table.index();

Review Comment:
   Could you add a check here, the index array contains at more one index, and it should be Primary index.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1950147563


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -554,28 +554,31 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
-    handleFlinkPrimaryKey(table, builder);
+    Optional<List<String>> flinkPrimaryKey = getFlinkPrimaryKey(table);
+    flinkPrimaryKey.ifPresent(builder::primaryKey);
     Map<String, String> flinkTableProperties =
         propertiesConverter.toFlinkTableProperties(table.properties());
     List<String> partitionKeys = partitionConverter.toFlinkPartitionKeys(table.partitioning());
     return CatalogTable.of(builder.build(), table.comment(), partitionKeys, flinkTableProperties);
   }
 
-  private static void handleFlinkPrimaryKey(
-      Table table, org.apache.flink.table.api.Schema.Builder builder) {
+  private static Optional<List<String>> getFlinkPrimaryKey(Table table) {
     List<Index> primaryKeyList =
         Arrays.stream(table.index())
             .filter(index -> index.type() == Index.IndexType.PRIMARY_KEY)
             .collect(Collectors.toList());
     if (primaryKeyList.isEmpty()) {
-      return;
+      return Optional.empty();
     }
     Preconditions.checkArgument(
         primaryKeyList.size() == 1, "More than one primary key is not supported.");
-    builder.primaryKey(
+    List<String> primaryKeyFieldList =
         Arrays.stream(primaryKeyList.get(0).fieldNames())
             .map(fieldNames -> fieldNames[0])

Review Comment:
   could you check the size of `fieldNames`?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1928272302


##########
server/build.gradle.kts:
##########
@@ -28,6 +28,7 @@ dependencies {
   implementation(project(":common"))
   implementation(project(":core"))
   implementation(project(":server-common"))
+  implementation(libs.mysql.driver)

Review Comment:
   please remove this, Gravitino server doesn't rely on mysql.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929703228


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/GravitinoPaimonTable.java:
##########
@@ -137,21 +137,10 @@ private List<String> getPrimaryKeysFromIndexes(Index[] indexes) {
     if (indexes == null || indexes.length == 0) {
       return Collections.emptyList();
     }
-
     Preconditions.checkArgument(
         indexes.length == 1, "Paimon only supports no more than one Index.");
-
     Index primaryKeyIndex = indexes[0];
-    Arrays.stream(primaryKeyIndex.fieldNames())
-        .forEach(
-            filedName ->
-                Preconditions.checkArgument(
-                    filedName != null && filedName.length == 1,
-                    "The primary key columns should not be nested."));
-
-    return Arrays.stream(primaryKeyIndex.fieldNames())
-        .map(fieldName -> fieldName[0])
-        .collect(Collectors.toList());
+    return Arrays.stream(primaryKeyIndex.fieldNames()).map(e -> e[0]).collect(Collectors.toList());

Review Comment:
   comparing to `e`, `fieldName` is more meaningful.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929677883


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,6 +552,11 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    Index[] indices = table.index();
+    if (indices != null && indices.length == 1) {

Review Comment:
   No. this means that only one primary key is supported. The Index object also stores field information and there can be multiple fields.
   ![image](https://github.com/user-attachments/assets/22e2d49a-edae-40f2-aad1-6bb9a6b2f1f4)
   



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929705761


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -289,6 +308,18 @@ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ig
     }
   }
 
+  private static Index[] getIndices(ResolvedCatalogBaseTable<?> resolvedTable) {

Review Comment:
   rename to `getIndices` -> `getGravitinoIndexes`?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929912246


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -276,8 +282,21 @@ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ig
         propertiesConverter.toGravitinoTableProperties(table.getOptions());
     Transform[] partitions =
         partitionConverter.toGravitinoPartitions(((CatalogTable) table).getPartitionKeys());
+
     try {
-      catalog().asTableCatalog().createTable(identifier, columns, comment, properties, partitions);
+
+      Index[] indices = getGrivatinoIndeics(resolvedTable);

Review Comment:
   use `getGrivatinoIndices`?



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,12 +554,30 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    handleFlinkPrimaryKey(table, builder);
     Map<String, String> flinkTableProperties =
         propertiesConverter.toFlinkTableProperties(table.properties());
     List<String> partitionKeys = partitionConverter.toFlinkPartitionKeys(table.partitioning());
     return CatalogTable.of(builder.build(), table.comment(), partitionKeys, flinkTableProperties);
   }
 
+  private static void handleFlinkPrimaryKey(

Review Comment:
   could you use `String getFlinkPrimaryKey(Table table)` to return the primary field name,  builder could use field name to build primary key.



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,12 +554,30 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    handleFlinkPrimaryKey(table, builder);
     Map<String, String> flinkTableProperties =
         propertiesConverter.toFlinkTableProperties(table.properties());
     List<String> partitionKeys = partitionConverter.toFlinkPartitionKeys(table.partitioning());
     return CatalogTable.of(builder.build(), table.comment(), partitionKeys, flinkTableProperties);
   }
 
+  private static void handleFlinkPrimaryKey(
+      Table table, org.apache.flink.table.api.Schema.Builder builder) {
+    List<Index> primaryKeyList =
+        Arrays.stream(table.index())
+            .filter(index -> index.type() == Index.IndexType.PRIMARY_KEY)
+            .collect(Collectors.toList());
+    if (primaryKeyList.isEmpty()) {
+      return;
+    }
+    Preconditions.checkArgument(

Review Comment:
   could you add the check for the size of filednames too?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "tengqm (via GitHub)" <gi...@apache.org>.
tengqm commented on code in PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#discussion_r1929676964


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -521,6 +552,11 @@ protected CatalogBaseTable toFlinkTable(Table table) {
           .column(column.name(), column.nullable() ? flinkType.nullable() : flinkType.notNull())
           .withComment(column.comment());
     }
+    Index[] indices = table.index();
+    if (indices != null && indices.length == 1) {

Review Comment:
   So .... this means the primary key always has a SINGLE column, right?



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/BaseCatalog.java:
##########
@@ -289,6 +308,18 @@ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ig
     }
   }
 
+  private static Index[] getIndices(ResolvedCatalogBaseTable<?> resolvedTable) {
+    Optional<UniqueConstraint> primaryKey = resolvedTable.getResolvedSchema().getPrimaryKey();
+    List<String> primaryColumns = primaryKey.map(UniqueConstraint::getColumns).orElse(null);
+    if (primaryColumns == null) {
+      return new Index[0];
+    }
+    String[][] primaryFiled =

Review Comment:
   ```suggestion
       String[][] primaryField =
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "hdygxsj (via GitHub)" <gi...@apache.org>.
hdygxsj closed pull request #6362: [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink
URL: https://github.com/apache/gravitino/pull/6362


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#6361] feat(paimon):Support specifying primary keys during create paimon table by flink [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #6362:
URL: https://github.com/apache/gravitino/pull/6362#issuecomment-2652426982

   @hdygxsj could you check the CI failures? @tengqm any other comments?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org