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/10/12 04:06:10 UTC

[GitHub] [flink] luoyuxia opened a new pull request, #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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

   <!--
   *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
   To fix the thrown excpetion with literal in Hive dialect.
   1: some folded constant like `Double.NAN` and no-primitive type  can't be convert into calcite literal 
   2: for divide function, if one parameter is decimal type and the other is int/long type literal, the exception of `Mismatch of expected output data type 'DECIMAL(xx)' and function's output type 'DECIMAL(xx)'` will be thrown.
   
   
   ## Brief change log
     -  Skip fold constant if the folded constant can't be converted into calcite literal.
     -  If it's divide function, and one parameter is decimal type and the other is int/long type literal, force make the expected output data type to be consistent to infered output type by making the two logic consistent.
   
   
   ## Verifying this change
   Add test in `HiveDialectQueryITCase#testLiteral`
   
   ## 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 #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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

   @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] flinkbot commented on pull request #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "b35021c3135509cbcb1a33f30180ffc2626f19b2",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "b35021c3135509cbcb1a33f30180ffc2626f19b2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b35021c3135509cbcb1a33f30180ffc2626f19b2 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 pull request #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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

   @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] lsyldliu commented on a diff in pull request #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java:
##########
@@ -39,6 +39,8 @@
 import org.apache.flink.table.delegation.Parser;
 import org.apache.flink.table.functions.hive.HiveGenericUDTFTest;
 import org.apache.flink.table.functions.hive.util.TestSplitUDTFInitializeWithStructObjectInspector;
+import org.apache.flink.table.module.CoreModule;

Review Comment:
   This is not used.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserTypeCheckProcFactory.java:
