for (SqlNode selectItem : selectScope.getExpandedSelectList()) { ++ordinal; if (converted.equalsDeep(stripAs(selectItem), false)) {
SqlValidatorUtil.getEnclosingSelectScope(bb.scope); final SqlValidatorNamespace selectNamespace = validator.getNamespace(selectScope.getNode()); final List<String> names = selectNamespace.getRowType().getFieldNames();
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) { for (String name : id.names) { if (namespace == null) { namespace = scope.resolve(name, null, null); final SqlValidatorTable table = namespace.getTable(); if (table != null) {
if (windowScope.existingWindowName(declName.toString())) { throw newValidationError(declName, RESOURCE.duplicateWindowName()); } else { windowScope.addWindowName(declName.toString());
public SqlNodeList expandStar( SqlNodeList selectList, SqlSelect select, boolean includeSystemVars) { List<SqlNode> list = new ArrayList<SqlNode>(); List<Map.Entry<String, RelDataType>> types = new ArrayList<Map.Entry<String, RelDataType>>(); for (int i = 0; i < selectList.size(); i++) { final SqlNode selectItem = selectList.get(i); expandSelectItem( selectItem, select, list, new LinkedHashSet<String>(), types, includeSystemVars); } getRawSelectScope(select).setExpandedSelectList(list); return new SqlNodeList(list, SqlParserPos.ZERO); }
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 = parent; } return false; }
public SqlMonotonicity getMonotonicity(SqlNode expr) { SqlMonotonicity monotonicity = expr.getMonotonicity(this); if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) { return monotonicity; } // TODO: compare fully qualified names final SqlNodeList orderList = getOrderList(); if (orderList.size() > 0) { SqlNode order0 = orderList.get(0); monotonicity = SqlMonotonicity.INCREASING; if ((order0 instanceof SqlCall) && (((SqlCall) order0).getOperator() == SqlStdOperatorTable.DESC)) { monotonicity = monotonicity.reverse(); order0 = ((SqlCall) order0).operand(0); } if (expr.equalsDeep(order0, false)) { return monotonicity; } } return SqlMonotonicity.NOT_MONOTONIC; }
SqlValidatorUtil.getEnclosingSelectScope(scope); if ((selectScope != null) && (selectScope.getChildren().size() == 1)) selectScope.getChildren().get(0).getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add(
final String tableName = identifier.names.get(0); SqlParserPos starPosition = identifier.getParserPosition(); final SqlValidatorNamespace childNs = scope.getChild(tableName); if (childNs == null) {
SqlSelect sqlSelect = (SqlSelect) sqlQuery; final SelectScope scope = getRawSelectScope(sqlSelect); final List<SqlNode> selectList = scope.getExpandedSelectList(); SqlNode selectItem = selectList.get(i); if (SqlUtil.isCallTo(selectItem, SqlStdOperatorTable.asOperator)) { for (String name : id.names) { if (namespace == null) { namespace = scope.resolve(name, null, null); final SqlValidatorTable table = namespace.getTable(); if (table != null) {
if (windowScope.existingWindowName(declName.toString())) { throw newValidationError( declName, EigenbaseResource.instance().DuplicateWindowName.ex()); } else { windowScope.addWindowName(declName.toString());
public SqlNodeList expandStar( SqlNodeList selectList, SqlSelect select, boolean includeSystemVars) { List<SqlNode> list = new ArrayList<SqlNode>(); List<Map.Entry<String, RelDataType>> types = new ArrayList<Map.Entry<String, RelDataType>>(); for (int i = 0; i < selectList.size(); i++) { final SqlNode selectItem = selectList.get(i); expandSelectItem( selectItem, select, list, new LinkedHashSet<String>(), types, includeSystemVars); } getRawSelectScope(select).setExpandedSelectList(list); return new SqlNodeList(list, SqlParserPos.ZERO); }
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 ((null != walker) && !(walker instanceof EmptyScope)) { if (walker instanceof SelectScope) { final SelectScope parentScope = (SelectScope) walker; return parentScope.existingWindowName(winName); } walker = parent; } return false; }
public SqlMonotonicity getMonotonicity(SqlNode expr) { SqlMonotonicity monotonicity = expr.getMonotonicity(this); if (monotonicity != SqlMonotonicity.NotMonotonic) { return monotonicity; } // TODO: compare fully qualified names final SqlNodeList orderList = getOrderList(); if ((orderList.size() > 0)) { SqlNode order0 = orderList.get(0); monotonicity = SqlMonotonicity.Increasing; if ((order0 instanceof SqlCall) && (((SqlCall) order0).getOperator() == SqlStdOperatorTable.descendingOperator)) { monotonicity = monotonicity.reverse(); order0 = ((SqlCall) order0).getOperands()[0]; } if (expr.equalsDeep(order0, false)) { return monotonicity; } } return SqlMonotonicity.NotMonotonic; }
SqlValidatorUtil.getEnclosingSelectScope(scope); if ((selectScope != null) && (selectScope.getChildren().size() == 1)) { RelDataType rowType = selectScope.getChildren().get(0).getRowType(); for (RelDataTypeField field : rowType.getFieldList()) { hintList.add(
final SqlValidatorNamespace childNs = scope.getChild(tableName); if (childNs == null) {
/** * Returns the expressions that are in the GROUP BY clause (or the SELECT * DISTINCT clause, if distinct) and that can therefore be referenced * without being wrapped in aggregate functions. * * <p>The expressions are fully-qualified, and any "*" in select clauses are * expanded. * * @return list of grouping expressions */ private List<SqlNode> getGroupExprs() { if (distinct) { // Cannot compute this in the constructor: select list has not been // expanded yet. assert select.isDistinct(); // Remove the AS operator so the expressions are consistent with // OrderExpressionExpander. List<SqlNode> groupExprs = new ArrayList<SqlNode>(); for (SqlNode selectItem : ((SelectScope) parent).getExpandedSelectList()) { groupExprs.add(stripAs(selectItem)); } return groupExprs; } else if (select.getGroup() != null) { return groupExprList; } else { return Collections.emptyList(); } }
@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(); if (select.getGroup() != null) { return select.getGroup().size(); } return validator.isAggregate(select) ? 0 : -1; }
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); }