use of org.apache.calcite.sql.SqlWindow in project calcite by apache.
the class SqlValidatorImpl method validateWindow.
public void validateWindow(SqlNode windowOrId, SqlValidatorScope scope, SqlCall call) {
// Enable nested aggregates with window aggregates (OVER operator)
inWindow = true;
final SqlWindow targetWindow;
switch(windowOrId.getKind()) {
case IDENTIFIER:
// Just verify the window exists in this query. It will validate
// when the definition is processed
targetWindow = getWindowByName((SqlIdentifier) windowOrId, scope);
break;
case WINDOW:
targetWindow = (SqlWindow) windowOrId;
break;
default:
throw Util.unexpected(windowOrId.getKind());
}
assert targetWindow.getWindowCall() == null;
targetWindow.setWindowCall(call);
targetWindow.validate(this, scope);
targetWindow.setWindowCall(null);
call.validate(this, scope);
validateAggregateParams(call, null, scope);
// Disable nested aggregates post validation
inWindow = false;
}
use of org.apache.calcite.sql.SqlWindow in project calcite by apache.
the class SqlValidatorImpl method getWindowByName.
protected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope) {
SqlWindow window = null;
if (id.isSimple()) {
final String name = id.getSimple();
window = scope.lookupWindow(name);
}
if (window == null) {
throw newValidationError(id, RESOURCE.windowNotFound(id.toString()));
}
return window;
}
use of org.apache.calcite.sql.SqlWindow in project calcite by apache.
the class SqlValidatorImpl method validateWindowClause.
protected void validateWindowClause(SqlSelect select) {
final SqlNodeList windowList = select.getWindowList();
@SuppressWarnings("unchecked") final List<SqlWindow> windows = (List) windowList.getList();
if (windows.isEmpty()) {
return;
}
final SelectScope windowScope = (SelectScope) getFromScope(select);
assert windowScope != null;
// 2. ensure they are unique within this scope
for (SqlWindow window : windows) {
SqlIdentifier declName = window.getDeclName();
if (!declName.isSimple()) {
throw newValidationError(declName, RESOURCE.windowNameMustBeSimple());
}
if (windowScope.existingWindowName(declName.toString())) {
throw newValidationError(declName, RESOURCE.duplicateWindowName());
} else {
windowScope.addWindowName(declName.toString());
}
}
// Check for pairs of windows which are equivalent.
for (int i = 0; i < windows.size(); i++) {
SqlNode window1 = windows.get(i);
for (int j = i + 1; j < windows.size(); j++) {
SqlNode window2 = windows.get(j);
if (window1.equalsDeep(window2, Litmus.IGNORE)) {
throw newValidationError(window2, RESOURCE.dupWindowSpec());
}
}
}
for (SqlWindow window : windows) {
final SqlNodeList expandedOrderList = (SqlNodeList) expand(window.getOrderList(), windowScope);
window.setOrderList(expandedOrderList);
expandedOrderList.validate(this, windowScope);
final SqlNodeList expandedPartitionList = (SqlNodeList) expand(window.getPartitionList(), windowScope);
window.setPartitionList(expandedPartitionList);
expandedPartitionList.validate(this, windowScope);
}
// Hand off to validate window spec components
windowList.validate(this, windowScope);
}
use of org.apache.calcite.sql.SqlWindow in project calcite by apache.
the class SelectScope method lookupWindow.
public SqlWindow lookupWindow(String name) {
final SqlNodeList windowList = select.getWindowList();
for (int i = 0; i < windowList.size(); i++) {
SqlWindow window = (SqlWindow) windowList.get(i);
final SqlIdentifier declId = window.getDeclName();
assert declId.isSimple();
if (declId.names.get(0).equals(name)) {
return window;
}
}
// if not in the select scope, then check window scope
if (windowParent != null) {
return windowParent.lookupWindow(name);
} else {
return null;
}
}
use of org.apache.calcite.sql.SqlWindow in project flink by apache.
the class SqlValidatorImpl method getWindowByName.
protected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope) {
SqlWindow window = null;
if (id.isSimple()) {
final String name = id.getSimple();
window = scope.lookupWindow(name);
}
if (window == null) {
throw newValidationError(id, RESOURCE.windowNotFound(id.toString()));
}
return window;
}
Aggregations