mirror of https://github.com/apache/druid.git
Check for Aggregation inside a window clause when syntax used as - WINDOW W AS DEF (#16801)
This commit is contained in:
parent
725d442355
commit
9b76d13ff8
|
@ -796,6 +796,22 @@ public class DruidSqlValidator extends BaseDruidSqlValidator
|
|||
super.validateCall(call, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validateWindowClause(SqlSelect select)
|
||||
{
|
||||
SqlNodeList windows = select.getWindowList();
|
||||
for (SqlNode sqlNode : windows) {
|
||||
if (SqlUtil.containsAgg(sqlNode)) {
|
||||
throw buildCalciteContextException(
|
||||
"Aggregation inside window is currently not supported with syntax WINDOW W AS <DEF>. "
|
||||
+ "Try providing window definition directly without alias",
|
||||
sqlNode
|
||||
);
|
||||
}
|
||||
}
|
||||
super.validateWindowClause(select);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SqlNode performUnconditionalRewrites(SqlNode node, final boolean underFrom)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.calcite.rel.RelNode;
|
||||
import org.apache.calcite.runtime.CalciteContextException;
|
||||
import org.apache.druid.common.config.NullHandling;
|
||||
import org.apache.druid.error.DruidException;
|
||||
|
@ -149,6 +150,7 @@ import java.util.Map;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
|
@ -15592,6 +15594,23 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
assertThat(e, invalidSqlContains("DISTINCT is not supported for window functions"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnSupportedAggInSelectWindow()
|
||||
{
|
||||
assertEquals(
|
||||
"1.37.0",
|
||||
RelNode.class.getPackage().getImplementationVersion(),
|
||||
"Calcite version changed; check if CALCITE-6500 is fixed and update:\n * method DruidSqlValidator#validateWindowClause"
|
||||
);
|
||||
|
||||
DruidException e = assertThrows(DruidException.class, () -> testBuilder()
|
||||
.queryContext(ImmutableMap.of(PlannerContext.CTX_ENABLE_WINDOW_FNS, true))
|
||||
.sql("SELECT dim1, ROW_NUMBER() OVER W from druid.foo WINDOW W as (ORDER BY max(length(dim1)))")
|
||||
.run());
|
||||
|
||||
assertThat(e, invalidSqlContains("not supported with syntax WINDOW W AS <DEF>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInGroupByLimitOutGroupByOrderBy()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue