mirror of https://github.com/apache/druid.git
Fix NPE for subquery with limit (#8775)
* Fix NPE for subquery with limit * Mark it as unplannable by returning null * Migrate testcases from SqlResourceTest to CalciteQueryTest * Throw CannotBuildQueryException * Fix typo * Patch comments
This commit is contained in:
parent
301c0649a7
commit
24be558347
|
@ -36,6 +36,7 @@ import org.apache.druid.java.util.common.guava.Sequence;
|
|||
import org.apache.druid.java.util.common.guava.Sequences;
|
||||
import org.apache.druid.query.QueryDataSource;
|
||||
import org.apache.druid.query.TableDataSource;
|
||||
import org.apache.druid.query.groupby.GroupByQuery;
|
||||
import org.apache.druid.sql.calcite.table.RowSignature;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -128,9 +129,14 @@ public class DruidOuterQueryRel extends DruidRel<DruidOuterQueryRel>
|
|||
return null;
|
||||
}
|
||||
|
||||
final GroupByQuery groupByQuery = subQuery.toGroupByQuery();
|
||||
if (groupByQuery == null) {
|
||||
throw new CannotBuildQueryException("Subquery could not be converted to GroupBy query");
|
||||
}
|
||||
|
||||
final RowSignature sourceRowSignature = subQuery.getOutputRowSignature();
|
||||
return partialQuery.build(
|
||||
new QueryDataSource(subQuery.toGroupByQuery()),
|
||||
new QueryDataSource(groupByQuery),
|
||||
sourceRowSignature,
|
||||
getPlannerContext(),
|
||||
getCluster().getRexBuilder(),
|
||||
|
|
|
@ -7776,6 +7776,39 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingSubqueryWithLimit() throws Exception
|
||||
{
|
||||
expectedException.expect(CannotBuildQueryException.class);
|
||||
expectedException.expectMessage("Subquery could not be converted to GroupBy query");
|
||||
|
||||
testQuery(
|
||||
"SELECT COUNT(*) AS cnt FROM ( SELECT * FROM druid.foo LIMIT 10 ) tmpA",
|
||||
ImmutableList.of(),
|
||||
ImmutableList.of()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUsingSubqueryWithoutLimit() throws Exception
|
||||
{
|
||||
testQuery(
|
||||
"SELECT COUNT(*) AS cnt FROM ( SELECT * FROM druid.foo ) tmpA",
|
||||
ImmutableList.of(
|
||||
Druids.newTimeseriesQueryBuilder()
|
||||
.dataSource(CalciteTests.DATASOURCE1)
|
||||
.intervals(querySegmentSpec(Filtration.eternity()))
|
||||
.granularity(Granularities.ALL)
|
||||
.aggregators(aggregators(new CountAggregatorFactory("a0")))
|
||||
.context(TIMESERIES_CONTEXT_DEFAULT)
|
||||
.build()
|
||||
),
|
||||
ImmutableList.of(
|
||||
new Object[]{6L}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnicodeFilterAndGroupBy() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue