public static OperatorKey of(final SqlOperator operator) { return new OperatorKey(operator.getName(), operator.getSyntax()); }
public void validateCall( SqlCall call, SqlValidatorScope scope) { final SqlOperator operator = call.getOperator(); if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !conformance.allowNiladicParentheses()) { // For example, "LOCALTIME()" is illegal. (It should be // "LOCALTIME", which would have been handled as a // SqlIdentifier.) throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null); } SqlValidatorScope operandScope = scope.getOperandScope(call); if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) { throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString())); } // Delegate validation to the operator. operator.validateCall(call, this, scope, operandScope); }
@Override public SqlSyntax getSyntax() { return operator.getSyntax(); }
private boolean isHolisticExpression(RexCall call) { /* If we are already processing a holistic expression then all * nested expressions should be treated holistically as well */ if (holisticExpression > 0) { return true; } if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL || call.getOperator().getSyntax() == SqlSyntax.FUNCTION) { return true; } return false; }
private boolean isHolisticExpression(RexCall call) { /* If we are already processing a holistic expression then all * nested expressions should be treated holistically as well */ if (holisticExpression > 0) { return true; } if (call.getOperator().getSyntax() == SqlSyntax.SPECIAL || call.getOperator().getSyntax() == SqlSyntax.FUNCTION) { return true; } return false; }
/** * Writes a SQL representation of a call to this operator to a writer, * including parentheses if the operators on either side are of greater * precedence. * * <p>The default implementation of this method delegates to * {@link SqlSyntax#unparse}. */ public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { getSyntax().unparse(writer, this, call, leftPrec, rightPrec); }
/** * Writes a SQL representation of a call to this operator to a writer, * including parentheses if the operators on either side are of greater * precedence. * * <p>The default implementation of this method delegates to * {@link SqlSyntax#unparse}. */ public void unparse( SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { getSyntax().unparse(writer, this, call, leftPrec, rightPrec); }
private static Iterator<SqlOperator> lookupSubjectRoutinesByName( SqlOperatorTable opTab, SqlIdentifier funcName, final SqlSyntax syntax, SqlFunctionCategory category) { final List<SqlOperator> sqlOperators = new ArrayList<>(); opTab.lookupOperatorOverloads(funcName, category, syntax, sqlOperators); switch (syntax) { case FUNCTION: return Iterators.filter(sqlOperators.iterator(), Predicates.instanceOf(SqlFunction.class)); default: return Iterators.filter(sqlOperators.iterator(), operator -> Objects.requireNonNull(operator).getSyntax() == syntax); } }
private static Iterator<SqlOperator> lookupSubjectRoutinesByName( SqlOperatorTable opTab, SqlIdentifier funcName, final SqlSyntax syntax, SqlFunctionCategory category) { final List<SqlOperator> sqlOperators = new ArrayList<>(); opTab.lookupOperatorOverloads(funcName, category, syntax, sqlOperators); switch (syntax) { case FUNCTION: return Iterators.filter(sqlOperators.iterator(), Predicates.instanceOf(SqlFunction.class)); default: return Iterators.filter(sqlOperators.iterator(), operator -> Objects.requireNonNull(operator).getSyntax() == syntax); } }
/** * Registers a function or operator in the table. */ public void register(SqlOperator op) { operators.put(new Key(op.getName(), op.getSyntax()), op); }
/** * Registers a function or operator in the table. */ public void register(SqlOperator op) { operators.put(new Key(op.getName(), op.getSyntax()), op); }
public static OperatorKey of(final SqlOperator operator) { return new OperatorKey(operator.getName(), operator.getSyntax()); }
@Override public RexNode visitCall(RexCall call) { final boolean isItem = call.getOperator().getSyntax() == SqlSyntax.SPECIAL && call.getOperator() == SqlStdOperatorTable.ITEM; if(isItem){ return visitCandidate(call); } return super.visitCall(call); }
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) { for (SqlOperator operator : this.operatorList) { if (operator.getSyntax() != syntax) { continue; } if (!opName.isSimple() || !operator.isName(opName.getSimple())) { continue; } if (category != null && category != category(operator) && !category.isUserDefinedNotSpecificFunction()) { continue; } operatorList.add(operator); } }
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) { for (SqlOperator operator : this.operatorList) { if (operator.getSyntax() != syntax) { continue; } if (!opName.isSimple() || !operator.isName(opName.getSimple())) { continue; } if (category != null && category != category(operator) && !category.isUserDefinedNotSpecificFunction()) { continue; } operatorList.add(operator); } }
@Test public void testSqlOperatorOverloading() { final SqlStdOperatorTable operatorTable = SqlStdOperatorTable.instance(); for (SqlOperator sqlOperator : operatorTable.getOperatorList()) { String operatorName = sqlOperator.getName(); List<SqlOperator> routines = new ArrayList<>(); operatorTable.lookupOperatorOverloads( new SqlIdentifier(operatorName, SqlParserPos.ZERO), null, sqlOperator.getSyntax(), routines); Iterator<SqlOperator> iter = routines.iterator(); while (iter.hasNext()) { SqlOperator operator = iter.next(); if (!sqlOperator.getClass().isInstance(operator)) { iter.remove(); } } assertThat(routines.size(), equalTo(1)); assertThat(sqlOperator, equalTo(routines.get(0))); } }
@Test public void testSqlOperatorOverloading() { final SqlStdOperatorTable operatorTable = SqlStdOperatorTable.instance(); for (SqlOperator sqlOperator : operatorTable.getOperatorList()) { String operatorName = sqlOperator.getName(); List<SqlOperator> routines = new ArrayList<>(); operatorTable.lookupOperatorOverloads( new SqlIdentifier(operatorName, SqlParserPos.ZERO), null, sqlOperator.getSyntax(), routines); Iterator<SqlOperator> iter = routines.iterator(); while (iter.hasNext()) { SqlOperator operator = iter.next(); if (!sqlOperator.getClass().isInstance(operator)) { iter.remove(); } } assertThat(routines.size(), equalTo(1)); assertThat(sqlOperator, equalTo(routines.get(0))); } }
/** Sanity check: All built-ins are upper-case. We rely on this. */ @Test public void testStandardOperatorNamesAreUpperCase() { for (SqlOperator op : SqlStdOperatorTable.instance().getOperatorList()) { final String name = op.getName(); switch (op.getSyntax()) { case SPECIAL: case INTERNAL: break; default: assertThat(name.toUpperCase(Locale.ROOT), equalTo(name)); break; } } }
/** Sanity check: All built-ins are upper-case. We rely on this. */ @Test public void testStandardOperatorNamesAreUpperCase() { for (SqlOperator op : SqlStdOperatorTable.instance().getOperatorList()) { final String name = op.getName(); switch (op.getSyntax()) { case SPECIAL: case INTERNAL: break; default: assertThat(name.toUpperCase(Locale.ROOT), equalTo(name)); break; } } }