You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "spena (via GitHub)" <gi...@apache.org> on 2024/12/06 20:49:03 UTC

[PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

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

   ## What is the purpose of the change
   
   Fix an issue with the CTAS statement to allow writing to metadata columns on the sink table.
   
   
   ## Verifying this change
   
   - Added unit tests
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   


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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876117885


##########
tools/maven/suppressions.xml:
##########
@@ -35,6 +35,7 @@ under the License.
 		<suppress files="DependencyTree.java" checks="IllegalImport"/>
 
 		<suppress files="FlinkSqlParserImplTest.java" checks="FileLength"/>
+	    <suppress files="SqlDdlToOperationConverterTest.java" checks="FileLength"/>

Review Comment:
   can we not split this file into some 2 or more logical groupings rather than suppressing the file length 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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876128994


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/MergeTableAsUtil.java:
##########
@@ -386,19 +387,24 @@ private void validateImplicitCastCompatibility(
                 int columnPos,
                 UnresolvedColumn sourceColumn,
                 UnresolvedColumn sinkColumn) {
-            if (!(sinkColumn instanceof UnresolvedPhysicalColumn)) {
+            LogicalType sinkColumnType;
+
+            if (sinkColumn instanceof UnresolvedPhysicalColumn) {
+                sinkColumnType = getLogicalType(((UnresolvedPhysicalColumn) sinkColumn));
+            } else if ((sinkColumn instanceof UnresolvedMetadataColumn)
+                    && !((UnresolvedMetadataColumn) sinkColumn).isVirtual()) {
+                sinkColumnType = getLogicalType(((UnresolvedMetadataColumn) sinkColumn));
+            } else {
                 throw new ValidationException(
                         String.format(
                                 "A column named '%s' already exists in the source schema. "
-                                        + "Computed and metadata columns cannot overwrite "
-                                        + "regular columns.",
+                                        + "Computed and virtual metadata columns cannot overwrite "

Review Comment:
   could we have different message for computed and virtual cases, so the message is specific. We could test each message in the unit tests.   
   



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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "spena (via GitHub)" <gi...@apache.org>.
spena commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876495984


##########
tools/maven/suppressions.xml:
##########
@@ -35,6 +35,7 @@ under the License.
 		<suppress files="DependencyTree.java" checks="IllegalImport"/>
 
 		<suppress files="FlinkSqlParserImplTest.java" checks="FileLength"/>
+	    <suppress files="SqlDdlToOperationConverterTest.java" checks="FileLength"/>

Review Comment:
   Yeah, we can do that. I moved the CTAS tests to another file `SqlCTASNodeToOperationTest`. I also added some tests to `SqlRTASNodeToOperationTest` btw.



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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25758:
URL: https://github.com/apache/flink/pull/25758#issuecomment-2524156693

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "de08c46bc8251b1e934ef0eba31d410ff6854d40",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "de08c46bc8251b1e934ef0eba31d410ff6854d40",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * de08c46bc8251b1e934ef0eba31d410ff6854d40 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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

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


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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876140487


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlDdlToOperationConverterTest.java:
##########
@@ -804,6 +804,61 @@ public void testCreateTableAsWithColumnsOverridden() {
                                                         .build()))));
     }
 
+    @Test
+    public void testCreateTableAsWithOverriddenMetadataColumns() {
+        CatalogTable catalogTable =
+                CatalogTable.newBuilder()
+                        .schema(
+                                Schema.newBuilder()
+                                        .column("f0", DataTypes.INT().notNull())
+                                        .column("f1", DataTypes.BIGINT())
+                                        .build())
+                        .build();
+
+        catalogManager.createTable(
+                catalogTable, ObjectIdentifier.of("builtin", "default", "src1"), false);
+
+        final String sql = "create table tbl1 (f1 bigint metadata) " + "AS SELECT * FROM src1";

Review Comment:
   I am wondering if we could test: 
   table src2 g1 and g2
   
   `create table tbl1 (f1 bigint metadata)  AS SELECT s.g1 as f1 FROM src2 as s;`
   
   and is this sort of thing valid - or as the 2 ASes not allowed?
   `create table tbl1 (g1 bigint metadata as f1)  AS SELECT s.g1 FROM src2 as s;`
   
   



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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "spena (via GitHub)" <gi...@apache.org>.
spena commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876497296


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlDdlToOperationConverterTest.java:
##########
@@ -804,6 +804,61 @@ public void testCreateTableAsWithColumnsOverridden() {
                                                         .build()))));
     }
 
+    @Test
+    public void testCreateTableAsWithOverriddenMetadataColumns() {
+        CatalogTable catalogTable =
+                CatalogTable.newBuilder()
+                        .schema(
+                                Schema.newBuilder()
+                                        .column("f0", DataTypes.INT().notNull())
+                                        .column("f1", DataTypes.BIGINT())
+                                        .build())
+                        .build();
+
+        catalogManager.createTable(
+                catalogTable, ObjectIdentifier.of("builtin", "default", "src1"), false);
+
+        final String sql = "create table tbl1 (f1 bigint metadata) " + "AS SELECT * FROM src1";

Review Comment:
   The second case  is not valid. You cannot have aliases in the CREATE part, only in the SELECT part. I updated a test to include aliases on physical and metadata columns. The same for RTAS tests.



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


Re: [PR] [FLINK-36861][table-planner] CREATE TABLE AS with METADATA columns doesn't work [flink]

Posted by "spena (via GitHub)" <gi...@apache.org>.
spena commented on code in PR #25758:
URL: https://github.com/apache/flink/pull/25758#discussion_r1876496585


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/MergeTableAsUtil.java:
##########
@@ -386,19 +387,24 @@ private void validateImplicitCastCompatibility(
                 int columnPos,
                 UnresolvedColumn sourceColumn,
                 UnresolvedColumn sinkColumn) {
-            if (!(sinkColumn instanceof UnresolvedPhysicalColumn)) {
+            LogicalType sinkColumnType;
+
+            if (sinkColumn instanceof UnresolvedPhysicalColumn) {
+                sinkColumnType = getLogicalType(((UnresolvedPhysicalColumn) sinkColumn));
+            } else if ((sinkColumn instanceof UnresolvedMetadataColumn)
+                    && !((UnresolvedMetadataColumn) sinkColumn).isVirtual()) {
+                sinkColumnType = getLogicalType(((UnresolvedMetadataColumn) sinkColumn));
+            } else {
                 throw new ValidationException(
                         String.format(
                                 "A column named '%s' already exists in the source schema. "
-                                        + "Computed and metadata columns cannot overwrite "
-                                        + "regular columns.",
+                                        + "Computed and virtual metadata columns cannot overwrite "

Review Comment:
   Yes. I updated the PR with new tests with different messages.



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