Refine search
@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(); SqlNode innerOffset = innerOperands.get(1); SqlOperator newOperator = innerKind == kind ? SqlStdOperatorTable.PLUS : SqlStdOperatorTable.MINUS; offset = newOperator.createCall(SqlParserPos.ZERO, offset, innerOffset); inner = call.getOperator().createCall(SqlParserPos.ZERO, innerOperands.get(0), offset); inner.accept(new NavigationExpander(call.getOperator(), offset)); if (op != null) { newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode, this.offset); return call.getOperator().createCall(SqlParserPos.ZERO, newOperands); } else { if (op == null) {
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"); if (conformance.isInsertSubsetColumnsAllowed() && targetRowType.isStruct() && rowConstructor.operandCount() < targetRowType.getFieldCount()) { targetRowType = typeFactory.createStructType( targetRowType.getFieldList() .subList(0, rowConstructor.operandCount())); } else if (targetRowType.isStruct() && rowConstructor.operandCount() != targetRowType.getFieldCount()) { return; if (targetRowType.isStruct()) { for (Pair<SqlNode, RelDataTypeField> pair : Pair.zip(rowConstructor.getOperandList(), targetRowType.getFieldList())) { if (!pair.right.getType().isNullable() if (rowCount >= 2) { SqlCall firstRow = (SqlCall) operands.get(0); final int columnCount = firstRow.operandCount();
@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); } }
@Override public SqlNode visit(SqlCall call) { SqlKind kind = call.getKind(); if (isLogicalNavigation(kind) || isAggregation(kind) || isRunningOrFinal(kind)) { return call; } switch (kind) { case PREV: final List<SqlNode> operands = call.getOperandList(); if (operands.get(0) instanceof SqlIdentifier) { String name = ((SqlIdentifier) operands.get(0)).names.get(0); return name.equals(alpha) ? call : SqlStdOperatorTable.LAST.createCall(SqlParserPos.ZERO, operands); } } return super.visit(call); }
/** * 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); }
case TIMESTAMPADD: call = TimestampAddFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); break; default: if (jj_2_669(2)) { call = TimestampDiffFunctionCall(); name = call.getOperator().getName(); args = new SqlNodeList(call.getOperandList(), getPos()); } else if (jj_2_670(2)) { jj_consume_token(CONVERT); name = id.getSimple(); } else if (jj_2_664(2)) { jj_consume_token(RPAREN); args = new SqlNodeList(s1.pos()); args.add(SqlIdentifier.star(s1.pos())); } else if (jj_2_667(2)) { jj_consume_token(LPAREN);
&& rowsPerMatch.getValue() == SqlMatchRecognize.RowsPerMatchOption.ALL_ROWS; pattern.accept(visitor); interval.validate(this, scope); if (((SqlIntervalLiteral) interval).signum() < 0) { throw newValidationError(interval, RESOURCE.intervalMustBeNonNegative(interval.toValue())); if (firstOrderByColumnType.getSqlTypeName() != SqlTypeName.TIMESTAMP) { throw newValidationError(interval, RESOURCE.firstColumnOfOrderByMustBeTimestamp()); 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())) { if (skipTo instanceof SqlCall) { final SqlCall skipToCall = (SqlCall) skipTo; final SqlIdentifier id = skipToCall.operand(0);
final SqlKind kind = call.getKind(); final List<SqlNode> operands = call.getOperandList(); for (int i = 0; i < operands.size(); i++) { SqlNode operand = operands.get(i); performUnconditionalRewrites(operand, childUnderFrom); if (newOperand != null && newOperand != operand) { call.setOperand(i, newOperand); if (call.getOperator() instanceof SqlUnresolvedFunction) { assert call instanceof SqlBasicCall; final SqlUnresolvedFunction function = (SqlUnresolvedFunction) call.getOperator(); 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); selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); return new SqlSelect(SqlParserPos.ZERO, null, selectList, call.operand(0), null, null, null, null, null, null, null);
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()); } },
/** 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; }); }
typeFactory.createTypeWithCharsetAndCollation( newInferredType, inferredType.getCharset(), inferredType.getCollation()); if (inferredType.isStruct()) { if (inferredType.getFieldCount() != nodeList.size()) { final SqlCall call = (SqlCall) node; final SqlOperandTypeInference operandTypeInference = call.getOperator().getOperandTypeInference(); final SqlCallBinding callBinding = new SqlCallBinding(this, scope, call); final List<SqlNode> operands = callBinding.operands();
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) {
call = (SqlCall) node; if (alias == null) { alias = call.operand(1).toString(); final boolean needAlias = call.operandCount() > 2; expr = call.operand(0); newExpr = registerFrom( lateral); if (newExpr != expr) { call.setOperand(0, newExpr); case TABLESAMPLE: call = (SqlCall) node; expr = call.operand(0); newExpr = registerFrom( lateral); if (newExpr != expr) { call.setOperand(0, newExpr); usingScope, register, ((SqlCall) node).operand(0), enclosingNode, alias,
public SqlNode result() { if (update || alwaysCopy) { return call.getOperator().createCall( call.getFunctionQuantifier(), call.getParserPosition(), clonedOperands); } else { return call; } }
@Override public Set<String> visit(SqlCall call) { boolean isSingle = false; Set<String> vars = new HashSet<>(); SqlKind kind = call.getKind(); List<SqlNode> operands = call.getOperandList(); if (isMeasure) { throw newValidationError(call, Static.RESOURCE.patternPrevFunctionInMeasure(call.toString())); Static.RESOURCE.patternPrevFunctionOrder(call.toString())); if (firstLastCount != 0) { throw newValidationError(call, Static.RESOURCE.patternPrevFunctionOrder(call.toString())); Static.RESOURCE.patternAggregationInNavigation(call.toString())); if (kind == SqlKind.COUNT && call.getOperandList().size() > 1) { throw newValidationError(call, Static.RESOURCE.patternCountFunctionArg()); Static.RESOURCE.patternRunningFunctionInDefine(call.toString())); if (operands.size() == 0 || !(operands.get(0) instanceof SqlCall) || ((SqlCall) operands.get(0)).getOperator() != SqlStdOperatorTable.CLASSIFIER) { if (vars.isEmpty()) { throw newValidationError(call, Static.RESOURCE.patternFunctionNullCheck(call.toString()));
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 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); }
selectList = SqlNode.clone(updateStmt.getSourceSelect().getSelectList()); } else { selectList.add(SqlIdentifier.star(SqlParserPos.ZERO)); SqlValidatorUtil.addAlias( targetTable, call.getAlias().getSimple()); SqlInsert insertCall = call.getInsertCall(); JoinType joinType = (insertCall == null) ? JoinType.INNER : JoinType.LEFT; final SqlNode leftJoinTerm = SqlNode.clone(sourceTableRef); SqlNode outerJoin = new SqlJoin(SqlParserPos.ZERO, leftJoinTerm, SqlLiteral.createBoolean(false, SqlParserPos.ZERO), joinType.symbol(SqlParserPos.ZERO), targetTable, SqlCall rowCall = valuesCall.operand(0); selectList = new SqlNodeList( rowCall.getOperandList(), SqlParserPos.ZERO); final SqlNode insertSource = SqlNode.clone(sourceTableRef); select = new SqlSelect(SqlParserPos.ZERO, null, selectList, insertSource, null,
SqlCall thatNode = (SqlCall) exprNode; if (!thisNode.getOperator().getName().equalsIgnoreCase(thatNode.getOperator().getName())) { return false; return isNodeListEqual(thisNode.getOperandList(), thatNode.getOperandList()); SqlLiteral thatNode = (SqlLiteral) exprNode; return Objects.equals(thisNode.getValue(), thatNode.getValue());