org.apache.calcite.sql.SqlOperator

Here are the examples of the java api org.apache.calcite.sql.SqlOperator taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

141 Examples 7

19 Source : DrillCalciteWrapperUtility.java
with Apache License 2.0
from zpochen

/**
 * This static method will extract the SqlOperator inside the given SqlOperator if the given SqlOperator is wrapped
 * in DrillCalciteSqlWrapper and will just return the given SqlOperator if it is not wrapped.
 */
public static SqlOperator extractSqlOperatorFromWrapper(final SqlOperator sqlOperator) {
    if (sqlOperator instanceof DrillCalciteSqlWrapper) {
        return ((DrillCalciteSqlWrapper) sqlOperator).getOperator();
    } else {
        return sqlOperator;
    }
}

19 Source : DrillCalciteSqlOperatorWrapper.java
with Apache License 2.0
from zpochen

/**
 * This clreplaced serves as a wrapper clreplaced for SqlOperator. The motivation is to plug-in the return type inference and operand
 * type check algorithms of Drill into Calcite's sql validation procedure.
 *
 * Except for the methods which are relevant to the return type inference and operand type check algorithms, the wrapper
 * simply forwards the method calls to the wrapped SqlOperator.
 */
public clreplaced DrillCalciteSqlOperatorWrapper extends SqlOperator implements DrillCalciteSqlWrapper {

    public final SqlOperator operator;

    public DrillCalciteSqlOperatorWrapper(SqlOperator operator, final String rename, final List<DrillFuncHolder> functions) {
        super(operator.getName(), operator.getKind(), operator.getLeftPrec(), operator.getRightPrec(), TypeInferenceUtils.getDrillSqlReturnTypeInference(rename, functions), operator.getOperandTypeInference(), Checker.ANY_CHECKER);
        this.operator = operator;
    }

    @Override
    public SqlOperator getOperator() {
        return operator;
    }

    @Override
    public SqlSyntax getSyntax() {
        return operator.getSyntax();
    }

    @Override
    public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
        return operator.createCall(functionQualifier, pos, operands);
    }

    @Override
    public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
        return operator.rewriteCall(validator, call);
    }

    @Override
    public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
        return true;
    }

    @Override
    public boolean validRexOperands(int count, boolean fail) {
        return true;
    }

    @Override
    public String getSignatureTemplate(final int operandsCount) {
        return operator.getSignatureTemplate(operandsCount);
    }

    @Override
    public String getAllowedSignatures(String opNameToUse) {
        return operator.getAllowedSignatures(opNameToUse);
    }

    @Override
    public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
        return operator.getMonotonicity(call);
    }

    @Override
    public boolean isDeterministic() {
        return operator.isDeterministic();
    }

    @Override
    public boolean requiresDecimalExpansion() {
        return operator.requiresDecimalExpansion();
    }

    @Override
    public boolean argumentMustBeScalar(int ordinal) {
        return operator.argumentMustBeScalar(ordinal);
    }

    @Override
    public String toString() {
        return operator.toString();
    }

    @Override
    public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
        operator.unparse(writer, call, leftPrec, rightPrec);
    }
}

19 Source : DrillReduceAggregatesRule.java
with Apache License 2.0
from zpochen

private static boolean isConversionToSumZeroNeeded(SqlOperator sqlOperator, RelDataType type) {
    sqlOperator = DrillCalciteWrapperUtility.extractSqlOperatorFromWrapper(sqlOperator);
    if (sqlOperator instanceof SqlSumAggFunction && !type.isNullable()) {
        // If SUM(x) is not nullable, the validator must have determined that
        // nulls are impossible (because the group is never empty and x is never
        // null). Therefore we translate to SUM0(x).
        return true;
    }
    return false;
}

19 Source : SqlDropTableExtension.java
with Apache License 2.0
from rayokota

/**
 * Parse tree for {@code DROP TABLE} statement.
 */
public clreplaced SqlDropTableExtension extends SqlDropObject {

    private static final SqlOperator OPERATOR = new SqlSpecialOperator("DROP TABLE", SqlKind.DROP_TABLE);

    /**
     * Creates a SqlDropTable.
     */
    public SqlDropTableExtension(SqlParserPos pos, boolean ifExists, SqlIdentifier name) {
        super(OPERATOR, pos, ifExists, name);
    }
}

19 Source : RexSqlStandardConvertletTable.java
with GNU General Public License v3.0
from MyCATApache

/**
 * Creates and registers a convertlet for an operator in which
 * the SQL and Rex representations are structurally equivalent.
 *
 * @param op operator instance
 */
protected void registerEquivOp(SqlOperator op) {
    registerOp(op, new EquivConvertlet(op));
}

19 Source : HBTQueryConvertor.java
with GNU General Public License v3.0
from MyCATApache

private SqlOperator op(String op) {
    SqlOperator sqlOperator = HBTCalciteSupport.INSTANCE.getSqlOperator(op);
    if (sqlOperator == null) {
        throw new replacedertionError("unknown: " + op);
    }
    return sqlOperator;
}

19 Source : UDFTransformerTest.java
with BSD 2-Clause "Simplified" License
from linkedin

