You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/15 11:12:05 UTC

[GitHub] [flink] fsk119 opened a new pull request, #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

fsk119 opened a new pull request, #19490:
URL: https://github.com/apache/flink/pull/19490

   … name in DDL
   
   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   *Currently the source output the metadata column with the `"$metadata"+ metadata key` as the column name. It's better that keep the name align with the user name specified in the DDL,e.g. use `event_time` as the name if the user specifies `event_time TIMESTAMP(3) FROM 'timestamp'`.*
   
   
   ## Brief change log
   
     - *Make call in the projection to do the rename*
   
   
   ## Verifying this change
   
   
   This change is already covered by existing tests in the `PushProjectIntoTableSourceScanRuleTest`.
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / **not documented**)
   


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] fsk119 commented on pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
fsk119 commented on PR #19490:
URL: https://github.com/apache/flink/pull/19490#issuecomment-1102632929

   @flinkbot  run azure
   
   Thanks for your review and help =-=.


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] twalthr commented on a diff in pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
twalthr commented on code in PR #19490:
URL: https://github.com/apache/flink/pull/19490#discussion_r852734551


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala:
##########
@@ -215,6 +215,87 @@ class TableEnvironmentTest {
       TableTestUtil.replaceNodeIdInOperator(TableTestUtil.replaceStreamNodeId(actual)))
   }
 
