Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,22 @@ public void validateCall(SqlCall call, SqlValidatorScope scope)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -149,6 +150,7 @@
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;
Expand Down Expand Up @@ -15592,6 +15594,23 @@ public void testDistinctNotSupportedWithWindow()
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()
{
Expand Down