public clreplaced UDFTransformerTest {

    static FrameworkConfig tableOneConfig;

    static String tableOneQuery;

    static FrameworkConfig tableThreeConfig;

    static String tableThreeQuery;

    static final SqlOperator targetUDF = UDFMapUtils.createUDF("targetFunc", ReturnTypes.DOUBLE);

    static final SqlOperator defaultUDF = UDFMapUtils.createUDF("", ReturnTypes.DOUBLE);

    static final SqlDialect sqlDialect = new SqlDialect(SqlDialect.DatabaseProduct.CALCITE, "Calcite", "", NullCollation.HIGH);

    @BeforeTest
    public static void beforeTest() {
        tableOneConfig = TestUtils.createFrameworkConfig(TABLE_ONE);
        tableThreeConfig = TestUtils.createFrameworkConfig(TABLE_THREE);
        tableOneQuery = "select scol, icol, dcol from " + TABLE_ONE.getTableName();
        tableThreeQuery = "select binaryfield, 'literal' from " + TABLE_THREE.getTableName();
    }

    private SqlNode applyTransformation(Project project, SqlOperator operator, String operandTransformer, String resultTransformer, String operatorTransformer) {
        UDFTransformer udfTransformer = UDFTransformer.of("", operator, operandTransformer, resultTransformer, operatorTransformer);
        RexBuilder rexBuilder = project.getCluster().getRexBuilder();
        List<RexNode> sourceOperands = new ArrayList<>();
        List<RexNode> projectOperands = project.getChildExps();
        for (int i = 0; i < projectOperands.size(); ++i) {
            // If the parameter is a reference to a column, we make it a RexInputRef.
            // We make a new reference because the RexBuilder refers to a column based on the output of the projection.
            // We cannot preplaced the the source operands from the Project operator directly because they are references to the
            // columns of the table.
            // We need to create a new input reference to each projection output because it is the new input to the UDF.
            // Unlike input references, other primitives such as RexLiteral can be added as a sourceOperand directly since
            // they are not normally projected as outputs and are not usually input references.
            if (projectOperands.get(i) instanceof RexInputRef) {
                sourceOperands.add(rexBuilder.makeInputRef(project, i));
            } else {
                sourceOperands.add(projectOperands.get(i));
            }
        }
        RelToSqlConverter sqlConverter = new RelToSqlConverter(sqlDialect);
        SqlImplementor.Result result = sqlConverter.visit(project);
        RexNode rexNode = udfTransformer.transformCall(rexBuilder, sourceOperands);
        return result.builder(project, SqlImplementor.Clause.SELECT).context.toSql(null, rexNode);
    }

    private void testTransformation(String query, FrameworkConfig config, SqlOperator operator, String operandTransformer, String resultTransformer, String operatorTransformer, String expected) {
        Project project = (Project) TestUtils.toRel(query, config);
        SqlNode result = applyTransformation(project, operator, operandTransformer, resultTransformer, operatorTransformer);
        replacedertEquals(result.toSqlString(sqlDialect).getSql(), expected);
    }

    private void testFailedTransformation(String query, FrameworkConfig config, SqlOperator operator, String operandTransformer, String resultTransformer, String operatorTransformer, Clreplaced exceptionClreplaced) {
        try {
            Project project = (Project) TestUtils.toRel(query, config);
            applyTransformation(project, operator, operandTransformer, resultTransformer, operatorTransformer);
            fail();
        } catch (Exception e) {
            replacedertTrue(exceptionClreplaced.isInstance(e));
        }
    }

    @Test
    public void testWrongOperandSyntax() {
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "", null, null, IllegalStateException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "{}", null, null, IllegalStateException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{input}]", null, null, JsonSyntaxException.clreplaced);
    }

    @Test
    public void testWrongResultSyntax() {
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, null, "", null, IllegalStateException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, null, "[]", null, IllegalStateException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, null, "{", null, JsonSyntaxException.clreplaced);
    }

    @Test
    public void testInvalidInput() {
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":0}]", null, null, IllegalArgumentException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":4}]", null, null, IllegalArgumentException.clreplaced);
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":-1}]", null, null, IllegalArgumentException.clreplaced);
    }

    @Test
    public void testInvalidJsonNode() {
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"dummy\":0}]", null, null, IllegalArgumentException.clreplaced);
    }

    @Test
    public void testLiteral() {
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"value\":'astring'}]", null, null, "targetFunc('astring')");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"value\":true}]", null, null, "targetFunc(TRUE)");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"value\":5}]", null, null, "targetFunc(5)");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"value\":2.5}]", null, null, "targetFunc(2.5)");
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"value\":[1, 2]}]", null, null, IllegalArgumentException.clreplaced);
    }

    @Test
    public void testResizeTransformation() {
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":1}, {\"input\":3}]", null, null, "targetFunc(scol, dcol)");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[]", null, null, "targetFunc()");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":2}, {\"input\":1}, {\"input\":2}, {\"input\":3}]", null, null, "targetFunc(icol, scol, icol, dcol)");
    }

    @Test
    public void testIdenreplacedyTransformation() {
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, null, null, null, "targetFunc(scol, icol, dcol)");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"input\":1}, {\"input\":2}, {\"input\":3}]", "{\"input\":0}", null, "targetFunc(scol, icol, dcol)");
    }

    @Test
    public void testNormalTransformation() {
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"op\":\"*\",\"operands\":[{\"input\":2},{\"input\":3}]}, {\"input\":1}]", null, null, "targetFunc(icol * dcol, scol)");
        testTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"op\":\"*\",\"operands\":[{\"input\":2},{\"input\":3}]}, {\"input\":1}]", "{\"op\":\"+\",\"operands\":[{\"input\":0},{\"input\":3}]}", null, "targetFunc(icol * dcol, scol) + dcol");
        testFailedTransformation(tableOneQuery, tableOneConfig, targetUDF, "[{\"op\":\"%\",\"operands\":[{\"input\":2},{\"input\":3}]}, {\"input\":1}]", null, null, UnsupportedOperationException.clreplaced);
    }

    @Test
    public void testInputOperatorTransformer() {
        // Verifies that an operator transformer that has an exact match uses its target function.
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"'literal'\", \"input\":2, \"name\":\"newFunc\"}]", "newFunc(binaryfield, 'literal')");
        // Verifies that an operator transformer that has a substring match uses its target function.
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(liter).*$\", \"input\":2, \"name\":\"newFunc\"}]", "newFunc(binaryfield, 'literal')");
        // Verifies that an operator transformer that has no match uses the default trivial function and throws error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, defaultUDF, null, null, "[{\"regex\":\"^.*(?i)(noMatch).*$\", \"input\":2, \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
    }

    @Test
    public void testMultipleOperatorTransformers() {
        // Verifies that all operator transformers in the operator transformers array are tested.
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(noMatch).*$\", \"input\":2, \"name\":\"unmatchFunc\"}," + "{\"regex\":\"^.*(?i)(literal).*$\", \"input\":2, \"name\":\"matchFunc\"}]", "matchFunc(binaryfield, 'literal')");
        // Verifies that the first target function matcher to match is selected has its target function selected.
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"input\":2, \"name\":\"firstFunc\"}," + "{\"regex\":\"^.*(?i)(literal).*$\", \"input\":2, \"name\":\"secondFunc\"}]", "firstFunc(binaryfield, 'literal')");
    }

    @Test
    public void testNoMatchOperatorTransformer() {
        // Verifies that a target function with no default target UDF throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, null, null, null, "[{\"regex\":\"^.*(?i)(noMatch).*$\", \"input\":2, \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
    }

    @Test
    public void testInvalidArgumentsOperatorTransformer() {
        // Verifies that an empty function name throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"input\":2, \"name\":\"\"}]", IllegalArgumentException.clreplaced);
        // Verifies that an input parameter position <= 0 throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"input\":0, \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
        // Verifies that an input parameter position > the input size throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"input\":3, \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
    }

    @Test
    public void testSufficientArgumentsOperatorTransformer() {
        // Verifies that an operator transformer that does not define a matcher throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"input\":2, \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
        // Verifies that an operator transformer that does not define a parameter position throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"name\":\"newFunc\"}]", IllegalArgumentException.clreplaced);
        // Verifies that an operator transformer that does not define a replacement function name throws an error.
        testFailedTransformation(tableThreeQuery, tableThreeConfig, targetUDF, null, null, "[{\"regex\":\"^.*(?i)(literal).*$\", \"input\":2}]", IllegalArgumentException.clreplaced);
    }

    @Test
    public void testOperandTransformerAndOperatorTransformer() {
        // Verifies that an operator transformer used in conjunction with an operand transformer works correctly.
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, "[{\"input\":1}]", null, "[{\"regex\":\"'literal'\", \"input\":2, \"name\":\"newFunc\"}]", "newFunc(binaryfield)");
        testTransformation(tableThreeQuery, tableThreeConfig, targetUDF, "[{\"input\":2}]", null, "[{\"regex\":\"'literal'\", \"input\":2, \"name\":\"newFunc\"}]", "newFunc('literal')");
    }
}

