if (!identifier.isStar()) { return false; final SqlParserPos startPosition = identifier.getParserPosition(); switch (identifier.names.size()) { case 1: boolean hasDynamicStruct = false; for (ScopeChild child : scope.children) { final int before = fields.size(); if (child.namespace.getRowType().isDynamicStruct()) { hasDynamicStruct = true; new SqlIdentifier( ImmutableList.of(child.name, DynamicRecordType.DYNAMIC_STAR_PREFIX), startPosition); new SqlIdentifier( ImmutableList.of(child.name, columnName), startPosition); final SqlIdentifier prefixId = identifier.skipLast(1); final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl(); RESOURCE.unknownIdentifier(prefixId.toString())); aliases, fields,
/** 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; }
SqlParserPos pos = SqlParserPos.sum(posList); if (star) { {if (true) return SqlIdentifier.star(list, pos, posList);} {if (true) return new SqlIdentifier(list, null, pos, posList);} throw new Error("Missing return statement in function");
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; }
@Override public boolean isSqlIdentifierEqual(SqlIdentifier querySqlIdentifier, SqlIdentifier exprSqlIdentifier) { int parsedIdx = ParamNodeParser.parseParamIdx(exprSqlIdentifier.toString()); if (parsedIdx >= 0) { SqlNode matchedBefore = matchedNodesMap.get(parsedIdx); if (matchedBefore != null) { return ExpressionComparator.isNodeEqual(querySqlIdentifier, matchedBefore, this); } else { matchedNodesMap.put(parsedIdx, querySqlIdentifier); return true; } } else { return querySqlIdentifier.equalsDeep(exprSqlIdentifier, Litmus.IGNORE); } }
final List<SqlNode> oldSelectItems = ImmutableList.copyOf(selectItems); selectItems.clear(); final List<Map.Entry<String, RelDataType>> oldFields = ImmutableList.copyOf(fields); fields.clear(); for (ImmutableIntList source : sources) { final RelDataType type1 = field1.getValue(); final boolean nullable = type.isNullable() && type1.isNullable(); final RelDataType type2 = SqlTypeUtil.leastRestrictiveForComparison(typeFactory, type, maybeCast(selectItem, type, type2), maybeCast(selectItem1, type1, type2)), new SqlIdentifier(name, SqlParserPos.ZERO)); type = typeFactory.createTypeWithNullability(type2, nullable);
protected List<String> constructArgNameList(SqlCall call) { // If any arguments are named, construct a map. final ImmutableList.Builder<String> nameBuilder = ImmutableList.builder(); for (SqlNode operand : call.getOperandList()) { if (operand.getKind() == SqlKind.ARGUMENT_ASSIGNMENT) { final List<SqlNode> operandList = ((SqlCall) operand).getOperandList(); nameBuilder.add(((SqlIdentifier) operandList.get(1)).getSimple()); } } ImmutableList<String> argNames = nameBuilder.build(); if (argNames.isEmpty()) { return null; } else { return argNames; } }
private RelDataType validateUsingCol(SqlIdentifier id, SqlNode leftOrRight) { if (id.names.size() == 1) { String name = id.names.get(0); final SqlValidatorNamespace namespace = getNamespace(leftOrRight); final RelDataType rowType = namespace.getRowType(); final SqlNameMatcher nameMatcher = catalogReader.nameMatcher(); final RelDataTypeField field = nameMatcher.field(rowType, name); if (field != null) { if (nameMatcher.frequency(rowType.getFieldNames(), name) > 1) { throw newValidationError(id, RESOURCE.columnInUsingNotUnique(id.toString())); } return field.getType(); } } throw newValidationError(id, RESOURCE.columnNotFound(id.toString())); }
return call.getOperator().validateOperands( SqlValidatorImpl.this, scope, for (i = id.names.size() - 1; i > 0; i--) { final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl(); scope.resolve(id.names.subList(0, i), nameMatcher, false, resolved); if (resolved.count() == 1) { type = resolve.rowType(); for (SqlValidatorScope.Step p : Util.skip(resolve.path.steps())) { type = type.getFieldList().get(p.i).getType(); if (type == null || id.names.size() == 1) { final SqlIdentifier last = id.getComponent(i - 1, i); throw newValidationError(last, RESOURCE.unknownIdentifier(last.toString())); throw newValidationError(id.getComponent(i), RESOURCE.unknownField(name)); type = field.getType();
/** * Returns the position of the <code>i</code>th component of a compound * identifier, or the position of the whole identifier if that information * is not present. * * @param i Ordinal of component. * @return Position of i'th component */ public SqlParserPos getComponentParserPosition(int i) { assert (i >= 0) && (i < names.size()); return (componentPositions == null) ? getParserPosition() : componentPositions.get(i); }
private void registerId(SqlIdentifier id, SqlValidatorScope scope) { for (int i = 0; i < id.names.size(); i++) { final SqlParserPos subPos = id.getComponentParserPosition(i); SqlIdentifier subId = i == id.names.size() - 1 ? id : new SqlIdentifier(id.names.subList(0, i + 1), subPos); idPositions.put(subPos.toString(), new IdInfo(scope, subId)); } }
IdentifierNamespace idNs = ns.unwrap(IdentifierNamespace.class); final SqlIdentifier id = idNs.getId(); for (int i = 0; i < id.names.size(); i++) { if (pos.toString().equals( id.getComponent(i).getParserPosition().toString())) { final List<SqlMoniker> objNames = new ArrayList<>(); SqlValidatorUtil.getSchemaObjectMonikers( getCatalogReader(), id.names.subList(0, i + 1), objNames); for (SqlMoniker objName : objNames) { switch (node.getKind()) { case JOIN: lookupJoinHints((SqlJoin) node, scope, pos, hintList);
for (SqlNode node : partitionBy) { SqlIdentifier identifier = (SqlIdentifier) node; identifier.validate(this, scope); RelDataType type = deriveType(scope, identifier); String name = identifier.names.get(1); typeBuilder.add(name, type); if (subsets != null && subsets.size() > 0) { 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()); if (skipTo instanceof SqlCall) { final SqlCall skipToCall = (SqlCall) skipTo; final SqlIdentifier id = skipToCall.operand(0); if (!scope.getPatternVars().contains(id.getSimple())) { throw newValidationError(id, RESOURCE.unknownPattern(id.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); } }
@Override public SqlNode visit(SqlIdentifier id) { if (id.isSimple()) { return id; } SqlOperator operator = id.names.get(0).equals(alpha) ? SqlStdOperatorTable.PREV : SqlStdOperatorTable.LAST; return operator.createCall(SqlParserPos.ZERO, id, SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO)); } }
validateFeature(RESOURCE.sQLFeature_E051_01(), select.getModifierNode(SqlSelectKeyword.DISTINCT) .getParserPosition()); if (selectItem instanceof SqlIdentifier) { SqlIdentifier id = (SqlIdentifier) selectItem; if (id.isStar() && (id.names.size() == 1)) {