private void genParamPath(SqlNode sqlNode, List<Integer> path) { if (sqlNode instanceof SqlIdentifier) { int paramIdx = ParamNodeParser.parseParamIdx(sqlNode.toString()); if (paramIdx >= 0 && path.size() > 0) { paramPath.put(paramIdx, path); } } else if (sqlNode instanceof SqlCall) { List<SqlNode> operands = ((SqlCall) sqlNode).getOperandList(); for (int i = 0; i < operands.size(); i++) { List<Integer> copiedPath = Lists.newArrayList(path); copiedPath.add(i); genParamPath(operands.get(i), copiedPath); } } }
@Override public SqlNode visit(SqlCall call) { SqlKind kind = call.getKind(); List<SqlNode> operands = call.getOperandList(); List<SqlNode> newOperands = new ArrayList<>(); if (call.getFunctionQuantifier() != null && call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT) { final SqlParserPos pos = call.getParserPosition(); throw SqlUtil.newContextException(pos, Static.RESOURCE.functionQuantifierNotAllowed(call.toString())); SqlKind innerKind = inner.getKind(); if (isPhysicalNavigation(innerKind)) { List<SqlNode> innerOperands = ((SqlCall) inner).getOperandList(); inner.accept(new NavigationExpander(call.getOperator(), offset)); if (op != null) { newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode, this.offset); for (SqlNode node : operands) { if (node != null) { SqlNode newNode = node.accept(new NavigationExpander()); if (op != null) { newNode = op.createCall(SqlParserPos.ZERO, newNode, offset);
public void validateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType) { final SqlValidatorNamespace ns = getNamespace(node, scope); if (node.getKind() == SqlKind.TABLESAMPLE) { List<SqlNode> operands = ((SqlCall) node).getOperandList(); SqlSampleSpec sampleSpec = SqlLiteral.sampleValue(operands.get(1)); if (sampleSpec instanceof SqlSampleSpec.SqlTableSampleSpec) { validateFeature(RESOURCE.sQLFeature_T613(), node.getParserPosition()); } else if (sampleSpec instanceof SqlSampleSpec.SqlSubstitutionSampleSpec) { validateFeature(RESOURCE.sQLFeatureExt_T613_Substitution(), node.getParserPosition()); } } validateNamespace(ns, targetRowType); switch (node.getKind()) { case EXTEND: // Until we have a dedicated namespace for EXTEND deriveType(scope, node); } if (node == top) { validateModality(node); } validateAccess( node, ns.getTable(), SqlAccessEnum.SELECT); }
private void validateNodeFeature(SqlNode node) { switch (node.getKind()) { case MULTISET_VALUE_CONSTRUCTOR: validateFeature(RESOURCE.sQLFeature_S271(), node.getParserPosition()); break; } }
/** Return the intended modality of a SELECT or set-op. */ private SqlModality deduceModality(SqlNode query) { if (query instanceof SqlSelect) { SqlSelect select = (SqlSelect) query; return select.getModifierNode(SqlSelectKeyword.STREAM) != null ? SqlModality.STREAM : SqlModality.RELATION; } else if (query.getKind() == SqlKind.VALUES) { return SqlModality.RELATION; } else { assert query.isA(SqlKind.SET_QUERY); final SqlCall call = (SqlCall) query; return deduceModality(call.getOperandList().get(0)); } }
private SqlNode navigationInMeasure(SqlNode node, boolean allRows) { final Set<String> prefix = node.accept(new PatternValidator(true)); Util.discard(prefix); final List<SqlNode> ops = ((SqlCall) node).getOperandList(); final SqlOperator defaultOp = allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL; final SqlNode op0 = ops.get(0); if (!isRunningOrFinal(op0.getKind()) || !allRows && op0.getKind() == SqlKind.RUNNING) { SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0); node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1)); } node = new NavigationExpander().go(node); return node; }
performUnconditionalRewrites(operand, childUnderFrom); if (newOperand != null && newOperand != operand) { call.setOperand(i, newOperand); node = call.getOperator().rewriteCall(this, call); final SqlKind kind = node.getKind(); switch (kind) { case VALUES: selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); final SqlNodeList orderList; if (getInnerSelect(node) != null && isAggregate(getInnerSelect(node))) { orderList = SqlNode.clone(orderBy.orderList); 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), SqlParserPos.ZERO)); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); return new SqlSelect(SqlParserPos.ZERO, null, selectList, call.operand(0), null, null, null, null, null, null, null);
&& rowsPerMatch.getValue() == SqlMatchRecognize.RowsPerMatchOption.ALL_ROWS; if (orderBy != null) { for (SqlNode node : orderBy) { node.validate(this, scope); SqlIdentifier identifier = null; if (node instanceof SqlBasicCall) { pattern.accept(visitor); interval.validate(this, scope); if (((SqlIntervalLiteral) interval).signum() < 0) { throw newValidationError(interval, RESOURCE.intervalMustBeNonNegative(interval.toValue())); for (SqlNode right : (SqlNodeList) operands.get(1)) { SqlIdentifier id = (SqlIdentifier) right; if (!scope.getPatternVars().contains(id.getSimple())) { if (skipTo instanceof SqlCall) { final SqlCall skipToCall = (SqlCall) skipTo; final SqlIdentifier id = skipToCall.operand(0);
boolean forceNullable, final boolean lateral) { final SqlKind kind = node.getKind(); call = (SqlCall) node; if (alias == null) { alias = call.operand(1).toString(); final boolean needAlias = call.operandCount() > 2; expr = call.operand(0); newExpr = registerFrom( throw Util.unexpected(kind); throw Util.unexpected(kind);
@Override public SqlRexConvertlet get(SqlCall call) { if (call.getKind() == SqlKind.EXTRACT && call.getOperandList().get(1).getKind() != SqlKind.LITERAL) { // Avoid using the standard convertlet for EXTRACT(TIMEUNIT FROM col), since we want to handle it directly // in ExtractOperationConversion. return BYPASS_CONVERTLET; } else { final SqlRexConvertlet convertlet = table.get(call.getOperator()); return convertlet != null ? convertlet : StandardConvertletTable.INSTANCE.get(call); } }
SqlNode parsed = sqlParser.parseExpression(); if (parsed instanceof SqlCall || parsed instanceof SqlIdentifier) { String name = parsed instanceof SqlCall ? ((SqlCall) parsed).getOperator().getName() : parsed.toString(); List<String> defIds = functionNameDefMap.get(name); if (defIds == null) {
/** Returns the operands to a call permuted into the same order as the * formal parameters of the function. */ private List<SqlNode> permutedOperands(final SqlCall call) { final SqlFunction operator = (SqlFunction) call.getOperator(); return Lists.transform(operator.getParamNames(), paramName -> { for (SqlNode operand2 : call.getOperandList()) { final SqlCall call2 = (SqlCall) operand2; assert operand2.getKind() == SqlKind.ARGUMENT_ASSIGNMENT; final SqlIdentifier id = call2.operand(1); if (id.getSimple().equals(paramName)) { return call2.operand(0); } } return DEFAULT_CALL; }); }
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); }
/** * Registers any sub-queries inside a given call operand, and converts the * operand to a scalar sub-query if the operator requires it. * * @param parentScope Parent scope * @param call Call * @param operandOrdinal Ordinal of operand within call * @see SqlOperator#argumentMustBeScalar(int) */ private void registerOperandSubQueries( SqlValidatorScope parentScope, SqlCall call, int operandOrdinal) { SqlNode operand = call.operand(operandOrdinal); if (operand == null) { return; } if (operand.getKind().belongsTo(SqlKind.QUERY) && call.getOperator().argumentMustBeScalar(operandOrdinal)) { operand = SqlStdOperatorTable.SCALAR_QUERY.createCall( operand.getParserPosition(), operand); call.setOperand(operandOrdinal, operand); } registerSubQueries(parentScope, operand); }
RelDataType targetRowType, final SqlValidatorScope scope) { assert node.getKind() == SqlKind.VALUES; final List<SqlNode> operands = node.getOperandList(); for (SqlNode operand : operands) { if (!(operand.getKind() == SqlKind.ROW)) { throw Util.needToImplement( "Values function where operands are scalars"); && rowConstructor.operandCount() < targetRowType.getFieldCount()) { targetRowType = typeFactory.createStructType( operand.validate(this, scope);
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; } }
public void unparse( SqlWriter writer, SqlOperator operator, SqlCall call, int leftPrec, int rightPrec) { assert call.operandCount() == 1; call.operand(0).unparse(writer, operator.getLeftPrec(), operator.getRightPrec()); writer.keyword(operator.getName()); } },
private boolean isRowConstructor(SqlNode node) { if (!(node.getKind() == SqlKind.ROW)) { return false; } SqlCall call = (SqlCall) node; return call.getOperator().getName().equalsIgnoreCase("row"); }
if (operand.getKind() != SqlKind.ARGUMENT_ASSIGNMENT) { throw UserException.unsupportedError() .message("Unsupported argument type. Only assignment arguments (param => value) are supported.") .build(logger); final List<SqlNode> operandList = ((SqlCall) operand).getOperandList(); final String name = ((SqlIdentifier) operandList.get(1)).getSimple(); SqlNode literal = operandList.get(0); if (!(literal instanceof SqlLiteral)) { Object value = ((SqlLiteral)literal).getValue(); if (value instanceof NlsString) { value = ((NlsString)value).getValue();