19 Source : UDFMapUtils.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a mapping from Calcite SQL operator to Presto UDF with Presto SqlOperator.
 *
 * @param udfMap Map to store the result
 * @param calciteOp Calcite SQL operator
 * @param numOperands Number of operands
 * @param prestoSqlOperator The Presto Sql Operator that is used as the target operator in the map
 */
static void createUDFMapEntry(Map<String, UDFTransformer> udfMap, SqlOperator calciteOp, int numOperands, SqlOperator prestoSqlOperator) {
    createUDFMapEntry(udfMap, calciteOp, numOperands, prestoSqlOperator, null, null);
}

19 Source : UDFMapUtils.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a mapping for Calcite SQL operator to Presto UDF.
 *
 * @param udfMap Map to store the result
 * @param calciteOp Calcite SQL operator
 * @param numOperands Number of operands
 * @param prestoUDFName Name of Presto UDF
 */
static void createUDFMapEntry(Map<String, UDFTransformer> udfMap, SqlOperator calciteOp, int numOperands, String prestoUDFName) {
    createUDFMapEntry(udfMap, calciteOp, numOperands, prestoUDFName, null, null);
}

19 Source : HiveFunction.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Clreplaced to represent builtin or user-defined Hive function. This provides
 * information required to replacedyze the function call in SQL statement and to
 * convert the Hive function to intermediate representation in Calcite. This does
 * not provide function definition to actually evaluate the function. Right now,
 * this also does not provide implementation to dynamically figure out return type
 * based on input parameters.
 *
 * NOTE: HiveFunction is designed to be "re-usable" clreplaced.
 */
public clreplaced HiveFunction {

    // Function clreplaced name specified in TBLPROPERTIES clause.  It contains path leading to the clreplaced file.
    // Example: "com.linkedin.dali.udf.date.hive.DateFormatToEpoch"
    private final String hiveName;

    private final SqlOperator sqlOperator;

    public HiveFunction(String functionName, SqlOperator sqlOperator) {
        this.hiveName = functionName;
        this.sqlOperator = sqlOperator;
    }

    public String getHiveFunctionName() {
        return hiveName;
    }

    public SqlOperator getSqlOperator() {
        return sqlOperator;
    }

    public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
        return sqlOperator.createCall(qualifier, ZERO, operands.toArray(new SqlNode[operands.size()]));
    }

    // Specific instances of HiveFunction to override default behavior
    /**
     * Instance of cast() function
     */
    public static final HiveFunction CAST = new HiveFunction("cast", SqlStdOperatorTable.CAST) {

        @Override
        public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
            checkNotNull(operands);
            checkArgument(operands.size() == 1);
            return super.createCall(null, ImmutableList.of(operands.get(0), function), null);
        }
    };

    /**
     * Hive {@code CASE} operator
     */
    public static final HiveFunction CASE = new HiveFunction("case", SqlStdOperatorTable.CASE) {

        @Override
        public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
            checkNotNull(operands);
            List<SqlNode> whenNodes = new ArrayList<>();
            List<SqlNode> thenNodes = new ArrayList<>();
            for (int i = 1; i < operands.size() - 1; i += 2) {
                whenNodes.add(operands.get(i));
                thenNodes.add(operands.get(i + 1));
            }
            // 1 node for case, 2n for when/then nodes, and optionally 1 else node
            SqlNode elseNode = operands.size() % 2 == 1 ? SqlLiteral.createNull(ZERO) : Util.last(operands);
            return SqlCase.createSwitched(ZERO, operands.get(0), new SqlNodeList(whenNodes, ZERO), new SqlNodeList(thenNodes, ZERO), elseNode);
        }
    };

    public static final HiveFunction WHEN = new HiveFunction("when", SqlStdOperatorTable.CASE) {

        @Override
        public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
            checkNotNull(operands);
            List<SqlNode> whenNodes = new ArrayList<>();
            List<SqlNode> thenNodes = new ArrayList<>();
            for (int i = 0; i < operands.size() - 1; i += 2) {
                whenNodes.add(operands.get(i));
                thenNodes.add(operands.get(i + 1));
            }
            // 2n for when/then nodes, and optionally 1 else node
            SqlNode elseNode = operands.size() % 2 == 0 ? SqlLiteral.createNull(ZERO) : Util.last(operands);
            return new SqlCase(ZERO, null, new SqlNodeList(whenNodes, ZERO), new SqlNodeList(thenNodes, ZERO), elseNode);
        }
    };

    // this handles both between and not_between...it's odd because hive parse tree for between operator is odd!
    public static final HiveFunction BETWEEN = new HiveFunction("between", SqlStdOperatorTable.BETWEEN) {

        @Override
        public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
            checkNotNull(operands);
            checkArgument(operands.size() >= 3 && operands.get(0) instanceof SqlLiteral);
            SqlLiteral opType = (SqlLiteral) operands.get(0);
            List<SqlNode> callParams = operands.subList(1, operands.size());
            if (opType.booleanValue()) {
                return SqlStdOperatorTable.NOT_BETWEEN.createCall(ZERO, callParams);
            } else {
                return SqlStdOperatorTable.BETWEEN.createCall(ZERO, callParams);
            }
        }
    };

    public static final HiveFunction IN = new HiveFunction("in", HiveInOperator.IN) {

        @Override
        public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
            checkState(operands.size() >= 2);
            SqlNode lhs = operands.get(0);
            SqlNode firstRhs = operands.get(1);
            if (firstRhs instanceof SqlSelect) {
                // for IN subquery use Calcite IN operator. Calcite IN operator
                // will turn it into inner join, which not ideal but that's better
                // tested.
                return SqlStdOperatorTable.IN.createCall(ZERO, operands);
            } else {
                // column IN values () clause
                List<SqlNode> rhsList = operands.subList(1, operands.size());
                SqlNodeList rhs = new SqlNodeList(rhsList, ZERO);
                return getSqlOperator().createCall(ZERO, lhs, rhs);
            }
        }
    };
}