##########
@@ -1234,6 +1236,46 @@ protected ExprNodeDesc getXpathOrFuncExprNodeDesc(
                     desc =
                             ExprNodeGenericFuncDesc.newInstance(
                                     new HiveGenericUDFInternalInterval(), funcText, children);
+                } else if (genericUDF instanceof GenericUDFOPDivide && children.size() == 2) {
+                    // special case for GenericUDFOPDivide
+                    // if the divisor or dividend is decimal type and the other one
+                    // parameter is int/long literal, the TypeInfo of the ExprNodeGenericFuncDesc
+                    // may be different with inferred result type, which will cause "Mismatch of
+                    // expected output data type 'DECIMAL(..)' and function's output type
+                    // 'DECIMAL(..)'" in BridgingFunctionGenUtil#verifyOutputType
+
+                    // the reason is: in here we got expected result type, which will consider
+                    // int/long literal parameter as actual precision,
+                    // but in the phase to infer result type phase, the
+                    // int/long literal parameter will always be considered as max precision. 10 for
+                    // int, and 19 for long.
+                    // To fix it, in here, we also should consider the int/long literal parameter as
+                    // max precision.
+                    ExprNodeDesc exprNodeDesc1 = children.get(0);
+                    ExprNodeDesc exprNodeDesc2 = children.get(1);
+                    // if one parameter is decimal type, and the other is int or long
+                    if ((isDecimalTypeInfo(exprNodeDesc1)
+                                    && isIntOrLongTypeInfo(exprNodeDesc2)

Review Comment:
   Does short or byte type also need to be considered?



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserTypeCheckProcFactory.java:
##########
@@ -1234,6 +1236,46 @@ protected ExprNodeDesc getXpathOrFuncExprNodeDesc(
                     desc =
                             ExprNodeGenericFuncDesc.newInstance(
                                     new HiveGenericUDFInternalInterval(), funcText, children);
+                } else if (genericUDF instanceof GenericUDFOPDivide && children.size() == 2) {
+                    // special case for GenericUDFOPDivide
+                    // if the divisor or dividend is decimal type and the other one
+                    // parameter is int/long literal, the TypeInfo of the ExprNodeGenericFuncDesc
+                    // may be different with inferred result type, which will cause "Mismatch of
+                    // expected output data type 'DECIMAL(..)' and function's output type
+                    // 'DECIMAL(..)'" in BridgingFunctionGenUtil#verifyOutputType
+
+                    // the reason is: in here we got expected result type, which will consider
+                    // int/long literal parameter as actual precision,
+                    // but in the phase to infer result type phase, the
+                    // int/long literal parameter will always be considered as max precision. 10 for
+                    // int, and 19 for long.
+                    // To fix it, in here, we also should consider the int/long literal parameter as
+                    // max precision.
+                    ExprNodeDesc exprNodeDesc1 = children.get(0);
+                    ExprNodeDesc exprNodeDesc2 = children.get(1);
+                    // if one parameter is decimal type, and the other is int or long
+                    if ((isDecimalTypeInfo(exprNodeDesc1)
+                                    && isIntOrLongTypeInfo(exprNodeDesc2)

Review Comment:
   It would be better to adjust the order
   ```
   && exprNodeDesc2 instanceof ExprNodeConstantDesc && isIntOrLongTypeInfo(exprNodeDesc2)
   ```



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserTypeCheckProcFactory.java:
##########
@@ -1355,6 +1403,46 @@ private boolean isDescendant(Node ans, Node des) {
             return false;
         }
 
+        private boolean isDecimalTypeInfo(ExprNodeDesc exprNodeDesc) {
+            TypeInfo typeInfo = exprNodeDesc.getTypeInfo();
+            return typeInfo instanceof PrimitiveTypeInfo
+                    && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.DECIMAL;
+        }
+
+        private boolean isIntOrLongTypeInfo(ExprNodeDesc exprNodeDesc) {
+            TypeInfo typeInfo = exprNodeDesc.getTypeInfo();
+            if (!(typeInfo instanceof PrimitiveTypeInfo)) {
+                return false;
+            }
+            return ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.INT
+                    || ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.LONG;
+        }
+
+        private boolean canSafeFoldToConstant(ExprNodeConstantDesc constantExpr) {
+            // if it's not primitive type, can't be folded to constant safely
+            boolean isPrimitiveTyp = constantExpr.getTypeInfo() instanceof PrimitiveTypeInfo;
+            if (!isPrimitiveTyp) {
+                return false;
+            }
+            // if it's binary type, can't be folded to constant safely
+            boolean isBinaryConstant =
+                    constantExpr.getTypeInfo() instanceof PrimitiveTypeInfo
+                            && (((PrimitiveTypeInfo) constantExpr.getTypeInfo())
+                                            .getPrimitiveCategory()
+                                    == PrimitiveObjectInspector.PrimitiveCategory.BINARY);
+            if (isBinaryConstant) {
+                return false;
+            }
+            // if it's Double.NAN, can't be folded to constant safely
+            boolean isNAN =
+                    constantExpr.getValue() instanceof Double

Review Comment:
   Float also maybe NaN, does the `constantExpr.getValue()` is Float type?



-- 
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 #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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

   @lsyldliu Thanks for reviewing. I have addressed your commens.


-- 
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 #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/HiveParserTypeCheckProcFactory.java:
##########
@@ -1355,6 +1403,46 @@ private boolean isDescendant(Node ans, Node des) {
             return false;
         }
 
+        private boolean isDecimalTypeInfo(ExprNodeDesc exprNodeDesc) {
+            TypeInfo typeInfo = exprNodeDesc.getTypeInfo();
+            return typeInfo instanceof PrimitiveTypeInfo
+                    && ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.DECIMAL;
+        }
+
+        private boolean isIntOrLongTypeInfo(ExprNodeDesc exprNodeDesc) {
+            TypeInfo typeInfo = exprNodeDesc.getTypeInfo();
+            if (!(typeInfo instanceof PrimitiveTypeInfo)) {
+                return false;
+            }
+            return ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.INT
+                    || ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory()
+                            == PrimitiveObjectInspector.PrimitiveCategory.LONG;
+        }
+
+        private boolean canSafeFoldToConstant(ExprNodeConstantDesc constantExpr) {
+            // if it's not primitive type, can't be folded to constant safely
+            boolean isPrimitiveTyp = constantExpr.getTypeInfo() instanceof PrimitiveTypeInfo;
+            if (!isPrimitiveTyp) {
+                return false;
+            }
+            // if it's binary type, can't be folded to constant safely
+            boolean isBinaryConstant =
+                    constantExpr.getTypeInfo() instanceof PrimitiveTypeInfo
+                            && (((PrimitiveTypeInfo) constantExpr.getTypeInfo())
+                                            .getPrimitiveCategory()
+                                    == PrimitiveObjectInspector.PrimitiveCategory.BINARY);
+            if (isBinaryConstant) {
+                return false;
+            }
+            // if it's Double.NAN, can't be folded to constant safely
+            boolean isNAN =
+                    constantExpr.getValue() instanceof Double

Review Comment:
   It may be float type,  we need to add to 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] wuchong merged pull request #21026: [FLINK-29590][hive] fix literal issue in Hive dialect

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


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