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/09/19 12:27:08 UTC

[GitHub] [flink] luoyuxia opened a new pull request, #20855: [FLINK-29337][hive] Fix fail to use Hive Dialect for non-hive table

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

   <!--
   *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
   Ti fix the failure for the query with non-hive table in Hive dialect.
   
   ## Brief change log
   // todo:
   
   
   ## Verifying this change
   Added test in xxx.
   
   ## 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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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

   @flinkbot run azure


-- 
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] lsyldliu commented on a diff in pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {

Review Comment:
   The `TableSchema` has been deprecated, does we can use the new `Schema`? If not, I think we should create an issue to migrate `TableSchema` to `Schema` for hive.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserBaseSemanticAnalyzer.java:
##########
@@ -520,10 +523,46 @@ public static String getUnescapedUnqualifiedTableName(HiveParserASTNode node) {
      * Get dequoted name from a table/column node.
      *
      * @param tableOrColumnNode the table or column node
-     * @return for table node, db.tab or tab. for column node column.
+     * @return for table node, return the table that users specific like catalog.db.tab, db.tab or
+     *     tab. For column node column, return col.
      */
-    public static String getUnescapedName(HiveParserASTNode tableOrColumnNode) {
-        return getUnescapedName(tableOrColumnNode, null);
+    public static String getUnescapedName(HiveParserASTNode tableOrColumnNode)
+            throws SemanticException {
+        return getUnescapedName(tableOrColumnNode, null, null);
+    }
+
+    public static String getUnescapedName(
+            HiveParserASTNode tableOrColumnNode, String currentCatalog, String currentDatabase)

Review Comment:
   Nit: currentCatalog and currentDatabase add `@Nullable` annotation.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {
+        final TableSchema.Builder builder = TableSchema.builder();
+
+        final DataType unresolvedType = DataTypes.TIMESTAMP(3);
+        schema.getColumns().stream()
+                .map(
+                        column -> {
+                            if (column instanceof Schema.UnresolvedPhysicalColumn) {
+                                final Schema.UnresolvedPhysicalColumn c =
+                                        (Schema.UnresolvedPhysicalColumn) column;
+                                return TableColumn.physical(
+                                        c.getName(), (DataType) c.getDataType());
+                            } else if (column instanceof Schema.UnresolvedMetadataColumn) {
+                                final Schema.UnresolvedMetadataColumn c =
+                                        (Schema.UnresolvedMetadataColumn) column;
+                                return TableColumn.metadata(
+                                        c.getName(),
+                                        (DataType) c.getDataType(),
+                                        c.getMetadataKey(),
+                                        c.isVirtual());
+                            } else if (column instanceof Schema.UnresolvedComputedColumn) {
+                                final Schema.UnresolvedComputedColumn c =
+                                        (Schema.UnresolvedComputedColumn) column;
+                                return TableColumn.computed(
+                                        c.getName(),
+                                        unresolvedType,

Review Comment:
   Why not use `DataTypes.TIMESTAMP(3)` directly?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserSemanticAnalyzer.java:
##########
@@ -2158,6 +2074,44 @@ public String getAutogenColAliasPrfxLbl() {
         return this.autogenColAliasPrfxLbl;
     }
 
+    public CatalogBaseTable getCatalogBaseTable(String tableName, HiveParserQB qb) {
+        return getCatalogBaseTable(tableName, qb, true);
+    }
+
+    public CatalogBaseTable getCatalogBaseTable(

Review Comment:
   Nit: add `@Nullable` annotation.



-- 
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] wuchong merged pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

Posted by GitBox <gi...@apache.org>.
wuchong merged PR #20855:
URL: https://github.com/apache/flink/pull/20855


-- 
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] luoyuxia commented on a diff in pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {

Review Comment:
   we can use the new `Scema`, but it should be another pr. I have created FLINK-29585 for it.



-- 
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 #20855: [FLINK-29337][hive] Fix fail to use Hive Dialect for non-hive table

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "7d7b0bb51d4d6a0471ced9ba38bfdf23a75824c2",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "7d7b0bb51d4d6a0471ced9ba38bfdf23a75824c2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 7d7b0bb51d4d6a0471ced9ba38bfdf23a75824c2 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] luoyuxia commented on a diff in pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {

Review Comment:
   I have created FLINK-29585 for it.



-- 
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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to use Hive Dialect for non-hive table

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

   @flinkbot run azure


-- 
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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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

   @wuchong Could you please help merge?


-- 
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] luoyuxia commented on a diff in pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {
+        final TableSchema.Builder builder = TableSchema.builder();
+
+        final DataType unresolvedType = DataTypes.TIMESTAMP(3);
+        schema.getColumns().stream()
+                .map(
+                        column -> {
+                            if (column instanceof Schema.UnresolvedPhysicalColumn) {
+                                final Schema.UnresolvedPhysicalColumn c =
+                                        (Schema.UnresolvedPhysicalColumn) column;
+                                return TableColumn.physical(
+                                        c.getName(), (DataType) c.getDataType());
+                            } else if (column instanceof Schema.UnresolvedMetadataColumn) {
+                                final Schema.UnresolvedMetadataColumn c =
+                                        (Schema.UnresolvedMetadataColumn) column;
+                                return TableColumn.metadata(
+                                        c.getName(),
+                                        (DataType) c.getDataType(),
+                                        c.getMetadataKey(),
+                                        c.isVirtual());
+                            } else if (column instanceof Schema.UnresolvedComputedColumn) {
+                                final Schema.UnresolvedComputedColumn c =
+                                        (Schema.UnresolvedComputedColumn) column;
+                                return TableColumn.computed(
+                                        c.getName(),
+                                        unresolvedType,

Review Comment:
   `DataTypes.TIMESTAMP(3)`  will be used in two places, so I prefer to create a local variable `unresolvedType ` and make these two places use the variable.



-- 
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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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

   test for hive3 is in https://github.com/apache/flink/pull/20907


-- 
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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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

   @flinkbot run azure


-- 
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] luoyuxia commented on pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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

   @flinkbot run azure


-- 
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] Aitozi commented on a diff in pull request #20855: [FLINK-29337][hive] Fix fail to query non-hive table in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserUtils.java:
##########
@@ -1689,4 +1694,61 @@ public static boolean isFromTimeStampToDecimal(RelDataType srcType, RelDataType
         return srcType.getSqlTypeName().equals(SqlTypeName.TIMESTAMP)
                 && targetType.getSqlTypeName().equals(SqlTypeName.DECIMAL);
     }
+
+    /**
+     * Helps to migrate the new {@link Schema} to old API methods. HiveCatalog use deprecated {@link
+     * TableSchema}, other catalogs may use the new {@link Schema}. Currently, we use it to unify to
+     * {@link TableSchema}. It should be dropped after dropping {@link TableSchema}.
+     */
+    public static TableSchema fromUnresolvedSchema(Schema schema) {
+        final TableSchema.Builder builder = TableSchema.builder();
+
+        final DataType unresolvedType = DataTypes.TIMESTAMP(3);

Review Comment:
   Hi @luoyuxia , I have a question here, why here unresolvedType is hard coded `TIMESTAMP(3)` ? 



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