Skip to content
Open
Show file tree
Hide file tree
Changes from 20 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 @@ -924,6 +924,9 @@ ExInst<CalciteException> illegalArgumentForTableFunctionCall(String a0,
@BaseMessage("Extended columns not allowed under the current SQL conformance level")
ExInst<SqlValidatorException> extendNotAllowed();

@BaseMessage("Aggregate function referencing outer column is not allowed under the current SQL conformance level")
ExInst<SqlValidatorException> correlatedAggregateNotAllowed();

@BaseMessage("Rolled up column ''{0}'' is not allowed in {1}")
ExInst<SqlValidatorException> rolledUpNotAllowed(String column, String context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ public abstract class SqlAbstractConformance implements SqlConformance {
@Override public boolean isDistinctOnAllowed() {
return SqlConformanceEnum.DEFAULT.isDistinctOnAllowed();
}

@Override public boolean isCorrelatedAggregateAllowed() {
return SqlConformanceEnum.DEFAULT.isCorrelatedAggregateAllowed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -691,4 +691,20 @@ default boolean isColonFieldAccessAllowed() {
* false otherwise.
*/
boolean isDistinctOnAllowed();

/**
* Whether an aggregate function inside a scalar sub-query is allowed to
* reference columns from an outer query.
*
* <p>This is not allowed by the SQL standard, but is supported by some
* databases, including SQLite, DuckDB and SQL Server.
*
* <p>Among the built-in conformance levels, true in
* {@link SqlConformanceEnum#BABEL},
* {@link SqlConformanceEnum#LENIENT};
* false otherwise.
*/
default boolean isCorrelatedAggregateAllowed() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,14 @@ public enum SqlConformanceEnum implements SqlConformance {
return false;
}
}

@Override public boolean isCorrelatedAggregateAllowed() {
switch (this) {
case BABEL:
case LENIENT:
return true;
default:
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,8 @@ protected SqlDelegatingConformance(SqlConformance delegate) {
@Override public boolean isDistinctOnAllowed() {
return delegate.isDistinctOnAllowed();
}

@Override public boolean isCorrelatedAggregateAllowed() {
return delegate.isCorrelatedAggregateAllowed();
}
}
Loading
Loading