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

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

                Author: ASF GitHub Bot
            Created on: 24/Jun/19 12:00
            Start Date: 24/Jun/19 12:00
    Worklog Time Spent: 10m 
      Work Description: nrchakradhar commented on pull request #8930: 
[BEAM-7621] Null pointer exception when accessing null row fields in BeamSql
URL: https://github.com/apache/beam/pull/8930#discussion_r296686844
 
 

 ##########
 File path: 
sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamComplexTypeTest.java
 ##########
 @@ -246,4 +253,28 @@ public void testRowConstructor() {
                 .build());
     pipeline.run().waitUntilFinish(Duration.standardMinutes(2));
   }
+
+  @Test
 
 Review comment:
   This test only includes both fields to be null. Can another test be added 
where one of the field is valid and SQL query uses both fields.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


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

            Worklog Id:     (was: 265677)
            Time Spent: 10m
    Remaining Estimate: 0h

> Selecting null row field's causes Null pointer Exception with BeamSql
> ---------------------------------------------------------------------
>
>                 Key: BEAM-7621
>                 URL: https://issues.apache.org/jira/browse/BEAM-7621
>             Project: Beam
>          Issue Type: Bug
>          Components: dsl-sql
>    Affects Versions: 2.14.0
>            Reporter: Vishwas
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I have below schema of the row:
>   private static final Schema innerRowWithArraySchema =
>       Schema.builder()
>           .addStringField("string_field")
>           .addArrayField("array_field", FieldType.INT64)
>           .build();
> private static final Schema nullableNestedRowWithArraySchema =
>           Schema.builder()
>               
> .addNullableField("field1",FieldType.row(innerRowWithArraySchema))
>               .addNullableField("field2", 
> FieldType.array(FieldType.row(innerRowWithArraySchema)))
>               .build();
>  
> *// Create a row with null values*
> Row nullRow = Row.nullRow(nullableNestedRowWithArraySchema);
>  
> Now when we try to select nested row field's NPE is thrown:
> .apply(SqlTransform.query("select PCOLLECTION.field1.string_field as 
> row_string_field, PCOLLECTION.field2[2].string_field as array_string_field 
> from PCOLLECTION"));
>  
> Below is the exception thrown:
> Caused by: java.lang.RuntimeException: CalcFn failed to evaluate: {
>   final org.apache.beam.sdk.values.Row current = 
> (org.apache.beam.sdk.values.Row) c.element();
>   *final java.util.List inp1_ = 
> org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel.WrappedList.of(current.getRow(1));*
>   *final java.util.List inp2_ = 
> org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel.WrappedList.of(current.getArray(2));*
>   
> c.output(org.apache.beam.sdk.values.Row.withSchema(outputSchema).addValue(inp1_
>  == null ? (String) null : (String) 
> org.apache.beam.repackaged.beam_sdks_java_extensions_sql.org.apache.calcite.runtime.SqlFunctions.structAccess(inp1_,
>  0, 
> "string_field")).addValue(org.apache.beam.repackaged.beam_sdks_java_extensions_sql.org.apache.calcite.runtime.SqlFunctions.arrayItemOptional(inp2_,
>  2) == null ? (String) null : (String) 
> org.apache.beam.repackaged.beam_sdks_java_extensions_sql.org.apache.calcite.runtime.SqlFunctions.structAccess(org.apache.beam.repackaged.beam_sdks_java_extensions_sql.org.apache.calcite.runtime.SqlFunctions.arrayItemOptional(inp2_,
>  2), 0, "string_field")).build());
> }
>     at 
> org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel$CalcFn.processElement(BeamCalcRel.java:253)
> Caused by: java.lang.NullPointerException
>     at 
> org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel$WrappedList.of(BeamCalcRel.java:459)
>     at SC.eval0(Unknown Source)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  
> In BeamCalcRel.class *field* method, null values are not handled for 
> composite types.
>     public Expression field(BlockBuilder list, int index, Type storageType) {
>      ....
>       } else if (fromType.getTypeName().isCompositeType()
>           || (fromType.getTypeName().isCollectionType()
>               && 
> fromType.getCollectionElementType().getTypeName().isCompositeType())) {
>         field = Expressions.call(WrappedList.class, "of", field);  // 
> List.of() is passed with null values
>       }
>       ... 
>     }
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to