mirror of https://github.com/apache/druid.git
SQL: Remove useless boolean CASTs in filters. (#5619)
This commit is contained in:
parent
80fa5094e8
commit
ff27c54774
|
@ -218,9 +218,12 @@ public class Expressions
|
||||||
final RexNode expression
|
final RexNode expression
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (expression.getKind() == SqlKind.AND
|
if (expression.getKind() == SqlKind.CAST && expression.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) {
|
||||||
|| expression.getKind() == SqlKind.OR
|
// Calcite sometimes leaves errant, useless cast-to-booleans inside filters. Strip them and continue.
|
||||||
|| expression.getKind() == SqlKind.NOT) {
|
return toFilter(plannerContext, rowSignature, Iterables.getOnlyElement(((RexCall) expression).getOperands()));
|
||||||
|
} else if (expression.getKind() == SqlKind.AND
|
||||||
|
|| expression.getKind() == SqlKind.OR
|
||||||
|
|| expression.getKind() == SqlKind.NOT) {
|
||||||
final List<DimFilter> filters = Lists.newArrayList();
|
final List<DimFilter> filters = Lists.newArrayList();
|
||||||
for (final RexNode rexNode : ((RexCall) expression).getOperands()) {
|
for (final RexNode rexNode : ((RexCall) expression).getOperands()) {
|
||||||
final DimFilter nextFilter = toFilter(
|
final DimFilter nextFilter = toFilter(
|
||||||
|
|
|
@ -2965,6 +2965,34 @@ public class CalciteQueryTest extends CalciteTestBase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveUselessCaseWhen() throws Exception
|
||||||
|
{
|
||||||
|
testQuery(
|
||||||
|
"SELECT COUNT(*) FROM druid.foo\n"
|
||||||
|
+ "WHERE\n"
|
||||||
|
+ " CASE\n"
|
||||||
|
+ " WHEN __time >= TIME_PARSE('2000-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss') AND __time < TIMESTAMP '2001-01-01 00:00:00'\n"
|
||||||
|
+ " THEN true\n"
|
||||||
|
+ " ELSE false\n"
|
||||||
|
+ " END\n"
|
||||||
|
+ "OR\n"
|
||||||
|
+ " __time >= TIMESTAMP '2010-01-01 00:00:00' AND __time < TIMESTAMP '2011-01-01 00:00:00'",
|
||||||
|
ImmutableList.of(
|
||||||
|
Druids.newTimeseriesQueryBuilder()
|
||||||
|
.dataSource(CalciteTests.DATASOURCE1)
|
||||||
|
.intervals(QSS(Intervals.of("2000/2001"), Intervals.of("2010/2011")))
|
||||||
|
.granularity(Granularities.ALL)
|
||||||
|
.aggregators(AGGS(new CountAggregatorFactory("a0")))
|
||||||
|
.context(TIMESERIES_CONTEXT_DEFAULT)
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
ImmutableList.of(
|
||||||
|
new Object[]{3L}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCountStarWithTimeMillisecondFilters() throws Exception
|
public void testCountStarWithTimeMillisecondFilters() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue