Handling null operand in JSON_QUERY_ARRAY (#16118)

* fix return type inference for JSON_QUERY_ARRAY to be nullable
This commit is contained in:
Sree Charan Manamala 2024-03-14 06:36:27 +05:30 committed by GitHub
parent 256160aba6
commit e9d2caccb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View File

@ -253,7 +253,7 @@ public class NestedDataOperatorConversions
SqlTypeFamily.CHARACTER
)
)
.returnTypeInference(NESTED_ARRAY_RETURN_TYPE_INFERENCE)
.returnTypeInference(NESTED_ARRAY_RETURN_TYPE_INFERENCE.andThen(SqlTypeTransforms.FORCE_NULLABLE))
.functionCategory(SqlFunctionCategory.SYSTEM)
.build();

View File

@ -6626,6 +6626,46 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest
.run();
}
@Test
public void testJsonQueryArrayNullArray()
{
cannotVectorize();
testBuilder()
.sql("SELECT JSON_QUERY_ARRAY(arrayObject, '$.') FROM druid.arrays where arrayObject is null limit 1")
.queryContext(QUERY_CONTEXT_DEFAULT)
.expectedQueries(
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(DATA_SOURCE_ARRAYS)
.intervals(querySegmentSpec(Filtration.eternity()))
.virtualColumns(
expressionVirtualColumn(
"v0",
"null",
ColumnType.ofArray(ColumnType.NESTED_DATA)
)
)
.filters(isNull("arrayObject"))
.columns("v0")
.limit(1)
.context(QUERY_CONTEXT_DEFAULT)
.legacy(false)
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.build()
)
)
.expectedResults(
NullHandling.replaceWithDefault() ?
ImmutableList.of(new Object[]{null}) : ImmutableList.of()
)
.expectedSignature(
RowSignature.builder()
.add("EXPR$0", ColumnType.ofArray(ColumnType.NESTED_DATA))
.build()
)
.run();
}
@Test
public void testUnnestJsonQueryArrays()
{