You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/08/04 19:48:00 UTC

[jira] [Work logged] (BEAM-10633) UdfImpl when returns java.util.List will hit a NPE

     [ https://issues.apache.org/jira/browse/BEAM-10633?focusedWorklogId=466420&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-466420 ]

ASF GitHub Bot logged work on BEAM-10633:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Aug/20 19:47
            Start Date: 04/Aug/20 19:47
    Worklog Time Spent: 10m 
      Work Description: ibzib commented on a change in pull request #12461:
URL: https://github.com/apache/beam/pull/12461#discussion_r465289699



##########
File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamSqlDslUdfUdafTest.java
##########
@@ -101,6 +103,21 @@ public void testJodaTimeUdfUdaf() throws Exception {
     pipeline.run().waitUntilFinish();
   }
 
+  @Test
+  public void testListUdf() throws Exception {
+    Schema resultType = Schema.builder().addArrayField("array_field", FieldType.INT64).build();
+
+    Row row1 = Row.withSchema(resultType).addValue(Arrays.asList(1L)).build();

Review comment:
       Nit: why are row1, sql1, etc. variable names numbered when there's only one of each?

##########
File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/CalciteUtils.java
##########
@@ -285,16 +286,23 @@ private static RelDataType toRelDataType(
    * SQL-Java type mapping, with specified Beam rules: <br>
    * 1. redirect {@link AbstractInstant} to {@link Date} so Calcite can recognize it.
    *
-   * @param rawType
+   * @param type
    * @return
    */
-  public static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory typeFactory, Type rawType) {
+  public static RelDataType sqlTypeWithAutoCast(RelDataTypeFactory typeFactory, Type type) {
     // For Joda time types, return SQL type for java.util.Date.
-    if (rawType instanceof Class && AbstractInstant.class.isAssignableFrom((Class<?>) rawType)) {
+    if (type instanceof Class && AbstractInstant.class.isAssignableFrom((Class<?>) type)) {
       return typeFactory.createJavaType(Date.class);
-    } else if (rawType instanceof Class && ByteString.class.isAssignableFrom((Class<?>) rawType)) {
+    } else if (type instanceof Class && ByteString.class.isAssignableFrom((Class<?>) type)) {
       return typeFactory.createJavaType(byte[].class);
+    } else if (type instanceof ParameterizedType
+        && java.util.List.class.isAssignableFrom(
+            (Class<?>) ((ParameterizedType) type).getRawType())) {
+      ParameterizedType parameterizedType = (ParameterizedType) type;
+      Class<?> genericType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
+      RelDataType collectionElementType = typeFactory.createJavaType(genericType);
+      return typeFactory.createArrayType(collectionElementType, -1L);

Review comment:
       ```suggestion
         return typeFactory.createArrayType(collectionElementType, UNLIMITED_ARRAY_SIZE);
   ```

##########
File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/utils/CalciteUtils.java
##########
@@ -285,16 +286,23 @@ private static RelDataType toRelDataType(
    * SQL-Java type mapping, with specified Beam rules: <br>
    * 1. redirect {@link AbstractInstant} to {@link Date} so Calcite can recognize it.

Review comment:
       We should probably update this comment to explain how/why ByteString and List are special cases.




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

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 466420)
    Time Spent: 0.5h  (was: 20m)

> UdfImpl when returns java.util.List will hit a NPE
> --------------------------------------------------
>
>                 Key: BEAM-10633
>                 URL: https://issues.apache.org/jira/browse/BEAM-10633
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Rui Wang
>            Priority: P2
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)