+  @Test
+  def testCreateTableWithMultipleColumnsFromSameMetadataKey(): Unit = {
+    assertThatThrownBy(() =>
+      tableEnv.executeSql(
+        """
+          |CREATE TABLE source (
+          |  a INT METADATA,
+          |  b INT METADATA FROM 'a'
+          |) WITH (
+          |  'connector' = 'COLLECTION'
+          |)
+          |""".stripMargin)).satisfies(
+      FlinkAssertions.anyCauseMatches(
+        classOf[ValidationException],
+        "The column `a` and `b` in the table are both from the same metadata key 'a'. " +
+          "Please specify one of the columns as the metadata column and use the computed column" +
+          " syntax to specify the others."))
+  }
+
+  @Test
+  def testCreateTableLikeWithMultipleColumnsFromSameMetadataKey(): Unit = {
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE source (
+        |  a INT METADATA
+        |) WITH (
+        |  'connector' = 'COLLECTION'
+        |)
+        |""".stripMargin)
+    assertThatThrownBy(() =>
+      tableEnv.executeSql(
+        """
+          |CREATE TABLE like_source (
+          |  b INT METADATA FROM 'a'
+          |)
+          |WITH (
+          |  'connector' = 'COLLECTION'
+          |) LIKE source (
+          |  INCLUDING METADATA
+          |)
+          |""".stripMargin
+      )).satisfies(FlinkAssertions.anyCauseMatches(
+      "The column `a` and `b` in the table are both from the same metadata key 'a'. " +
+        "Please specify one of the columns as the metadata column and use the computed column" +
+        " syntax to specify the others."
+    ))
+  }
+
+  @Test
+  def testCreateTableLikeExcludeColumnsFromSameMetadataKey(): Unit = {
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE source (
+        |  a INT METADATA
+        |) WITH (
+        |  'connector' = 'COLLECTION'
+        |)
+        |""".stripMargin)
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE like_source (
+        |  b INT METADATA FROM 'a'
+        |)
+        |WITH (
+        |  'connector' = 'COLLECTION'
+        |) LIKE source (
+        |  EXCLUDING METADATA
+        |)
+        |""".stripMargin
+    )
+    assertEquals(

Review Comment:
   not sure if testing this is still necessary. this should be covered by tests already?



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/connectors/DynamicSourceUtils.java:
##########
@@ -168,26 +165,40 @@ public static void prepareDynamicSource(
     // TODO: isUpsertSource(), isSourceChangeEventsDuplicate()
 
     /**
-     * Returns a list of required metadata keys. Ordered by the iteration order of {@link
+     * Returns a list of required metadata columns. Ordered by the iteration order of {@link
      * SupportsReadingMetadata#listReadableMetadata()}.
      *
      * <p>This method assumes that source and schema have been validated via {@link
      * #prepareDynamicSource(String, ResolvedCatalogTable, DynamicTableSource, boolean,
      * ReadableConfig)}.
      */
-    public static List<String> createRequiredMetadataKeys(
+    public static List<MetadataColumn> createRequiredMetadataColumns(
             ResolvedSchema schema, DynamicTableSource source) {
         final List<MetadataColumn> metadataColumns = extractMetadataColumns(schema);
 
-        final Set<String> requiredMetadataKeys =
-                metadataColumns.stream()
-                        .map(c -> c.getMetadataKey().orElse(c.getName()))
-                        .collect(Collectors.toSet());
+        Map<String, MetadataColumn> metadataKeysToMetadataColumns = new HashMap<>();
+
+        for (MetadataColumn column : metadataColumns) {
+            String metadataKey = column.getMetadataKey().orElse(column.getName());
+            if (metadataKeysToMetadataColumns.containsKey(metadataKey)) {
+                throw new ValidationException(

Review Comment:
   We don't need this check here. `DefaultSchemaResolver` should be the only location for validation.



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala:
##########
@@ -215,6 +215,87 @@ class TableEnvironmentTest {
       TableTestUtil.replaceNodeIdInOperator(TableTestUtil.replaceStreamNodeId(actual)))
   }
 
+  @Test
+  def testCreateTableWithMultipleColumnsFromSameMetadataKey(): Unit = {

Review Comment:
   `TableEnvironmentTest` is meant for code that is located in `TableEnvironment` implementation. Move these tests to `org.apache.flink.table.planner.plan.batch.sql.TableScanTest`? Most DDL stuff like `testDDLWithComputedColumn` is located there currently.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] flinkbot commented on pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #19490:
URL: https://github.com/apache/flink/pull/19490#issuecomment-1100045930

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "b98759b38d05a732ef3c9ceabfc844dfaf4bd2e8",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "b98759b38d05a732ef3c9ceabfc844dfaf4bd2e8",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b98759b38d05a732ef3c9ceabfc844dfaf4bd2e8 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] fsk119 commented on a diff in pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
fsk119 commented on code in PR #19490:
URL: https://github.com/apache/flink/pull/19490#discussion_r852764442


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala:
##########
@@ -215,6 +215,87 @@ class TableEnvironmentTest {
       TableTestUtil.replaceNodeIdInOperator(TableTestUtil.replaceStreamNodeId(actual)))
   }
 
+  @Test
+  def testCreateTableWithMultipleColumnsFromSameMetadataKey(): Unit = {

Review Comment:
   Move to the TableScanTest.



##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/api/TableEnvironmentTest.scala:
##########
@@ -215,6 +215,87 @@ class TableEnvironmentTest {
       TableTestUtil.replaceNodeIdInOperator(TableTestUtil.replaceStreamNodeId(actual)))
   }
 
+  @Test
+  def testCreateTableWithMultipleColumnsFromSameMetadataKey(): Unit = {
+    assertThatThrownBy(() =>
+      tableEnv.executeSql(
+        """
+          |CREATE TABLE source (
+          |  a INT METADATA,
+          |  b INT METADATA FROM 'a'
+          |) WITH (
+          |  'connector' = 'COLLECTION'
+          |)
+          |""".stripMargin)).satisfies(
+      FlinkAssertions.anyCauseMatches(
+        classOf[ValidationException],
+        "The column `a` and `b` in the table are both from the same metadata key 'a'. " +
+          "Please specify one of the columns as the metadata column and use the computed column" +
+          " syntax to specify the others."))
+  }
+
+  @Test
+  def testCreateTableLikeWithMultipleColumnsFromSameMetadataKey(): Unit = {
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE source (
+        |  a INT METADATA
+        |) WITH (
+        |  'connector' = 'COLLECTION'
+        |)
+        |""".stripMargin)
+    assertThatThrownBy(() =>
+      tableEnv.executeSql(
+        """
+          |CREATE TABLE like_source (
+          |  b INT METADATA FROM 'a'
+          |)
+          |WITH (
+          |  'connector' = 'COLLECTION'
+          |) LIKE source (
+          |  INCLUDING METADATA
+          |)
+          |""".stripMargin
+      )).satisfies(FlinkAssertions.anyCauseMatches(
+      "The column `a` and `b` in the table are both from the same metadata key 'a'. " +
+        "Please specify one of the columns as the metadata column and use the computed column" +
+        " syntax to specify the others."
+    ))
+  }
+
+  @Test
+  def testCreateTableLikeExcludeColumnsFromSameMetadataKey(): Unit = {
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE source (
+        |  a INT METADATA
+        |) WITH (
+        |  'connector' = 'COLLECTION'
+        |)
+        |""".stripMargin)
+    tableEnv.executeSql(
+      """
+        |CREATE TABLE like_source (
+        |  b INT METADATA FROM 'a'
+        |)
+        |WITH (
+        |  'connector' = 'COLLECTION'
+        |) LIKE source (
+        |  EXCLUDING METADATA
+        |)
+        |""".stripMargin
+    )
+    assertEquals(

Review Comment:
   Remove the test.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] twalthr commented on a diff in pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
twalthr commented on code in PR #19490:
URL: https://github.com/apache/flink/pull/19490#discussion_r852601520


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/MergeTableLikeUtilTest.java:
##########
@@ -431,6 +433,100 @@ public void mergeOverwritingMetadataColumnsDuplicate() {
         assertThat(mergedSchema, equalTo(expectedSchema));
     }
 
+    @Test
+    public void mergeIncludingMetadataColumnWithSameMetadataKey() {
+        TableSchema sourceSchema = TableSchema.builder().build();
+
+        List<SqlNode> derivedColumns =
+                Arrays.asList(
+                        metadataColumn("one", DataTypes.BOOLEAN(), true),
+                        metadataColumn("two", DataTypes.STRING(), "one", false));
+
+        Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
+        mergingStrategies.put(FeatureOption.METADATA, MergingStrategy.INCLUDING);
+
+        thrown.expect(ValidationException.class);
+        thrown.expectMessage(

Review Comment:
   How about we add this validation logic to `DefaultSchemaResolver`? This way we avoid checking duplicate metadata keys at three locations and fail as early as possible.



-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] twalthr commented on pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
twalthr commented on PR #19490:
URL: https://github.com/apache/flink/pull/19490#issuecomment-1103506386

   Fixed in 1.15 via 5e9ccf1cdd4328885ac50fad4d32fc93a62290fd.


-- 
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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] twalthr closed pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…

Posted by GitBox <gi...@apache.org>.
twalthr closed pull request #19490: [FLINK-27263][table] Rename the metadata column to the user specified…
URL: https://github.com/apache/flink/pull/19490


-- 
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: issues-unsubscribe@flink.apache.org

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