19 Source : ListSqlOperatorTable.java
with Apache License 2.0
from lealone

protected static SqlFunctionCategory category(SqlOperator operator) {
    if (operator instanceof SqlFunction) {
        return ((SqlFunction) operator).getFunctionType();
    } else {
        return SqlFunctionCategory.SYSTEM;
    }
}

19 Source : ListSqlOperatorTable.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public void add(SqlOperator op) {
    operatorList.add(op);
}

19 Source : SetopOperandTypeChecker.java
with Apache License 2.0
from lealone

public String getAllowedSignatures(SqlOperator op, String opName) {
    return "{0} " + opName + " {1}";
}

19 Source : SameOperandTypeChecker.java
with Apache License 2.0
from lealone

public String getAllowedSignatures(SqlOperator op, String opName) {
    final String typeName = getTypeName();
    return SqlUtil.getAliasedSignature(op, opName, nOperands == -1 ? ImmutableList.of(typeName, typeName, "...") : Collections.nCopies(nOperands, typeName));
}

19 Source : MultisetOperandTypeChecker.java
with Apache License 2.0
from lealone

public String getAllowedSignatures(SqlOperator op, String opName) {
    return "<MULTISET> " + opName + " <MULTISET>";
}

19 Source : LiteralOperandTypeChecker.java
with Apache License 2.0
from lealone

public String getAllowedSignatures(SqlOperator op, String opName) {
    return "<LITERAL>";
}

19 Source : FamilyOperandTypeChecker.java
with Apache License 2.0
from lealone

public String getAllowedSignatures(SqlOperator op, String opName) {
    return SqlUtil.getAliasedSignature(op, opName, families);
}

19 Source : RexMultisetUtil.java
with Apache License 2.0
from lealone

/**
 * Returns a reference to the first found multiset call or null if none was
 * found
 */
public static RexCall findFirstMultiset(final RexNode node, boolean deep) {
    if (node instanceof RexFieldAccess) {
        return findFirstMultiset(((RexFieldAccess) node).getReferenceExpr(), deep);
    }
    if (!(node instanceof RexCall)) {
        return null;
    }
    final RexCall call = (RexCall) node;
    RexCall firstOne = null;
    for (SqlOperator op : MULTISET_OPERATORS) {
        firstOne = RexUtil.findOperatorCall(op, call);
        if (null != firstOne) {
            if (firstOne.getOperator().equals(SqlStdOperatorTable.CAST) && !isMultisetCast(firstOne)) {
                firstOne = null;
                continue;
            }
            break;
        }
    }
    if (!deep && (firstOne != call)) {
        return null;
    }
    return firstOne;
}

19 Source : FindLimit0Visitor.java
with Apache License 2.0
from lealone

private static boolean isUnsupportedScalarFunction(final SqlOperator operator) {
    return operator instanceof DrillSqlOperator && unsupportedFunctions.contains(operator.getName().toUpperCase());
}

19 Source : DrillCalciteSqlOperatorWrapper.java
with Apache License 2.0
from lealone

/**
 * This clreplaced serves as a wrapper clreplaced for SqlOperator. The motivation is to plug-in the return type inference and operand
 * type check algorithms of Drill into Calcite's sql validation procedure.
 *
 * Except for the methods which are relevant to the return type inference and operand type check algorithms, the wrapper
 * simply forwards the method calls to the wrapped SqlOperator.
 */
