/** If there is at least one call to an aggregate function, returns the * first. */ private SqlNode getAgg(SqlSelect select) { final SelectScope selectScope = getRawSelectScope(select); if (selectScope != null) { final List<SqlNode> selectList = selectScope.getExpandedSelectList(); if (selectList != null) { return aggFinder.findAgg(selectList); } } return aggFinder.findAgg(select.getSelectList()); }
public void declareCursor(SqlSelect select, SqlValidatorScope parentScope) { cursorSet.add(select); // add the cursor to a map that maps the cursor to its select based on // the position of the cursor relative to other cursors in that call FunctionParamInfo funcParamInfo = functionCallStack.peek(); Map<Integer, SqlSelect> cursorMap = funcParamInfo.cursorPosToSelectMap; int numCursors = cursorMap.size(); cursorMap.put(numCursors, select); // create a namespace associated with the result of the select // that is the argument to the cursor constructor; register it // with a scope corresponding to the cursor SelectScope cursorScope = new SelectScope(parentScope, null, select); cursorScopes.put(select, cursorScope); final SelectNamespace selectNs = createSelectNamespace(select, select); String alias = deriveAlias(select, nextGeneratedId++); registerNamespace(cursorScope, alias, selectNs, false); }
SqlSelect sqlSelect = (SqlSelect) sqlQuery; final SelectScope scope = getRawSelectScope(sqlSelect); final List<SqlNode> selectList = scope.getExpandedSelectList(); final SqlNode selectItem = stripAs(selectList.get(i)); if (selectItem instanceof SqlIdentifier) { final SqlQualified qualified = scope.fullyQualify((SqlIdentifier) selectItem); SqlValidatorNamespace namespace = qualified.namespace; final SqlValidatorTable table = namespace.getTable();
if (windowScope.existingWindowName(declName.toString())) { throw newValidationError(declName, RESOURCE.duplicateWindowName()); } else { windowScope.addWindowName(declName.toString());
@Override public int getGroupCount() { final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); if (selectScope == null) { // Probably "VALUES expr". Treat same as "SELECT expr GROUP BY ()" return 0; } final SqlSelect select = selectScope.getNode(); final SqlNodeList group = select.getGroup(); if (group != null) { int n = 0; for (SqlNode groupItem : group) { if (!(groupItem instanceof SqlNodeList) || ((SqlNodeList) groupItem).size() != 0) { ++n; } } return n; } return validator.isAggregate(select) ? 0 : -1; }
String inputs = String.join(", ", scope.getChildNames()); throw newValidationError(select, Static.RESOURCE.cannotStreamResultsForNonStreamingInputs(inputs));
private boolean isSortCompatible(SelectScope scope, SqlNode node, boolean descending) { switch (node.getKind()) { case DESCENDING: return isSortCompatible(scope, ((SqlCall) node).getOperandList().get(0), true); } final SqlMonotonicity monotonicity = scope.getMonotonicity(node); switch (monotonicity) { case INCREASING: case STRICTLY_INCREASING: return !descending; case DECREASING: case STRICTLY_DECREASING: return descending; default: return false; } }
SqlValidatorUtil.getEnclosingSelectScope(scope); if ((selectScope != null) && (selectScope.getChildren().size() == 1)) { RelDataType rowType = selectScope.getChildren().get(0).getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add(
public boolean existingWindowName(String winName) { for (String windowName : windowNames) { if (windowName.equalsIgnoreCase(winName)) { return true; } } // if the name wasn't found then check the parent(s) SqlValidatorScope walker = parent; while (!(walker instanceof EmptyScope)) { if (walker instanceof SelectScope) { final SelectScope parentScope = (SelectScope) walker; return parentScope.existingWindowName(winName); } walker = ((DelegatingScope) walker).parent; } return false; }
@Override public int getGroupCount() { final SelectScope selectScope = SqlValidatorUtil.getEnclosingSelectScope(scope); if (selectScope == null) { // Probably "VALUES expr". Treat same as "SELECT expr GROUP BY ()" return 0; } final SqlSelect select = selectScope.getNode(); final SqlNodeList group = select.getGroup(); if (group != null) { int n = 0; for (SqlNode groupItem : group) { if (!(groupItem instanceof SqlNodeList) || ((SqlNodeList) groupItem).size() != 0) { ++n; } } return n; } return validator.isAggregate(select) ? 0 : -1; }
SqlSelect sqlSelect = (SqlSelect) sqlQuery; final SelectScope scope = getRawSelectScope(sqlSelect); final List<SqlNode> selectList = scope.getExpandedSelectList(); final SqlNode selectItem = stripAs(selectList.get(i)); if (selectItem instanceof SqlIdentifier) { final SqlQualified qualified = scope.fullyQualify((SqlIdentifier) selectItem); SqlValidatorNamespace namespace = qualified.namespace; final SqlValidatorTable table = namespace.getTable();
if (windowScope.existingWindowName(declName.toString())) { throw newValidationError(declName, RESOURCE.duplicateWindowName()); } else { windowScope.addWindowName(declName.toString());
List<String> names = fromScope.getChildNames(); if (!catalogReader.nameMatcher().isCaseSensitive()) { names = Lists.transform(names, s -> s.toUpperCase(Locale.ROOT));
/** * Returns whether any of the given expressions are sorted. * * <p>If so, it can be the default ORDER BY clause for a WINDOW specification. * (This is an extension to the SQL standard for streaming.) */ static boolean containsMonotonic(SelectScope scope, SqlNodeList nodes) { for (SqlNode node : nodes) { if (!scope.getMonotonicity(node).mayRepeat()) { return true; } } return false; }
SqlValidatorUtil.getEnclosingSelectScope(scope); if ((selectScope != null) && (selectScope.getChildren().size() == 1)) { RelDataType rowType = selectScope.getChildren().get(0).getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add(
public boolean existingWindowName(String winName) { for (String windowName : windowNames) { if (windowName.equalsIgnoreCase(winName)) { return true; } } // if the name wasn't found then check the parent(s) SqlValidatorScope walker = parent; while (!(walker instanceof EmptyScope)) { if (walker instanceof SelectScope) { final SelectScope parentScope = (SelectScope) walker; return parentScope.existingWindowName(winName); } walker = ((DelegatingScope) walker).parent; } return false; }
public SqlMonotonicity getMonotonicity(String columnName) { final RelDataType rowType = this.getRowTypeSansSystemColumns(); final int field = SqlTypeUtil.findField(rowType, columnName); final SqlNode selectItem = validator.getRawSelectScope(select) .getExpandedSelectList().get(field); return validator.getSelectScope(select).getMonotonicity(selectItem); } }
assert selectScope != null; final SqlValidatorNamespace selectNamespace = validator.getNamespace(selectScope.getNode()); final List<String> names = selectNamespace.getRowType().getFieldNames();
SqlSelect sqlSelect = (SqlSelect) sqlQuery; final SelectScope scope = getRawSelectScope(sqlSelect); final List<SqlNode> selectList = scope.getExpandedSelectList(); final SqlNode selectItem = stripAs(selectList.get(i)); if (selectItem instanceof SqlIdentifier) { final SqlQualified qualified = scope.fullyQualify((SqlIdentifier) selectItem); SqlValidatorNamespace namespace = qualified.namespace; final SqlValidatorTable table = namespace.getTable();