private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope) { if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) { final SqlIdentifier id = (SqlIdentifier) node; final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent(); return getNamespace(id, idScope); } else if (node instanceof SqlCall) { // Handle extended identifiers. final SqlCall call = (SqlCall) node; switch (call.getOperator().getKind()) { case EXTEND: final SqlIdentifier id = (SqlIdentifier) call.getOperandList().get(0); final DelegatingScope idScope = (DelegatingScope) scope; return getNamespace(id, idScope); case AS: final SqlNode nested = call.getOperandList().get(0); switch (nested.getKind()) { case EXTEND: return getNamespace(nested, scope); } break; } } return getNamespace(node); }
private SqlValidatorNamespace getNamespace(SqlIdentifier id, DelegatingScope scope) { if (id.isSimple()) { final SqlNameMatcher nameMatcher = catalogReader.nameMatcher(); final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl(); scope.resolve(id.names, nameMatcher, false, resolved); if (resolved.count() == 1) { return resolved.only().namespace; } } return getNamespace(id); }
columnName = identifier.names.get(0); final Map<String, ScopeChild> map = findQualifyingTableNames(columnName, identifier, nameMatcher); switch (map.size()) { case 0: final SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal(); final Map<String, ScopeChild> map2 = findQualifyingTableNames(columnName, identifier, liberalMatcher); if (!map2.isEmpty()) { final List<String> list = new ArrayList<>(); resolveInNamespace(namespace, false, identifier.names, nameMatcher, Path.EMPTY, resolved); final RelDataTypeField field = nameMatcher.field(namespace.getRowType(), columnName); if (field != null) { if (hasAmbiguousUnresolvedStar(namespace.getRowType(), field, columnName)) { throw validator.newValidationError(identifier, final SqlIdentifier prefix = identifier.getComponent(0, i); resolved.clear(); resolve(prefix.names, nameMatcher, false, resolved); if (resolved.count() == 1) { final Resolve resolve = resolved.only(); final SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal(); resolved.clear();
public SqlQualified fullyQualify(SqlIdentifier identifier) { // If it's a simple identifier, look for an alias. if (identifier.isSimple() && validator.getConformance().isSortByAlias()) { final String name = identifier.names.get(0); final SqlValidatorNamespace selectNs = validator.getNamespace(select); final RelDataType rowType = selectNs.getRowType(); final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher(); final RelDataTypeField field = nameMatcher.field(rowType, name); final int aliasCount = aliasCount(nameMatcher, name); if (aliasCount > 1) { // More than one column has this alias. throw validator.newValidationError(identifier, RESOURCE.columnAmbiguous(name)); } if (field != null && !field.isDynamicStar() && aliasCount == 1) { // if identifier is resolved to a dynamic star, use super.fullyQualify() for such case. return SqlQualified.create(this, 1, selectNs, identifier); } } return super.fullyQualify(identifier); }
public SqlValidatorScope getOperandScope(SqlCall call) { if (call.getOperator().isAggregator()) { // If we're the 'SUM' node in 'select a + sum(b + c) from t // group by a', then we should validate our arguments in // the non-aggregating scope, where 'b' and 'c' are valid // column references. return parent; } else { // Check whether expression is constant within the group. // // If not, throws. Example, 'empno' in // SELECT empno FROM emp GROUP BY deptno // // If it perfectly matches an expression in the GROUP BY // clause, we validate its arguments in the non-aggregating // scope. Example, 'empno + 1' in // // SELECT empno + 1 FROM emp GROUP BY empno + 1 final boolean matches = checkAggregateExpr(call, false); if (matches) { return parent; } } return super.getOperandScope(call); }
final Step path2 = path.plus(rowType, field.getIndex(), field.getName(), StructKind.FULLY_QUALIFIED); resolveInNamespace(ns2, nullable, remainder, nameMatcher, path2, resolved); final Step path2 = path.plus(rowType, field0.getIndex(), field0.getName(), StructKind.FULLY_QUALIFIED); resolveInNamespace(ns2, nullable, names.subList(1, names.size()), nameMatcher, path2, resolved); } else { field.getName(), field.getType().getStructKind()); final SqlValidatorNamespace ns2 = ns.lookupChild(field.getName()); resolveInNamespace(ns2, nullable, names, nameMatcher, path2, resolved);
columnName = identifier.names.get(0); final Map<String, ScopeChild> map = findQualifyingTableNames(columnName, identifier, nameMatcher); switch (map.size()) { case 0: final SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal(); final Map<String, ScopeChild> map2 = findQualifyingTableNames(columnName, identifier, liberalMatcher); if (!map2.isEmpty()) { final List<String> list = new ArrayList<>(); resolveInNamespace(namespace, false, identifier.names, nameMatcher, Path.EMPTY, resolved); final RelDataTypeField field = nameMatcher.field(namespace.getRowType(), columnName); if (field != null) { if (hasAmbiguousUnresolvedStar(namespace.getRowType(), field, columnName)) { throw validator.newValidationError(identifier, final SqlIdentifier prefix = identifier.getComponent(0, i); resolved.clear(); resolve(prefix.names, nameMatcher, false, resolved); if (resolved.count() == 1) { final Resolve resolve = resolved.only(); final SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal(); resolved.clear();
public SqlQualified fullyQualify(SqlIdentifier identifier) { // If it's a simple identifier, look for an alias. if (identifier.isSimple() && validator.getConformance().isSortByAlias()) { final String name = identifier.names.get(0); final SqlValidatorNamespace selectNs = validator.getNamespace(select); final RelDataType rowType = selectNs.getRowType(); final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher(); final RelDataTypeField field = nameMatcher.field(rowType, name); final int aliasCount = aliasCount(nameMatcher, name); if (aliasCount > 1) { // More than one column has this alias. throw validator.newValidationError(identifier, RESOURCE.columnAmbiguous(name)); } if (field != null && !field.isDynamicStar() && aliasCount == 1) { // if identifier is resolved to a dynamic star, use super.fullyQualify() for such case. return SqlQualified.create(this, 1, selectNs, identifier); } } return super.fullyQualify(identifier); }
public SqlValidatorScope getOperandScope(SqlCall call) { if (call.getOperator().isAggregator()) { // If we're the 'SUM' node in 'select a + sum(b + c) from t // group by a', then we should validate our arguments in // the non-aggregating scope, where 'b' and 'c' are valid // column references. return parent; } else { // Check whether expression is constant within the group. // // If not, throws. Example, 'empno' in // SELECT empno FROM emp GROUP BY deptno // // If it perfectly matches an expression in the GROUP BY // clause, we validate its arguments in the non-aggregating // scope. Example, 'empno + 1' in // // SELECT empno + 1 FROM emp GROUP BY empno + 1 final boolean matches = checkAggregateExpr(call, false); if (matches) { return parent; } } return super.getOperandScope(call); }
final Step path2 = path.plus(rowType, field.getIndex(), field.getName(), StructKind.FULLY_QUALIFIED); resolveInNamespace(ns2, nullable, remainder, nameMatcher, path2, resolved); final Step path2 = path.plus(rowType, field0.getIndex(), field0.getName(), StructKind.FULLY_QUALIFIED); resolveInNamespace(ns2, nullable, names.subList(1, names.size()), nameMatcher, path2, resolved); } else { field.getName(), field.getType().getStructKind()); final SqlValidatorNamespace ns2 = ns.lookupChild(field.getName()); resolveInNamespace(ns2, nullable, names, nameMatcher, path2, resolved);
public static SelectScope getEnclosingSelectScope(SqlValidatorScope scope) { while (scope instanceof DelegatingScope) { if (scope instanceof SelectScope) { return (SelectScope) scope; } scope = ((DelegatingScope) scope).getParent(); } return null; }
super.resolve(names, nameMatcher, deep, resolved);
public static AggregatingSelectScope getEnclosingAggregateSelectScope( SqlValidatorScope scope) { while (scope instanceof DelegatingScope) { if (scope instanceof AggregatingSelectScope) { return (AggregatingSelectScope) scope; } scope = ((DelegatingScope) scope).getParent(); } return null; }
super.resolve(names, nameMatcher, deep, resolved);
public static SelectScope getEnclosingSelectScope(SqlValidatorScope scope) { while (scope instanceof DelegatingScope) { if (scope instanceof SelectScope) { return (SelectScope) scope; } scope = ((DelegatingScope) scope).getParent(); } return null; }
private SqlValidatorNamespace getNamespace(SqlIdentifier id, DelegatingScope scope) { if (id.isSimple()) { final SqlNameMatcher nameMatcher = catalogReader.nameMatcher(); final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl(); scope.resolve(id.names, nameMatcher, false, resolved); if (resolved.count() == 1) { return resolved.only().namespace; } } return getNamespace(id); }
public static AggregatingSelectScope getEnclosingAggregateSelectScope( SqlValidatorScope scope) { while (scope instanceof DelegatingScope) { if (scope instanceof AggregatingSelectScope) { return (AggregatingSelectScope) scope; } scope = ((DelegatingScope) scope).getParent(); } return null; }
private SqlValidatorNamespace getNamespace(SqlIdentifier id, DelegatingScope scope) { if (id.isSimple()) { final SqlNameMatcher nameMatcher = catalogReader.nameMatcher(); final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl(); scope.resolve(id.names, nameMatcher, false, resolved); if (resolved.count() == 1) { return resolved.only().namespace; } } return getNamespace(id); }
private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope) { if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) { final SqlIdentifier id = (SqlIdentifier) node; final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent(); return getNamespace(id, idScope); } else if (node instanceof SqlCall) { // Handle extended identifiers. final SqlCall call = (SqlCall) node; switch (call.getOperator().getKind()) { case EXTEND: final SqlIdentifier id = (SqlIdentifier) call.getOperandList().get(0); final DelegatingScope idScope = (DelegatingScope) scope; return getNamespace(id, idScope); case AS: final SqlNode nested = call.getOperandList().get(0); switch (nested.getKind()) { case EXTEND: return getNamespace(nested, scope); } break; } } return getNamespace(node); }
private SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope) { if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) { final SqlIdentifier id = (SqlIdentifier) node; final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent(); return getNamespace(id, idScope); } else if (node instanceof SqlCall) { // Handle extended identifiers. final SqlCall call = (SqlCall) node; switch (call.getOperator().getKind()) { case EXTEND: final SqlIdentifier id = (SqlIdentifier) call.getOperandList().get(0); final DelegatingScope idScope = (DelegatingScope) scope; return getNamespace(id, idScope); case AS: final SqlNode nested = call.getOperandList().get(0); switch (nested.getKind()) { case EXTEND: return getNamespace(nested, scope); } break; } } return getNamespace(node); }