SQL: Include virtual columns used for filtering in ScanQuery. (#7472)

PR #6902 introduced the ability to use virtual columns for filters, but they
were being omitted from "scan" queries, so filters would refer to a null column
instead of the intended virtual column.
This commit is contained in:
Gian Merlino 2019-04-14 15:03:36 -07:00 committed by GitHub
parent 6789438a49
commit 721191635a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -1011,7 +1011,7 @@ public class DruidQuery
return new ScanQuery(
dataSource,
filtration.getQuerySegmentSpec(),
selectProjection != null ? VirtualColumns.create(selectProjection.getVirtualColumns()) : VirtualColumns.EMPTY,
getVirtualColumns(true),
ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST,
0,
scanLimit,

View File

@ -575,6 +575,30 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
);
}
@Test
public void testSelectWithExpressionFilter() throws Exception
{
testQuery(
"SELECT dim1 FROM druid.foo WHERE m1 + 1 = 7",
ImmutableList.of(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
.intervals(querySegmentSpec(Filtration.eternity()))
.virtualColumns(
expressionVirtualColumn("v0", "(\"m1\" + 1)", ValueType.FLOAT)
)
.filters(selector("v0", "7", null))
.columns("dim1")
.resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of(
new Object[]{"abc"}
)
);
}
@Test
public void testSelectStarWithLimitTimeDescending() throws Exception
{