@Override public Void visit(SqlIdentifier id) { Preconditions.checkArgument(id.isSimple()); scope.addPatternVar(id.getSimple()); return null; }
/** Returns the alias of a "expr AS alias" expression. */ private static String alias(SqlNode item) { assert item instanceof SqlCall; assert item.getKind() == SqlKind.AS; final SqlIdentifier identifier = ((SqlCall) item).operand(1); return identifier.getSimple(); }
@Override public void lookupOperatorOverloads( final SqlIdentifier opName, final SqlFunctionCategory category, final SqlSyntax syntax, final List<SqlOperator> operatorList ) { if (opName == null) { return; } if (opName.names.size() != 1) { return; } final OperatorKey operatorKey = OperatorKey.of(opName.getSimple(), syntax); final SqlAggregator aggregator = aggregators.get(operatorKey); if (aggregator != null) { operatorList.add(aggregator.calciteFunction()); } final SqlOperatorConversion operatorConversion = operatorConversions.get(operatorKey); if (operatorConversion != null) { operatorList.add(operatorConversion.calciteOperator()); } final SqlOperator convertletOperator = CONVERTLET_OPERATORS.get(operatorKey); if (convertletOperator != null) { operatorList.add(convertletOperator); } }
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; }
/** Returns the set of field names in the join condition specified by USING * or implicitly by NATURAL, de-duplicated and in order. */ private List<String> usingNames(SqlJoin join) { switch (join.getConditionType()) { case USING: final ImmutableList.Builder<String> list = ImmutableList.builder(); final Set<String> names = catalogReader.nameMatcher().createSet(); for (SqlNode node : (SqlNodeList) join.getCondition()) { final String name = ((SqlIdentifier) node).getSimple(); if (names.add(name)) { list.add(name); } } return list.build(); case NONE: if (join.isNatural()) { final RelDataType t0 = getValidatedNodeType(join.getLeft()); final RelDataType t1 = getValidatedNodeType(join.getRight()); return SqlValidatorUtil.deriveNaturalJoinColumnList( catalogReader.nameMatcher(), t0, t1); } } return null; }
private void registerWith( SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlWith with, SqlNode enclosingNode, String alias, boolean forceNullable, boolean checkUpdate) { final WithNamespace withNamespace = new WithNamespace(this, with, enclosingNode); registerNamespace(usingScope, alias, withNamespace, forceNullable); SqlValidatorScope scope = parentScope; for (SqlNode withItem_ : with.withList) { final SqlWithItem withItem = (SqlWithItem) withItem_; final WithScope withScope = new WithScope(scope, withItem); scopes.put(withItem, withScope); registerQuery(scope, null, withItem.query, with, withItem.name.getSimple(), false); registerNamespace(null, alias, new WithItemNamespace(this, withItem, enclosingNode), false); scope = withScope; } registerQuery(scope, null, with.body, enclosingNode, alias, forceNullable, checkUpdate); }
public SqlWindow resolveWindow( SqlNode windowOrRef, SqlValidatorScope scope, boolean populateBounds) { SqlWindow window; if (windowOrRef instanceof SqlIdentifier) { window = getWindowByName((SqlIdentifier) windowOrRef, scope); } else { window = (SqlWindow) windowOrRef; } while (true) { final SqlIdentifier refId = window.getRefName(); if (refId == null) { break; } final String refName = refId.getSimple(); SqlWindow refWindow = scope.lookupWindow(refName); if (refWindow == null) { throw newValidationError(refId, RESOURCE.windowNotFound(refName)); } window = window.overlay(refWindow, this); } if (populateBounds) { window.populateBounds(); } return window; }
/** * Creates the SELECT statement that putatively feeds rows into a DELETE * statement to be deleted. * * @param call Call to the DELETE operator * @return select statement */ protected SqlSelect createSourceSelectForDelete(SqlDelete call) { final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); SqlNode sourceTable = call.getTargetTable(); if (call.getAlias() != null) { sourceTable = SqlValidatorUtil.addAlias( sourceTable, call.getAlias().getSimple()); } return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null); }
final List<SqlNode> sources = update.getSourceExpressionList().getList(); for (final Pair<SqlNode, SqlNode> column : Pair.zip(targets, sources)) { final String columnName = ((SqlIdentifier) column.left).getSimple(); final Integer columnIndex = nameToIndex.get(columnName); if (projectMap.containsKey(columnIndex)) {
@Override public void userDefinedType(SqlDataTypeSpec typeSpec, int leftPrec, int rightPrec) { keyword(typeSpec.getTypeName().getSimple()); // also print precision and scale for user-defined-type int precision = typeSpec.getPrecision(); int scale = typeSpec.getScale(); if (precision >= 0) { final SqlWriter.Frame frame = startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); this.print(precision); if (scale >= 0) { this.sep(",", true); this.print(scale); } this.endList(frame); } }
for (SqlNode node : subsets) { List<SqlNode> operands = ((SqlCall) node).getOperandList(); String leftString = ((SqlIdentifier) operands.get(0)).getSimple(); if (scope.getPatternVars().contains(leftString)) { throw newValidationError(operands.get(0), for (SqlNode right : (SqlNodeList) operands.get(1)) { SqlIdentifier id = (SqlIdentifier) right; if (!scope.getPatternVars().contains(id.getSimple())) { throw newValidationError(id, RESOURCE.unknownPattern(id.getSimple())); scope.addPatternVar(id.getSimple()); final SqlCall skipToCall = (SqlCall) skipTo; final SqlIdentifier id = skipToCall.operand(0); if (!scope.getPatternVars().contains(id.getSimple())) { throw newValidationError(id, RESOURCE.unknownPattern(id.getSimple()));
public SqlNode visit(SqlIdentifier id) { // Aliases, e.g. 'select a as x, b from t order by x'. if (id.isSimple() && getConformance().isSortByAlias()) { String alias = id.getSimple(); final SqlValidatorNamespace selectNs = getNamespace(select); final RelDataType rowType = selectNs.getRowTypeSansSystemColumns(); final SqlNameMatcher nameMatcher = catalogReader.nameMatcher(); RelDataTypeField field = nameMatcher.field(rowType, alias); if (field != null) { return nthSelectItem( field.getIndex(), id.getParserPosition()); } } // No match. Return identifier unchanged. return getScope().fullyQualify(id).identifier; }
/** * Creates the SELECT statement that putatively feeds rows into an UPDATE * statement to be updated. * * @param call Call to the UPDATE operator * @return select statement */ protected SqlSelect createSourceSelectForUpdate(SqlUpdate call) { final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); int ordinal = 0; for (SqlNode exp : call.getSourceExpressionList()) { // Force unique aliases to avoid a duplicate for Y with // SET X=Y String alias = SqlUtil.deriveAliasFromOrdinal(ordinal); selectList.add(SqlValidatorUtil.addAlias(exp, alias)); ++ordinal; } SqlNode sourceTable = call.getTargetTable(); if (call.getAlias() != null) { sourceTable = SqlValidatorUtil.addAlias( sourceTable, call.getAlias().getSimple()); } return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, call.getCondition(), null, null, null, null, null, null); }
? validator.getConformance().isHavingAlias() : validator.getConformance().isGroupByAlias())) { String name = id.getSimple(); SqlNode expr = null; final SqlNameMatcher nameMatcher =
if (!SqlTypeUtil.isComparable(leftColType, rightColType)) { throw newValidationError(id, RESOURCE.naturalOrUsingColumnNotCompatible(id.getSimple(), leftColType.toString(), rightColType.toString()));
getSelfJoinExprForUpdate( updateCall.getTargetTable(), updateCall.getAlias().getSimple()); assert selfJoinTgtExpr != null;
SqlValidatorUtil.addAlias( targetTable, call.getAlias().getSimple());
name = id.getSimple(); } else if (jj_2_664(2)) {
name = id.getSimple(); } else if (jj_2_664(2)) {
name = id.getSimple(); } else if (jj_2_669(2)) {