public clreplaced DrillCalciteSqlOperatorWrapper extends SqlOperator implements DrillCalciteSqlWrapper {

    public final SqlOperator operator;

    public DrillCalciteSqlOperatorWrapper(SqlOperator operator, final String rename, final List<DrillFuncHolder> functions) {
        super(operator.getName(), operator.getKind(), operator.getLeftPrec(), operator.getRightPrec(), TypeInferenceUtils.getDrillSqlReturnTypeInference(rename, functions), operator.getOperandTypeInference(), Checker.ANY_CHECKER);
        this.operator = operator;
    }

    @Override
    public SqlOperator getOperator() {
        return operator;
    }

    @Override
    public SqlSyntax getSyntax() {
        return operator.getSyntax();
    }

    @Override
    public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
        return operator.createCall(functionQualifier, pos, operands);
    }

    @Override
    public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
        return operator.rewriteCall(validator, call);
    }

    @Override
    public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
        return true;
    }

    @Override
    public boolean validRexOperands(int count, Litmus litmus) {
        return true;
    }

    @Override
    public String getSignatureTemplate(final int operandsCount) {
        return operator.getSignatureTemplate(operandsCount);
    }

    @Override
    public String getAllowedSignatures(String opNameToUse) {
        return operator.getAllowedSignatures(opNameToUse);
    }

    @Override
    public SqlMonotonicity getMonotonicity(SqlOperatorBinding call) {
        return operator.getMonotonicity(call);
    }

    @Override
    public boolean isDeterministic() {
        return operator.isDeterministic();
    }

    @Override
    public boolean requiresDecimalExpansion() {
        return operator.requiresDecimalExpansion();
    }

    @Override
    public boolean argumentMustBeScalar(int ordinal) {
        return operator.argumentMustBeScalar(ordinal);
    }

    @Override
    public String toString() {
        return operator.toString();
    }

    @Override
    public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
        operator.unparse(writer, call, leftPrec, rightPrec);
    }
}

19 Source : OperatorTable.java
with Apache License 2.0
from dremio

public void add(String name, SqlOperator op) {
    operators.add(op);
    opMap.put(name.toUpperCase(), op);
}

19 Source : DremioArgChecker.java
with Apache License 2.0
from dremio

public String getAllowedSignatures(SqlOperator op, String opName) {
    return String.format(signature, opName);
}

19 Source : DremioSqlDialect.java
with Apache License 2.0
from dremio

/**
 * Gets a transformer to adjust the given RexCall
 */
public CallTransformer getCallTransformer(SqlOperator op) {
    return NoOpTransformer.INSTANCE;
}

19 Source : CallTransformer.java
with Apache License 2.0
from dremio

/**
 * Indicates if the given operator should be transformed by this.
 */
public boolean matches(SqlOperator operator) {
    return getCompatibleOperators().contains(operator);
}

18 Source : DrillOperatorTable.java
with Apache License 2.0
from zpochen

/**
 * When the option planner.type_inference.enable is turned on, the operators which are added via this method
 * will be used.
 */
public void addOperatorWithInference(String name, SqlOperator op) {
    drillOperatorsWithInference.add(op);
    drillOperatorsWithInferenceMap.put(name.toLowerCase(), op);
}

18 Source : DrillOperatorTable.java
with Apache License 2.0
from zpochen

/**
 * When the option planner.type_inference.enable is turned off, the operators which are added via this method
 * will be used.
 */
public void addOperatorWithoutInference(String name, SqlOperator op) {
    drillOperatorsWithoutInference.add(op);
    drillOperatorsWithoutInferenceMap.put(name.toLowerCase(), op);
}

18 Source : Checker.java
with Apache License 2.0
from zpochen

@Override
public String getAllowedSignatures(SqlOperator op, String opName) {
    return opName + "(Drill - Opaque)";
}

18 Source : PreProcessLogicalRel.java
with Apache License 2.0
from zpochen

private UserException getConvertFunctionException(final String functionName, final String typeName) {
    final String newFunctionName = functionName + typeName;
    final String typeNameToPrint = typeName.length() == 0 ? "<empty_string>" : typeName;
    final UserException.Builder exceptionBuilder = UserException.unsupportedError().message("%s does not support conversion %s type '%s'.", functionName, functionName.substring(8).toLowerCase(), typeNameToPrint);
    // Build a nice error message
    if (typeName.length() > 0) {
        List<String> ops = new ArrayList<>();
        for (SqlOperator op : table.getOperatorList()) {
            ops.add(op.getName());
        }
        final String bestMatch = ApproximateStringMatcher.getBestMatch(ops, newFunctionName);
        if (bestMatch != null && bestMatch.length() > functionName.length() && bestMatch.toLowerCase().startsWith("convert")) {
            final StringBuilder s = new StringBuilder("Did you mean ").append(bestMatch.substring(functionName.length())).append("?");
            exceptionBuilder.addContext(s.toString());
        }
    }
    return exceptionBuilder.build(logger);
}

18 Source : UDFTransformer.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a new transformer.
 *
 * @param calciteOperatorName Name of the Calcite function replacedociated with this UDF
 * @param targetOperator Target operator (a UDF in the target language)
 * @param operandTransformers JSON string representing the operand transformations,
 *                            null for idenreplacedy transformations
 * @param resultTransformer JSON string representing the result transformation,
 *                          null for idenreplacedy transformation
 * @param operatorTransformers JSON string representing an array of transformers that can vary the name of the target
 *                             operator based on runtime parameter values.
 *                             In the order of the JSON Array, the first transformer that matches the JSON string will
 *                             have its given operator named selected as the target operator name.
 *                             Operands are indexed beginning at index 1.
 *                             An operatorTransformer has the following serialized JSON string format:
 *                             "[
 *                               {
 *                                  \"name\" : \"{Name of function if this matches}\",
 *                                  \"input\" : {Index of the parameter starting at index 1 that is evaluated },
 *                                  \"regex\" : \"{Java Regex string matching the parameter at given input}\"
 *                               },
 *                               ...
 *                             ]"
 *                             For example, a transformer for a operator named "foo" when parameter 2 matches exactly
 *                             "bar" is specified as:
 *                             "[
 *                               {
 *                                  \"name\" : \"foo\",
 *                                  \"input\" : 2,
 *                                  \"regex\" : \"'bar'\"
 *                               }
 *                             ]"
 *                             NOTE: A string literal is represented exactly as ['STRING_LITERAL'] with the single
 *                             quotation marks INCLUDED.
 *                             As seen in the example above, the single quotation marks are also present in the
 *                             regex matcher.
 *
 * @return {@link UDFTransformer} object
 */
