public SqlValidatorScope getJoinScope(SqlNode node) { return scopes.get(stripAs(node)); }
private boolean shouldCheckForRollUp(SqlNode from) { if (from != null) { SqlKind kind = stripAs(from).getKind(); return kind != SqlKind.VALUES && kind != SqlKind.SELECT; } return false; }
final SelectScope scope = getRawSelectScope(sqlSelect); final List<SqlNode> selectList = scope.getExpandedSelectList(); final SqlNode selectItem = stripAs(selectList.get(i)); if (selectItem instanceof SqlIdentifier) { final SqlQualified qualified =
/** * Returns the <code>ordinal</code>th item in the select list. */ private SqlNode nthSelectItem(int ordinal, final SqlParserPos pos) { // TODO: Don't expand the list every time. Maybe keep an expanded // version of each expression -- select lists and identifiers -- in // the validator. SqlNodeList expandedSelectList = expandStar( select.getSelectList(), select, false); SqlNode expr = expandedSelectList.get(ordinal); expr = stripAs(expr); if (expr instanceof SqlIdentifier) { expr = getScope().fullyQualify((SqlIdentifier) expr).identifier; } // Create a copy of the expression with the position of the order // item. return expr.clone(pos); }
private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight) { leftOrRight = stripAs(leftOrRight); // if it's not a SqlIdentifier then that's fine, it'll be validated somewhere else. if (leftOrRight instanceof SqlIdentifier) { SqlIdentifier from = (SqlIdentifier) leftOrRight; Table table = findTable(catalogReader.getRootSchema(), Util.last(from.names), catalogReader.nameMatcher().isCaseSensitive()); String name = Util.last(identifier.names); if (table != null && table.isRolledUp(name)) { throw newValidationError(identifier, RESOURCE.rolledUpNotAllowed(name, "USING")); } } }
return SqlUtil.stripAs(select.getSelectList().get(ordinal));
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)); } } } }
return super.visit(id); expr = stripAs(expr); if (expr instanceof SqlIdentifier) { expr = getScope().fullyQualify((SqlIdentifier) expr).identifier;
SqlNodeList selectList2 = getInnerSelect(node).getSelectList(); for (Ord<SqlNode> sel : Ord.zip(selectList2)) { if (stripAs(sel.e).equalsDeep(sqlNode, Litmus.IGNORE)) { orderList.set(i, SqlLiteral.createExactNumeric(Integer.toString(sel.i + 1),
public SqlValidatorScope getJoinScope(SqlNode node) { return scopes.get(stripAs(node)); }
public SqlValidatorScope getJoinScope(SqlNode node) { return scopes.get(stripAs(node)); }
private boolean shouldCheckForRollUp(SqlNode from) { if (from != null) { SqlKind kind = stripAs(from).getKind(); return kind != SqlKind.VALUES && kind != SqlKind.SELECT; } return false; }
private boolean shouldCheckForRollUp(SqlNode from) { if (from != null) { SqlKind kind = stripAs(from).getKind(); return kind != SqlKind.VALUES && kind != SqlKind.SELECT; } return false; }
private static void populateAliases(SqlNode from, List<String> aliases, @Nullable String current) { if (from instanceof SqlJoin) { SqlJoin join = (SqlJoin) from; populateAliases(join.getLeft(), aliases, null); populateAliases(join.getRight(), aliases, null); } else if (from.getKind() == SqlKind.AS) { populateAliases(SqlUtil.stripAs(from), aliases, SqlValidatorUtil.getAlias(from, -1)); } else { if (current == null) { current = SqlValidatorUtil.getAlias(from, -1); } aliases.add(current); } }
private static void populateAliases(SqlNode from, List<String> aliases, String current) { if (from instanceof SqlJoin) { SqlJoin join = (SqlJoin) from; populateAliases(join.getLeft(), aliases, null); populateAliases(join.getRight(), aliases, null); } else if (from.getKind() == SqlKind.AS) { populateAliases(SqlUtil.stripAs(from), aliases, SqlValidatorUtil.getAlias(from, -1)); } else { if (current == null) { current = SqlValidatorUtil.getAlias(from, -1); } aliases.add(current); } }
/** * Returns the <code>ordinal</code>th item in the select list. */ private SqlNode nthSelectItem(int ordinal, final SqlParserPos pos) { // TODO: Don't expand the list every time. Maybe keep an expanded // version of each expression -- select lists and identifiers -- in // the validator. SqlNodeList expandedSelectList = expandStar( select.getSelectList(), select, false); SqlNode expr = expandedSelectList.get(ordinal); expr = stripAs(expr); if (expr instanceof SqlIdentifier) { expr = getScope().fullyQualify((SqlIdentifier) expr).identifier; } // Create a copy of the expression with the position of the order // item. return expr.clone(pos); }
private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight) { leftOrRight = stripAs(leftOrRight); // if it's not a SqlIdentifier then that's fine, it'll be validated somewhere else. if (leftOrRight instanceof SqlIdentifier) { SqlIdentifier from = (SqlIdentifier) leftOrRight; Table table = findTable(catalogReader.getRootSchema(), Util.last(from.names), catalogReader.nameMatcher().isCaseSensitive()); String name = Util.last(identifier.names); if (table != null && table.isRolledUp(name)) { throw newValidationError(identifier, RESOURCE.rolledUpNotAllowed(name, "USING")); } } }
private void checkRollUpInUsing(SqlIdentifier identifier, SqlNode leftOrRight) { leftOrRight = stripAs(leftOrRight); // if it's not a SqlIdentifier then that's fine, it'll be validated somewhere else. if (leftOrRight instanceof SqlIdentifier) { SqlIdentifier from = (SqlIdentifier) leftOrRight; Table table = findTable(catalogReader.getRootSchema(), Util.last(from.names), catalogReader.nameMatcher().isCaseSensitive()); String name = Util.last(identifier.names); if (table != null && table.isRolledUp(name)) { throw newValidationError(identifier, RESOURCE.rolledUpNotAllowed(name, "USING")); } } }
public void checkIntervalConv(String sql, String expected) { SqlValidator validator = getValidator(); final SqlCall n = (SqlCall) parseAndValidate(validator, sql); SqlNode node = null; for (int i = 0; i < n.operandCount(); i++) { node = stripAs(n.operand(i)); if (node instanceof SqlCall) { node = ((SqlCall) node).operand(0); break; } } assertNotNull(node); SqlIntervalLiteral intervalLiteral = (SqlIntervalLiteral) node; SqlIntervalLiteral.IntervalValue interval = (SqlIntervalLiteral.IntervalValue) intervalLiteral.getValue(); long l = interval.getIntervalQualifier().isYearMonth() ? SqlParserUtil.intervalToMonths(interval) : SqlParserUtil.intervalToMillis(interval); String actual = l + ""; assertEquals(expected, actual); }
public void checkIntervalConv(String sql, String expected) { SqlValidator validator = getValidator(); final SqlCall n = (SqlCall) parseAndValidate(validator, sql); SqlNode node = null; for (int i = 0; i < n.operandCount(); i++) { node = stripAs(n.operand(i)); if (node instanceof SqlCall) { node = ((SqlCall) node).operand(0); break; } } assertNotNull(node); SqlIntervalLiteral intervalLiteral = (SqlIntervalLiteral) node; SqlIntervalLiteral.IntervalValue interval = (SqlIntervalLiteral.IntervalValue) intervalLiteral.getValue(); long l = interval.getIntervalQualifier().isYearMonth() ? SqlParserUtil.intervalToMonths(interval) : SqlParserUtil.intervalToMillis(interval); String actual = l + ""; assertEquals(expected, actual); }