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); }
final List<RelDataType> typeList = new ArrayList<>(); for (Ord<SqlNode> column : Ord.zip(rowConstructor.getOperandList())) { final String alias = deriveAlias(column.e, column.i); aliasList.add(alias); final RelDataType type = deriveType(scope, column.e);
deriveAlias( selectItem, aliases.size()); if (expanded != selectItem) { String newAlias = deriveAlias( expanded, aliases.size());
private List<Map.Entry<String, RelDataType>> validateMeasure(SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows) { final List<String> aliases = new ArrayList<>(); final List<SqlNode> sqlNodes = new ArrayList<>(); final SqlNodeList measures = mr.getMeasureList(); final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>(); for (SqlNode measure : measures) { assert measure instanceof SqlCall; final String alias = deriveAlias(measure, aliases.size()); aliases.add(alias); SqlNode expand = expand(measure, scope); expand = navigationInMeasure(expand, allRows); setOriginal(expand, measure); inferUnknownTypes(unknownType, scope, expand); final RelDataType type = deriveType(scope, expand); setValidatedNodeType(measure, type); fields.add(Pair.of(alias, type)); sqlNodes.add( SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, expand, new SqlIdentifier(alias, SqlParserPos.ZERO))); } SqlNodeList list = new SqlNodeList(sqlNodes, measures.getParserPosition()); inferUnknownTypes(unknownType, scope, list); for (SqlNode node : list) { validateExpr(node, scope); } mr.setOperand(SqlMatchRecognize.OPERAND_MEASURES, list); return fields; }
deriveAlias( selectItem, aliasList.size());
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause) { current = stripAs(current); if (current instanceof SqlCall && !(current instanceof SqlSelect)) { // Validate OVER separately checkRollUpInWindow(getWindowInOver(current), scope); current = stripOver(current); List<SqlNode> children = ((SqlCall) stripDot(current)).getOperandList(); for (SqlNode child : children) { checkRollUp(parent, current, child, scope, optionalClause); } } else if (current instanceof SqlIdentifier) { SqlIdentifier id = (SqlIdentifier) current; if (!id.isStar() && isRolledUpColumn(id, scope)) { if (!isAggregation(parent.getKind()) || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) { String context = optionalClause != null ? optionalClause : parent.getKind().toString(); throw newValidationError(id, RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context)); } } } }
case IDENTIFIER: case OVER: alias = deriveAlias(node, -1); if (alias == null) { alias = deriveAlias(node, nextGeneratedId++); alias = deriveAlias(node, nextGeneratedId++); if (shouldExpandIdentifiers()) { case OTHER_FUNCTION: if (alias == null) { alias = deriveAlias(node, nextGeneratedId++);
final CollectNamespace tableConstructorNs = new CollectNamespace(call, cs, enclosingNode); final String alias2 = deriveAlias(node, nextGeneratedId++); registerNamespace( usingScope,
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); }
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); }
final List<RelDataType> typeList = new ArrayList<>(); for (Ord<SqlNode> column : Ord.zip(rowConstructor.getOperandList())) { final String alias = deriveAlias(column.e, column.i); aliasList.add(alias); final RelDataType type = deriveType(scope, column.e);
final List<RelDataType> typeList = new ArrayList<>(); for (Ord<SqlNode> column : Ord.zip(rowConstructor.getOperandList())) { final String alias = deriveAlias(column.e, column.i); aliasList.add(alias); final RelDataType type = deriveType(scope, column.e);
/** Converts a type to a struct if it is not already. */ protected RelDataType toStruct(RelDataType type, SqlNode unnest) { if (type.isStruct()) { return type; } return validator.getTypeFactory().builder() .add(validator.deriveAlias(unnest, 0), type) .build(); } }
/** Converts a type to a struct if it is not already. */ protected RelDataType toStruct(RelDataType type, SqlNode unnest) { if (type.isStruct()) { return type; } return validator.getTypeFactory().builder() .add(validator.deriveAlias(unnest, 0), type) .build(); } }
private List<Map.Entry<String, RelDataType>> validateMeasure(SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows) { final List<String> aliases = new ArrayList<>(); final List<SqlNode> sqlNodes = new ArrayList<>(); final SqlNodeList measures = mr.getMeasureList(); final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>(); for (SqlNode measure : measures) { assert measure instanceof SqlCall; final String alias = deriveAlias(measure, aliases.size()); aliases.add(alias); SqlNode expand = expand(measure, scope); expand = navigationInMeasure(expand, allRows); setOriginal(expand, measure); inferUnknownTypes(unknownType, scope, expand); final RelDataType type = deriveType(scope, expand); setValidatedNodeType(measure, type); fields.add(Pair.of(alias, type)); sqlNodes.add( SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, expand, new SqlIdentifier(alias, SqlParserPos.ZERO))); } SqlNodeList list = new SqlNodeList(sqlNodes, measures.getParserPosition()); inferUnknownTypes(unknownType, scope, list); for (SqlNode node : list) { validateExpr(node, scope); } mr.setOperand(SqlMatchRecognize.OPERAND_MEASURES, list); return fields; }
private List<Map.Entry<String, RelDataType>> validateMeasure(SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows) { final List<String> aliases = new ArrayList<>(); final List<SqlNode> sqlNodes = new ArrayList<>(); final SqlNodeList measures = mr.getMeasureList(); final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>(); for (SqlNode measure : measures) { assert measure instanceof SqlCall; final String alias = deriveAlias(measure, aliases.size()); aliases.add(alias); SqlNode expand = expand(measure, scope); expand = navigationInMeasure(expand, allRows); setOriginal(expand, measure); inferUnknownTypes(unknownType, scope, expand); final RelDataType type = deriveType(scope, expand); setValidatedNodeType(measure, type); fields.add(Pair.of(alias, type)); sqlNodes.add( SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, expand, new SqlIdentifier(alias, SqlParserPos.ZERO))); } SqlNodeList list = new SqlNodeList(sqlNodes, measures.getParserPosition()); inferUnknownTypes(unknownType, scope, list); for (SqlNode node : list) { validateExpr(node, scope); } mr.setOperand(SqlMatchRecognize.OPERAND_MEASURES, list); return fields; }
deriveAlias( selectItem, aliasList.size());
deriveAlias( selectItem, aliasList.size());
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause) { current = stripAs(current); if (current instanceof SqlCall && !(current instanceof SqlSelect)) { // Validate OVER separately checkRollUpInWindow(getWindowInOver(current), scope); current = stripOver(current); List<SqlNode> children = ((SqlCall) stripDot(current)).getOperandList(); for (SqlNode child : children) { checkRollUp(parent, current, child, scope, optionalClause); } } else if (current instanceof SqlIdentifier) { SqlIdentifier id = (SqlIdentifier) current; if (!id.isStar() && isRolledUpColumn(id, scope)) { if (!isAggregation(parent.getKind()) || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) { String context = optionalClause != null ? optionalClause : parent.getKind().toString(); throw newValidationError(id, RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context)); } } } }
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause) { current = stripAs(current); if (current instanceof SqlCall && !(current instanceof SqlSelect)) { // Validate OVER separately checkRollUpInWindow(getWindowInOver(current), scope); current = stripOver(current); List<SqlNode> children = ((SqlCall) stripDot(current)).getOperandList(); for (SqlNode child : children) { checkRollUp(parent, current, child, scope, optionalClause); } } else if (current instanceof SqlIdentifier) { SqlIdentifier id = (SqlIdentifier) current; if (!id.isStar() && isRolledUpColumn(id, scope)) { if (!isAggregation(parent.getKind()) || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) { String context = optionalClause != null ? optionalClause : parent.getKind().toString(); throw newValidationError(id, RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context)); } } } }