fix lookup nullable (#11060)

* fix lookup nullable

* fix lookup unit test

* test null case
This commit is contained in:
chenyuzhi459 2021-04-03 12:56:42 +08:00 committed by GitHub
parent cfcebc40f6
commit 450535073e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -40,7 +40,7 @@ public class QueryLookupOperatorConversion implements SqlOperatorConversion
private static final SqlFunction SQL_FUNCTION = OperatorConversions
.operatorBuilder("LOOKUP")
.operandTypes(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)
.returnTypeNonNull(SqlTypeName.VARCHAR)
.returnTypeNullable(SqlTypeName.VARCHAR)
.functionCategory(SqlFunctionCategory.STRING)
.build();

View File

@ -17086,4 +17086,41 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
).build()
);
}
@Test
public void testLookupWithNull() throws Exception
{
List<Object[]> expected;
if (useDefault) {
expected = ImmutableList.<Object[]>builder().add(
new Object[]{NULL_STRING, NULL_STRING},
new Object[]{NULL_STRING, NULL_STRING},
new Object[]{NULL_STRING, NULL_STRING}
).build();
} else {
expected = ImmutableList.<Object[]>builder().add(
new Object[]{NULL_STRING, NULL_STRING},
new Object[]{NULL_STRING, NULL_STRING}
).build();
}
testQuery(
"SELECT dim2 ,lookup(dim2,'lookyloo') from foo where dim2 is null",
ImmutableList.of(
new Druids.ScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
.intervals(querySegmentSpec(Filtration.eternity()))
.virtualColumns(
expressionVirtualColumn("v0", "null", ValueType.STRING)
)
.columns("v0")
.legacy(false)
.filters(new SelectorDimFilter("dim2", NULL_STRING, null))
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
expected
);
}
}