public static UDFTransformer of(@Nonnull String calciteOperatorName, @Nonnull SqlOperator targetOperator, @Nullable String operandTransformers, @Nullable String resultTransformer, @Nullable String operatorTransformers) {
    List<JsonObject> operands = null;
    JsonObject result = null;
    List<JsonObject> operators = null;
    if (operandTransformers != null) {
        operands = parseJsonObjectsFromString(operandTransformers);
    }
    if (resultTransformer != null) {
        result = new JsonParser().parse(resultTransformer).getAsJsonObject();
    }
    if (operatorTransformers != null) {
        operators = parseJsonObjectsFromString(operatorTransformers);
    }
    return new UDFTransformer(calciteOperatorName, targetOperator, operands, result, operators);
}

18 Source : UDFMapUtils.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a mapping from Calcite SQL operator to Presto UDF with Presto UDF name, operands transformer, and result transformers.
 * To construct Presto SqlOperator from Presto UDF name, this method reuses the return type inference from calciteOp,
 * replaceduming equivalence.
 *
 * @param udfMap Map to store the result
 * @param calciteOp Calcite SQL operator
 * @param numOperands Number of operands
 * @param prestoUDFName Name of Presto UDF
 * @param operandTransformer Operand transformers, null for idenreplacedy transformation
 * @param resultTransformer Result transformer, null for idenreplacedy transformation
 */
static void createUDFMapEntry(Map<String, UDFTransformer> udfMap, SqlOperator calciteOp, int numOperands, String prestoUDFName, String operandTransformer, String resultTransformer) {
    createUDFMapEntry(udfMap, calciteOp, numOperands, createUDF(prestoUDFName, calciteOp.getReturnTypeInference()), operandTransformer, resultTransformer);
}

18 Source : UDFMapUtils.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a mapping from Calcite SQL operator to Presto UDF with Presto SqlOperator, operands transformer, and result transformers.
 *
 * @param udfMap Map to store the result
 * @param calciteOp Calcite SQL operator
 * @param numOperands Number of operands
 * @param prestoSqlOperator The Presto Sql Operator that is used as the target operator in the map
 * @param operandTransformer Operand transformers, null for idenreplacedy transformation
 * @param resultTransformer Result transformer, null for idenreplacedy transformation
 */
static void createUDFMapEntry(Map<String, UDFTransformer> udfMap, SqlOperator calciteOp, int numOperands, SqlOperator prestoSqlOperator, String operandTransformer, String resultTransformer) {
    udfMap.put(getKey(calciteOp.getName(), numOperands), UDFTransformer.of(calciteOp.getName(), prestoSqlOperator, operandTransformer, resultTransformer, null));
}

18 Source : UDFMapUtils.java
with BSD 2-Clause "Simplified" License
from linkedin

/**
 * Creates a mapping from a Calcite SQL operator to a Presto UDF determined at runtime
 * by the values of input parameters with operand and result transformers.
 *
 * @param udfMap Map to store the result
 * @param calciteOp Calcite SQL operator
 * @param numOperands Number of operands
 * @param operatorTransformers Operator transformers as a JSON string.
 * @param operandTransformer Operand transformers, null for idenreplacedy transformation
 * @param resultTransformer Result transformer, null for idenreplacedy transformation
 */
static void createRuntimeUDFMapEntry(Map<String, UDFTransformer> udfMap, SqlOperator calciteOp, int numOperands, String operatorTransformers, String operandTransformer, String resultTransformer) {
    createUDFMapEntry(udfMap, calciteOp, numOperands, createUDF("", calciteOp.getReturnTypeInference()), operandTransformer, resultTransformer);
}

18 Source : StaticHiveFunctionRegistry.java
with BSD 2-Clause "Simplified" License
from linkedin

private static void addFunctionEntry(String functionName, SqlOperator operator) {
    FUNCTION_MAP.put(functionName, new HiveFunction(functionName, operator));
}

18 Source : ReflectiveConvertletTable.java
with Apache License 2.0
from lealone

/**
 * Registers a convertlet for a given operator instance
 *
 * @param op         Operator instance, say
 * {@link org.apache.calcite.sql.fun.SqlStdOperatorTable#MINUS}
 * @param convertlet Convertlet
 */
protected void registerOp(SqlOperator op, SqlRexConvertlet convertlet) {
    map.put(op, convertlet);
}

18 Source : ReflectiveConvertletTable.java
with Apache License 2.0
from lealone

/**
 * Registers that one operator is an alias for another.
 *
 * @param alias  Operator which is alias
 * @param target Operator to translate calls to
 */
protected void addAlias(final SqlOperator alias, final SqlOperator target) {
    map.put(alias, (SqlRexConvertlet) (cx, call) -> {
        Preconditions.checkArgument(call.getOperator() == alias, "call to wrong operator");
        final SqlCall newCall = target.createCall(SqlParserPos.ZERO, call.getOperandList());
        return cx.convertExpression(newCall);
    });
}

18 Source : ReflectiveSqlOperatorTable.java
with Apache License 2.0
from lealone

/**
 * Registers a function or operator in the table.
 */
public void register(SqlOperator op) {
    operators.put(new Key(op.getName(), op.getSyntax()), op);
}

18 Source : BigQuerySqlDialect.java
with Apache License 2.0
from lealone

/**
 * A <code>SqlDialect</code> implementation for Google BigQuery's "Standard SQL"
 * dialect.
 */
