Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ public Object computeForValue(Expression expression, Object[] inputFields) {
}
parDataType = ((SeaTunnelRowType) parDataType).getFieldType(idx);
res = parRowValues.getFields()[idx];
if (res == null) {
return null;
}
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.seatunnel.transform.sql.zeta;

import org.apache.seatunnel.api.table.type.BasicType;
import org.apache.seatunnel.api.table.type.MapType;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
Expand Down Expand Up @@ -54,4 +55,29 @@ public void testCastFunction() {
Assertions.assertEquals(Byte.parseByte("1"), f2Object);
Assertions.assertEquals(Short.parseShort("1"), f3Object);
}

@Test
public void testCastFunctionWithNullNestedField() {
SQLEngine sqlEngine = SQLEngineFactory.getSQLEngine(SQLEngineFactory.EngineType.ZETA);

SeaTunnelRowType rowType =
new SeaTunnelRowType(
new String[] {"user"},
new SeaTunnelDataType[] {
new MapType<>(BasicType.STRING_TYPE, BasicType.STRING_TYPE)
});

SeaTunnelRow inputRow = new SeaTunnelRow(new Object[] {null});

sqlEngine.init("test", null, rowType, "select user.address as address from test");

SeaTunnelRowType outRowType = sqlEngine.typeMapping(null);

SeaTunnelRow outRow = sqlEngine.transformBySQL(inputRow, outRowType).get(0);

Object addressField = outRow.getField(0);
Assertions.assertNull(
addressField,
"When casting nested field where intermediate value is null, result should be null");
}
}