Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-7621

Selecting null row field's causes Null pointer Exception with BeamSql

Details

    • Bug
    • Status: Resolved
    • P2
    • Resolution: Fixed
    • 2.14.0
    • 2.16.0
    • dsl-sql
    • None

    Description

      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       }

            ...
          }

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            vbm Vishwas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 3.5h
                3.5h