Vishwas created BEAM-7621:
-----------------------------
Summary: 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
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)