Keep traitSet of logicalValues (#11138)

This commit is contained in:
Jihoon Son 2021-04-27 18:45:23 -07:00 committed by GitHub
parent 57ddae782e
commit 261c1f271f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 9 deletions

View File

@ -76,7 +76,7 @@ public class DruidQueryRel extends DruidRel<DruidQueryRel>
return new DruidQueryRel(
scanRel.getCluster(),
scanRel.getCluster().traitSetOf(Convention.NONE),
table,
Preconditions.checkNotNull(table, "table"),
druidTable,
queryMaker,
PartialDruidQuery.create(scanRel)
@ -91,7 +91,7 @@ public class DruidQueryRel extends DruidRel<DruidQueryRel>
{
return new DruidQueryRel(
valuesRel.getCluster(),
valuesRel.getCluster().traitSetOf(Convention.NONE),
valuesRel.getTraitSet(), // the traitSet of valuesRel should be kept
null,
druidTable,
queryMaker,

View File

@ -109,6 +109,7 @@ import org.apache.druid.query.topn.TopNQueryBuilder;
import org.apache.druid.segment.column.RowSignature;
import org.apache.druid.segment.column.ValueType;
import org.apache.druid.segment.join.JoinType;
import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
import org.apache.druid.server.QueryLifecycle;
import org.apache.druid.server.QueryLifecycleFactory;
import org.apache.druid.server.security.Access;
@ -150,7 +151,29 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
// from a table.
testQuery(
"SELECT REGEXP_EXTRACT('foo', '^(.)')",
ImmutableList.of(),
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(
InlineDataSource.fromIterable(
ImmutableList.of(new Object[]{0L}),
RowSignature.builder().add("ZERO", ValueType.LONG).build()
)
)
.intervals(querySegmentSpec(Filtration.eternity()))
.virtualColumns(
new ExpressionVirtualColumn(
"v0",
"'f'",
ValueType.STRING,
ExprMacroTable.nil()
)
)
.columns("v0")
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of(
new Object[]{"f"}
)
@ -160,13 +183,32 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
@Test
public void testExpressionContainingNull() throws Exception
{
List<String> expectedResult = new ArrayList<>();
expectedResult.add("Hello");
expectedResult.add(null);
testQuery(
"SELECT ARRAY ['Hello', NULL]",
ImmutableList.of(),
ImmutableList.of(new Object[]{expectedResult})
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(
InlineDataSource.fromIterable(
ImmutableList.of(new Object[]{0L}),
RowSignature.builder().add("ZERO", ValueType.LONG).build()
)
)
.intervals(querySegmentSpec(Filtration.eternity()))
.virtualColumns(
new ExpressionVirtualColumn(
"v0",
"array('Hello',null)",
ValueType.STRING,
ExprMacroTable.nil()
)
)
.columns("v0")
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of(new Object[]{"[\"Hello\",null]"})
);
}
@ -7543,7 +7585,21 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
testQuery(
"SELECT dim2 FROM druid.foo ORDER BY dim2 LIMIT 0",
ImmutableList.of(
Druids.newScanQueryBuilder()
.dataSource(
InlineDataSource.fromIterable(
ImmutableList.of(),
RowSignature.builder().add("dim2", ValueType.STRING).build()
)
)
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("dim2")
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.legacy(false)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of()
);
}