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/11 11:45:27 UTC

[GitHub] [flink] luoyuxia opened a new pull request, #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   
   <!--
   *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 support to call Hive UDAF when the UDAF accepts one parameter with array type
   
   
   ## Brief change log
   When  the parameter is a single array, wrap it to an array.
   
   
   ## Verifying this change
   Added test method `testUDAFCollectList`  in  [HiveGenericUDAFTest.java](https://github.com/apache/flink/compare/master...luoyuxia:fix-call-hive-collect-list-issue?expand=1#diff-347c8a1c08423da764ef8547e503d5772bf26cbdc72e281ed2cf7959085104be)
   
   ## 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? N/A
   


-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   I think we should determine whether the  argTypes  is Array , replace primitive Array type.`
   If argsType is Array , inputs should be converted to an object[].
   If argsType is not Array, we can keep origin code logic.
   
   `HiveFunctionUtil.isSingleBoxedArray(argTypes);` throws exception when argTypes is Array and the elemet type is BOOLEAN | TINYINT | SMALLINT |  INTEGER | BIGINT | FLOAT | DOUBLE.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java:
##########
@@ -104,11 +106,29 @@ public void testUDAFCount() throws Exception {
         udf.accumulate(acc, 0.3d);
         udf.accumulate(acc, 5.3d);
 
-        udf.merge(acc, Arrays.asList());
+        udf.merge(acc, Collections.emptyList());
 
         assertEquals(3L, udf.getValue(acc));
     }
 
+    @Test
+    public void testUDAFCollectList() throws Exception {

Review Comment:
   It would be better if add a test about `Collect_Set` function



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java:
##########
@@ -104,11 +106,29 @@ public void testUDAFCount() throws Exception {
         udf.accumulate(acc, 0.3d);
         udf.accumulate(acc, 5.3d);
 
-        udf.merge(acc, Arrays.asList());
+        udf.merge(acc, Collections.emptyList());
 
         assertEquals(3L, udf.getValue(acc));
     }
 
+    @Test
+    public void testUDAFCollectList() throws Exception {
+        Object[] constantArgs = new Object[] {null};
+
+        DataType[] argTypes = new DataType[] {DataTypes.ARRAY(DataTypes.INT())};
+
+        HiveGenericUDAF udf = init(GenericUDAFCollectList.class, constantArgs, argTypes);
+        GenericUDAFEvaluator.AggregationBuffer acc = udf.createAccumulator();
+
+        udf.accumulate(acc, (Object[]) new Integer[] {1, 2});

Review Comment:
   Nit: The `(Object[])` is not required.



-- 
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 pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   @luoyuxia Thanks for your contribution, I left a minor comment. Overall, 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: 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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Thanks, I see you.
   Actually, I don't know why primiteive array is not supported. It's legacy code I have no knowledge.
   According to my insight and test with Hive's qtest.  it should be supported. I think the validation can be droped.
   But currently, I would like to keep it and then see what will happen.



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -173,6 +178,14 @@ public GenericUDAFEvaluator.AggregationBuffer createAccumulator() {
 
     public void accumulate(GenericUDAFEvaluator.AggregationBuffer acc, Object... inputs)
             throws HiveException {
+        // When the parameter of the function is (Integer, Array[Double]), Flink calls
+        // udf.eval(AggregationBuffer, Integer, Array[Double]), which is not a problem.
+        // But when the parameter is a single array, Flink calls udf.accumulate(AggregationBuffer,
+        // Array[Double]), at this point java's var-args will cast Array[Double] to Array[Object]
+        // and let it be Object... args, So we need wrap it.
+        if (isArgsSingleArray) {
+            inputs = new Object[] {inputs};
+        }
         if (!allIdentityConverter) {
             for (int i = 0; i < inputs.length; i++) {

Review Comment:
   I think there are some quetion. conversrsions length is 1,but inputs length is not when argsType is array(double)



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
    for (DataType dataType : argTypes) {
               if (HiveFunctionUtil.isPrimitiveArray(dataType)) {
                   throw new FlinkHiveUDFException(
                           "Flink doesn't support primitive array for Hive functions yet.");
               }
           }
   
   Array(Double)  is  PrimitiveArray , throws exception



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   @luoyuxia , I am wrong.
   Array(double) , the isNullable  of DoubleType is false,it will throw  exception.
   Array(double) , the isNullable  of DoubleType is true,it is normal.
   



-- 
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 commented on pull request #19423: [FLINK-27175][hive] Fix fail to call Hive UDAF when the UDAF accepts one parameter with array type

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

   Could you add an IT case for this?


-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   If the check of `isArgsSingleArray `  is not reasonable,  can I go to the next step to support ?
   `DataType[] argTypes = new DataType[]{DataTypes.ARRAY(DataTypes.INT().notNull())};`
   
   https://issues.apache.org/jira/browse/FLINK-27238



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
    for (DataType dataType : argTypes) {
               if (HiveFunctionUtil.isPrimitiveArray(dataType)) {
                   throw new FlinkHiveUDFException(
                           "Flink doesn't support primitive array for Hive functions yet.");
               }
           }
   
   Array(Double)  is  PrimitiveArray , throws exception.
   
   Do you know why primiteive array is not supported?
   There are some problems with `isArgsSingleArray`  condition .
   if argsType is Array  then need the code `inputs = new Object[] {inputs}`;
   if argsType is not Array then don't need the code.



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   @luoyuxia , I am wrong. Hive udf should be no problem.
   Array(double) , the isNullable  of DoubleType is false,it will throw  exception.
   Array(double) , the isNullable  of DoubleType is true,it is normal.
   
   



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   IIUC, the problem can be resolve in the changes of https://github.com/apache/flink/pull/19423/files#diff-fb0d46645c48e1c7b406addf9b31274625882afc69ad0cdf7700d2d67d699473R186



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Array<Double>\Array<String>  ...  throws  exception  here



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   @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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   If it is reasonable, can I go to the next step to support ?
   `DataType[] argTypes = new DataType[]{DataTypes.ARRAY(DataTypes.INT().notNull())};`
   
   https://issues.apache.org/jira/browse/FLINK-27238



-- 
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 #19423: [FLINK-27175][hive] Fix fail to call Hive UDAF when the UDAF accepts one parameter with array type

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


-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Array( Double)
   Array(String)  ...  
   throws  exception  here



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   If we use it in Flink, we can make an optimization extension
   If the check of `isArgsSingleArray `  is not reasonable,  can I go to the next step to support ?
   `DataType[] argTypes = new DataType[]{DataTypes.ARRAY(DataTypes.INT().notNull())};`
   
   https://issues.apache.org/jira/browse/FLINK-27238



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Update: I prefer to drop such validation logic. The logic is weird and  the primitive array type should be supported from my test run with Hive's qtest. I think it may be legacy code.  



-- 
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 #19423: [FLINK-27175][hive] Fix fail to call Hive UDAF when the UDAF accepts one parameter with array type

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

   > Could you add an IT case for this?
   
   Sure. Now, I add a query in [udaf.q](https://github.com/apache/flink/pull/19423/files#diff-d5e127b8a35b22a1beae4fe98c270efd5c51f69eb0cd812e69242de6c241e557) to verify this fix. Without this fix, the query will fail to run.


-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Yes, I think we has supported it. So I drop the check logic in this pr.



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   I think we should determine whether the  argTypes  is Array , replace primitive Array type.`
   If argsType is Array , inputs should be converted to an object[].
   If argsType is not Array, we can keep origin code logic.
   
   `HiveFunctionUtil.isSingleBoxedArray(argTypes);` throws exception when argTypes is Array and the element type is BOOLEAN | TINYINT | SMALLINT |  INTEGER | BIGINT | FLOAT | DOUBLE.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Why throws exception here?



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   IIUC, the proble can be resolve in the changes of https://github.com/apache/flink/pull/19423/files#diff-fb0d46645c48e1c7b406addf9b31274625882afc69ad0cdf7700d2d67d699473R186



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Array<Double>
   Array<String>  ...  
   throws  exception  here



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   @luoyuxia , I am wrong.
   Array(double) , the isNullable  of DoubleType is false,it will throw  exception.
   Array(double) , the isNullable  of DoubleType is true,it is normal.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   @hehuiyuan Thanks very much for your 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: issues-unsubscribe@flink.apache.org

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


[GitHub] [flink] hehuiyuan commented on pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   > @hehuiyuan Thanks very much for your review.
   
   <img width="68" alt="image" src="https://user-images.githubusercontent.com/18002496/163136872-0da05d91-7efc-442d-999c-8b2830e9cd38.png">We are just doing some hive compatibility verification.


-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
    for (DataType dataType : argTypes) {
               if (HiveFunctionUtil.isPrimitiveArray(dataType)) {
                   throw new FlinkHiveUDFException(
                           "Flink doesn't support primitive array for Hive functions yet.");
               }
           }
   
   Array<Double> is  PrimitiveArray , throws exception



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
    for (DataType dataType : argTypes) {
               if (HiveFunctionUtil.isPrimitiveArray(dataType)) {
                   throw new FlinkHiveUDFException(
                           "Flink doesn't support primitive array for Hive functions yet.");
               }
           }
   
   Array(Double)  is  PrimitiveArray , throws exception.
   
   Do you know why primiteive array is not supported?
   
   if argsType is Array  then need the code `inputs = new Object[] {inputs}`;
   if argsType is not Array then don't need the code.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "8cae721fd8832fd7cbb5711f3f05905c7b0c8bff",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "8cae721fd8832fd7cbb5711f3f05905c7b0c8bff",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8cae721fd8832fd7cbb5711f3f05905c7b0c8bff 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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -173,6 +178,14 @@ public GenericUDAFEvaluator.AggregationBuffer createAccumulator() {
 
     public void accumulate(GenericUDAFEvaluator.AggregationBuffer acc, Object... inputs)
             throws HiveException {
+        // When the parameter of the function is (Integer, Array[Double]), Flink calls
+        // udf.eval(AggregationBuffer, Integer, Array[Double]), which is not a problem.
+        // But when the parameter is a single array, Flink calls udf.accumulate(AggregationBuffer,
+        // Array[Double]), at this point java's var-args will cast Array[Double] to Array[Object]
+        // and let it be Object... args, So we need wrap it.
+        if (isArgsSingleArray) {
+            inputs = new Object[] {inputs};
+        }
         if (!allIdentityConverter) {
             for (int i = 0; i < inputs.length; i++) {

Review Comment:
   Thanks, got 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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes); 
   
   Do you know why primiteive array is not supported?
   
   if argsType is Array  then need the code `inputs = new Object[] {inputs}`;
   if argsType is not Array then don't need the code.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Thanks, I see you.
   Actuallu, I don't know why primiteive array is not supported. It's legacy code I have no knowledge.
   According to my insight and test with Hive's qtest.  it should be supported. I think the validation can be dropped.
   But currently, I would like to keep it and then see what will happen.



##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   Thanks, I see you.
   Actually, I don't know why primiteive array is not supported. It's legacy code I have no knowledge.
   According to my insight and test with Hive's qtest.  it should be supported. I think the validation can be dropped.
   But currently, I would like to keep it and then see what will happen.



-- 
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 #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -173,6 +178,14 @@ public GenericUDAFEvaluator.AggregationBuffer createAccumulator() {
 
     public void accumulate(GenericUDAFEvaluator.AggregationBuffer acc, Object... inputs)
             throws HiveException {
+        // When the parameter of the function is (Integer, Array[Double]), Flink calls
+        // udf.eval(AggregationBuffer, Integer, Array[Double]), which is not a problem.
+        // But when the parameter is a single array, Flink calls udf.accumulate(AggregationBuffer,
+        // Array[Double]), at this point java's var-args will cast Array[Double] to Array[Object]
+        // and let it be Object... args, So we need wrap it.
+        if (isArgsSingleArray) {
+            inputs = new Object[] {inputs};
+        }
         if (!allIdentityConverter) {
             for (int i = 0; i < inputs.length; i++) {

Review Comment:
   That's why we should make this change. When argsType is array, we will wrap the inputs to array so that the length will be 1.



-- 
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] hehuiyuan commented on a diff in pull request #19423: [FLINK-27175][hive] Support to call Hive UDAF when the UDAF accepts one parameter with array type

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


##########
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/functions/hive/HiveGenericUDAF.java:
##########
@@ -105,6 +108,8 @@ private void init() throws HiveException {
                         GenericUDAFEvaluator.Mode.FINAL,
                         new ObjectInspector[] {partialResultObjectInspector});
 
+        isArgsSingleArray = HiveFunctionUtil.isSingleBoxedArray(argTypes);

Review Comment:
   @luoyuxia , I am wrong.
   Array(double) , the isNullable  of DoubleType is false,it will throw  exception.
   Array(double) , the isNullable  of DoubleType is true,it is normal.
   Your test can pass.



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