public clreplaced BigQuerySqlDialect extends SqlDialect {

    public static final SqlDialect DEFAULT = new BigQuerySqlDialect(EMPTY_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY).withNullCollation(NullCollation.LOW));

    /**
     * Creates a BigQuerySqlDialect.
     */
    public BigQuerySqlDialect(SqlDialect.Context context) {
        super(context);
    }

    @Override
    public void unparseCall(final SqlWriter writer, final SqlCall call, final int leftPrec, final int rightPrec) {
        switch(call.getKind()) {
            case POSITION:
                final SqlWriter.Frame frame = writer.startFunCall("STRPOS");
                writer.sep(",");
                call.operand(1).unparse(writer, leftPrec, rightPrec);
                writer.sep(",");
                call.operand(0).unparse(writer, leftPrec, rightPrec);
                if (3 == call.operandCount()) {
                    throw new RuntimeException("3rd operand Not Supported for Function STRPOS in Big Query");
                }
                writer.endFunCall(frame);
                break;
            case UNION:
                if (!((SqlSetOperator) call.getOperator()).isAll()) {
                    SqlSyntax.BINARY.unparse(writer, UNION_DISTINCT, call, leftPrec, rightPrec);
                }
                break;
            case EXCEPT:
                if (!((SqlSetOperator) call.getOperator()).isAll()) {
                    SqlSyntax.BINARY.unparse(writer, EXCEPT_DISTINCT, call, leftPrec, rightPrec);
                }
                break;
            case INTERSECT:
                if (!((SqlSetOperator) call.getOperator()).isAll()) {
                    SqlSyntax.BINARY.unparse(writer, INTERSECT_DISTINCT, call, leftPrec, rightPrec);
                }
                break;
            default:
                super.unparseCall(writer, call, leftPrec, rightPrec);
        }
    }

    /**
     * List of BigQuery Specific Operators needed to form Syntactically Correct SQL.
     */
    private static final SqlOperator UNION_DISTINCT = new SqlSetOperator("UNION DISTINCT", SqlKind.UNION, 14, false);

    private static final SqlSetOperator EXCEPT_DISTINCT = new SqlSetOperator("EXCEPT DISTINCT", SqlKind.EXCEPT, 14, false);

    private static final SqlSetOperator INTERSECT_DISTINCT = new SqlSetOperator("INTERSECT DISTINCT", SqlKind.INTERSECT, 18, false);
}

18 Source : RexSqlReflectiveConvertletTable.java
with Apache License 2.0
from lealone

/**
 * Registers a convertlet for a given operator instance
 *
 * @param op         Operator instance, say
 * {@link org.apache.calcite.sql.fun.SqlStdOperatorTable#MINUS}
 * @param convertlet Convertlet
 */
protected void registerOp(SqlOperator op, RexSqlConvertlet convertlet) {
    map.put(op, convertlet);
}

18 Source : RexSqlReflectiveConvertletTable.java
with Apache License 2.0
from lealone

// ~ Methods ----------------------------------------------------------------
public RexSqlConvertlet get(RexCall call) {
    RexSqlConvertlet convertlet;
    final SqlOperator op = call.getOperator();
    // Is there a convertlet for this operator
    // (e.g. SqlStdOperatorTable.plusOperator)?
    convertlet = (RexSqlConvertlet) map.get(op);
    if (convertlet != null) {
        return convertlet;
    }
    // Is there a convertlet for this clreplaced of operator
    // (e.g. SqlBinaryOperator)?
    Clreplaced<? extends Object> clazz = op.getClreplaced();
    while (clazz != null) {
        convertlet = (RexSqlConvertlet) map.get(clazz);
        if (convertlet != null) {
            return convertlet;
        }
        clazz = clazz.getSuperclreplaced();
    }
    // Is there a convertlet for this clreplaced of expression
    // (e.g. SqlCall)?
    clazz = call.getClreplaced();
    while (clazz != null) {
        convertlet = (RexSqlConvertlet) map.get(clazz);
        if (convertlet != null) {
            return convertlet;
        }
        clazz = clazz.getSuperclreplaced();
    }
    return null;
}

18 Source : RelJson.java
with Apache License 2.0
from lealone

private String toJson(SqlOperator operator) {
    // User-defined operators are not yet handled.
    return operator.getName();
}

18 Source : SqlTableOption.java
with Apache License 2.0
from flink-tpc-ds

/**
 * Table options of a DDL, a key-value pair
 * with both key and value as string literal.
 */
public clreplaced SqlTableOption extends SqlCall {

    /**
     * Use this operator only if you don't have a better one.
     */
    protected static final SqlOperator OPERATOR = new SqlSpecialOperator("TableOption", SqlKind.OTHER);

    private final SqlNode key;

    private final SqlNode value;

    public SqlTableOption(SqlNode key, SqlNode value, SqlParserPos pos) {
        super(pos);
        this.key = requireNonNull(key, "Option key is missing");
        this.value = requireNonNull(value, "Option value is missing");
    }

    public SqlNode getKey() {
        return key;
    }

    public SqlNode getValue() {
        return value;
    }

    public String getKeyString() {
        return ((NlsString) SqlLiteral.value(key)).getValue();
    }

    public String getValueString() {
        return ((NlsString) SqlLiteral.value(value)).getValue();
    }

    @Override
    public SqlOperator getOperator() {
        return OPERATOR;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableNullableList.of(key, value);
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        key.unparse(writer, leftPrec, rightPrec);
        writer.keyword("=");
        value.unparse(writer, leftPrec, rightPrec);
    }
}

18 Source : SqlDropView.java
with Apache License 2.0
from flink-tpc-ds

/**
 * DROP VIEW DDL sql call.
 */
public clreplaced SqlDropView extends SqlDrop implements ExtendedSqlNode {

    private static final SqlOperator OPERATOR = new SqlSpecialOperator("DROP VIEW", SqlKind.DROP_VIEW);

    private final SqlIdentifier viewName;

    public SqlDropView(SqlParserPos pos, SqlIdentifier viewName, boolean ifExists) {
        super(OPERATOR, pos, ifExists);
        this.viewName = viewName;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableNullableList.of(viewName);
    }

    public SqlIdentifier getViewName() {
        return viewName;
    }

    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("DROP");
        writer.keyword("VIEW");
        if (ifExists) {
            writer.keyword("IF EXISTS");
        }
        viewName.unparse(writer, leftPrec, rightPrec);
    }

    public void validate() {
    // no-op
    }

    public String[] fullViewName() {
        return viewName.names.toArray(new String[0]);
    }
}

