mirror of
https://github.com/apache/druid.git
synced 2025-03-02 07:19:14 +00:00
Fix assertion error in sql planning for latest aggregators (#13151)
* Fix sql planning bug for latest aggregators * change test name * Fix error messages * fix error message again
This commit is contained in:
parent
cffa3bd263
commit
94e36731f9
@ -202,12 +202,20 @@ public class EarliestLatestAnySqlAggregator implements SqlAggregator
|
|||||||
theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, -1);
|
theAggFactory = aggregatorType.createAggregatorFactory(aggregatorName, fieldName, null, outputType, -1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
int maxStringBytes;
|
||||||
|
try {
|
||||||
|
maxStringBytes = RexLiteral.intValue(rexNodes.get(1));
|
||||||
|
}
|
||||||
|
catch (AssertionError ae) {
|
||||||
|
plannerContext.setPlanningError("The second argument '%s' to function '%s' is not a number", rexNodes.get(1), aggregateCall.getName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
theAggFactory = aggregatorType.createAggregatorFactory(
|
theAggFactory = aggregatorType.createAggregatorFactory(
|
||||||
aggregatorName,
|
aggregatorName,
|
||||||
fieldName,
|
fieldName,
|
||||||
null,
|
null,
|
||||||
outputType,
|
outputType,
|
||||||
RexLiteral.intValue(rexNodes.get(1))
|
maxStringBytes
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -122,12 +122,20 @@ public class EarliestLatestBySqlAggregator implements SqlAggregator
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
int maxStringBytes;
|
||||||
|
try {
|
||||||
|
maxStringBytes = RexLiteral.intValue(rexNodes.get(2));
|
||||||
|
}
|
||||||
|
catch (AssertionError ae) {
|
||||||
|
plannerContext.setPlanningError("The third argument '%s' to function '%s' is not a number", rexNodes.get(2), aggregateCall.getName());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
theAggFactory = aggregatorType.createAggregatorFactory(
|
theAggFactory = aggregatorType.createAggregatorFactory(
|
||||||
aggregatorName,
|
aggregatorName,
|
||||||
fieldName,
|
fieldName,
|
||||||
EarliestLatestAnySqlAggregator.getColumnName(plannerContext, virtualColumnRegistry, args.get(1), rexNodes.get(1)),
|
EarliestLatestAnySqlAggregator.getColumnName(plannerContext, virtualColumnRegistry, args.get(1), rexNodes.get(1)),
|
||||||
outputType,
|
outputType,
|
||||||
RexLiteral.intValue(rexNodes.get(2))
|
maxStringBytes
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -997,6 +997,56 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringLatestGroupByWithAlwaysFalseCondition()
|
||||||
|
{
|
||||||
|
testQuery(
|
||||||
|
"SELECT LATEST(dim4, 10),dim2 FROM numfoo WHERE (dim1 = 'something' AND dim1 IN( 'something else') ) GROUP BY dim2",
|
||||||
|
ImmutableList.of(
|
||||||
|
Druids.newScanQueryBuilder()
|
||||||
|
.dataSource(InlineDataSource.fromIterable(
|
||||||
|
ImmutableList.of(),
|
||||||
|
RowSignature.builder()
|
||||||
|
.add("EXPR$0", ColumnType.STRING)
|
||||||
|
.add("dim2", ColumnType.STRING)
|
||||||
|
.build()
|
||||||
|
))
|
||||||
|
.intervals(querySegmentSpec(Filtration.eternity()))
|
||||||
|
.columns("EXPR$0", "dim2")
|
||||||
|
.context(QUERY_CONTEXT_DEFAULT)
|
||||||
|
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
|
||||||
|
.legacy(false)
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
ImmutableList.of()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStringLatestByGroupByWithAlwaysFalseCondition()
|
||||||
|
{
|
||||||
|
testQuery(
|
||||||
|
"SELECT LATEST_BY(dim4, __time, 10),dim2 FROM numfoo WHERE (dim1 = 'something' AND dim1 IN( 'something else') ) GROUP BY dim2",
|
||||||
|
ImmutableList.of(
|
||||||
|
Druids.newScanQueryBuilder()
|
||||||
|
.dataSource(InlineDataSource.fromIterable(
|
||||||
|
ImmutableList.of(),
|
||||||
|
RowSignature.builder()
|
||||||
|
.add("EXPR$0", ColumnType.STRING)
|
||||||
|
.add("dim2", ColumnType.STRING)
|
||||||
|
.build()
|
||||||
|
))
|
||||||
|
.intervals(querySegmentSpec(Filtration.eternity()))
|
||||||
|
.columns("EXPR$0", "dim2")
|
||||||
|
.context(QUERY_CONTEXT_DEFAULT)
|
||||||
|
.resultFormat(ResultFormat.RESULT_FORMAT_COMPACTED_LIST)
|
||||||
|
.legacy(false)
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
ImmutableList.of()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// This test the off-heap (buffer) version of the EarliestAggregator (Double/Float/Long)
|
// This test the off-heap (buffer) version of the EarliestAggregator (Double/Float/Long)
|
||||||
@Test
|
@Test
|
||||||
public void testPrimitiveEarliestInSubquery()
|
public void testPrimitiveEarliestInSubquery()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user