18 Source : SqlDropTable.java
with Apache License 2.0
from flink-tpc-ds

/**
 * DROP TABLE DDL sql call.
 */
public clreplaced SqlDropTable extends SqlDrop implements ExtendedSqlNode {

    private static final SqlOperator OPERATOR = new SqlSpecialOperator("DROP TABLE", SqlKind.DROP_TABLE);

    private SqlIdentifier tableName;

    private boolean ifExists;

    public SqlDropTable(SqlParserPos pos, SqlIdentifier tableName, boolean ifExists) {
        super(OPERATOR, pos, ifExists);
        this.tableName = tableName;
        this.ifExists = ifExists;
    }

    @Override
    public List<SqlNode> getOperandList() {
        return ImmutableNullableList.of(tableName);
    }

    public SqlIdentifier getTableName() {
        return tableName;
    }

    public void setTableName(SqlIdentifier viewName) {
        this.tableName = viewName;
    }

    public boolean getIfExists() {
        return this.ifExists;
    }

    public void setIfExists(boolean ifExists) {
        this.ifExists = ifExists;
    }

    @Override
    public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
        writer.keyword("DROP");
        writer.keyword("TABLE");
        if (ifExists) {
            writer.keyword("IF EXISTS");
        }
        tableName.unparse(writer, leftPrec, rightPrec);
    }

    public void validate() {
    // no-op
    }

    public String[] fullTableName() {
        return tableName.names.toArray(new String[0]);
    }
}

18 Source : Checker.java
with Apache License 2.0
from dremio

@Override
public String getAllowedSignatures(SqlOperator op, String opName) {
    return opName + "(Dremio - Opaque)";
}

18 Source : DremioSqlDialect.java
with Apache License 2.0
from dremio

@Override
public boolean supportsFunction(SqlOperator operator, RelDataType type, List<RelDataType> paramTypes) {
    // Non-ARP dialects do not allow UDFs but do allow everything else.
    // TODO: DX-13199. Some functions such as Flatten are Dremio functions but not subclreplacedes
    // of SqlOperatorImpl so they could preplaced this check and we'll try to push them down.
    return !(operator instanceof SqlOperatorImpl);
}

18 Source : DremioSqlDialect.java
with Apache License 2.0
from dremio

/**
 * Indicates if the given operator, which takes in a time unit literal, is supported with
 * the given time unit.
 * <p>
 * The operands parameter includes the TimeUnit itself.
 */
public boolean supportsTimeUnitFunction(SqlOperator operator, TimeUnitRange timeUnit, RelDataType returnType, List<RelDataType> paramTypes) {
    return supportsFunction(operator, returnType, paramTypes);
}

18 Source : NoOpTransformer.java
with Apache License 2.0
from dremio

@Override
public boolean matches(SqlOperator op) {
    return true;
}

18 Source : TestORCFindRelevantFilters.java
with Apache License 2.0
from dremio

private void singleOpTest(SqlOperator op) {
    RexNode eqInt = builder.makeCall(op, asList(input(0), intLit(0, 23)));
    replacedertEqualsDigest(eqInt, eqInt.accept(finder));
    RexNode eqBigInt = builder.makeCall(op, asList(input(1), bigIntLit(1, 23234234L)));
    replacedertEqualsDigest(eqBigInt, eqBigInt.accept(finder));
    RexNode eqFloat = builder.makeCall(op, asList(input(2), floatLit(2, 23234.233f)));
    replacedertEqualsDigest(eqFloat, eqFloat.accept(finder));
    RexNode eqDouble = builder.makeCall(op, asList(input(3), doubleLit(3, 235234234.234324d)));
    replacedertEqualsDigest(eqDouble, eqDouble.accept(finder));
    RexNode eqDate = builder.makeCall(op, asList(input(4), dateLit(4, 1231293712)));
    replacedertEqualsDigest(eqDate, eqDate.accept(finder));
    RexNode eqTs = builder.makeCall(op, asList(input(5), tsLit(5, 232349893L)));
    replacedertEqualsDigest(eqTs, eqTs.accept(finder));
    RexNode eqVarchar = builder.makeCall(op, asList(input(6), varcharLit(6, "str")));
    replacedertEqualsDigest(eqVarchar, eqVarchar.accept(finder));
    RexNode eqBool = builder.makeCall(op, asList(input(7), boolLit(7, false)));
    replacedertEqualsDigest(eqBool, eqBool.accept(finder));
}

18 Source : SqlParseUtil.java
with Apache License 2.0
from binglind

private static void parseFunction(SqlNode sqlNode, List<String> udfs) {
    if (sqlNode instanceof SqlBasicCall) {
        SqlBasicCall sqlBasicCall = (SqlBasicCall) sqlNode;
        SqlOperator operator = sqlBasicCall.getOperator();
        if (operator instanceof SqlFunction) {
            SqlFunction sqlFunction = (SqlFunction) operator;
            SqlFunctionCategory category = sqlFunction.getFunctionType();
            switch(category) {
                case USER_DEFINED_FUNCTION:
                case USER_DEFINED_SPECIFIC_FUNCTION:
                case USER_DEFINED_TABLE_FUNCTION:
                case USER_DEFINED_TABLE_SPECIFIC_FUNCTION:
                    addUdf(udfs, sqlFunction.getName());
                    break;
                default:
            }
        } else {
            parseFunction(sqlBasicCall.operand(0), udfs);
        }
        // 查询嵌套的函数
        SqlNode[] nodes = sqlBasicCall.getOperands();
        if (nodes != null && nodes.length > 0) {
            for (SqlNode node : nodes) {
                parseFunction(node, udfs);
            }
        }
    }
}

18 Source : HiveSqlFunction.java
with Apache License 2.0
from 51nb

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof SqlOperator)) {
        return false;
    }
    if (!obj.getClreplaced().equals(this.getClreplaced())) {
        return false;
    }
    SqlOperator other = (SqlOperator) obj;
    return getName().equals(other.getName()) && kind == other.kind && getSyntax().equals(other.getSyntax());
}

See More Examples