Search in sources :

Example 1 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project drill by apache.

the class DrillOperatorTable method populateFromTypeInference.

private void populateFromTypeInference(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) {
    final List<SqlOperator> calciteOperatorList = Lists.newArrayList();
    inner.lookupOperatorOverloads(opName, category, syntax, calciteOperatorList);
    if (!calciteOperatorList.isEmpty()) {
        for (SqlOperator calciteOperator : calciteOperatorList) {
            if (calciteToWrapper.containsKey(calciteOperator)) {
                operatorList.add(calciteToWrapper.get(calciteOperator));
            } else {
                operatorList.add(calciteOperator);
            }
        }
    } else {
        // if no function is found, check in Drill UDFs
        if (operatorList.isEmpty() && (syntax == SqlSyntax.FUNCTION || syntax == SqlSyntax.FUNCTION_ID) && opName.isSimple()) {
            List<SqlOperator> drillOps = drillOperatorsWithInferenceMap.get(opName.getSimple().toLowerCase());
            if (drillOps != null && !drillOps.isEmpty()) {
                operatorList.addAll(drillOps);
            }
        }
    }
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator)

Example 2 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class RelJson method toOp.

private SqlOperator toOp(String op, Map<String, Object> map) {
    // TODO: build a map, for more efficient lookup
    // TODO: look up based on SqlKind
    final List<SqlOperator> operatorList = SqlStdOperatorTable.instance().getOperatorList();
    for (SqlOperator operator : operatorList) {
        if (operator.getName().equals(op)) {
            return operator;
        }
    }
    String class_ = (String) map.get("class");
    if (class_ != null) {
        return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
    }
    return null;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator)

Example 3 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class RexUtil method flatten.

/**
 * Flattens an expression.
 *
 * <p>Returns the same expression if it is already flat.
 */
public static RexNode flatten(RexBuilder rexBuilder, RexNode node) {
    if (node instanceof RexCall) {
        RexCall call = (RexCall) node;
        final SqlOperator op = call.getOperator();
        final List<RexNode> flattenedOperands = flatten(call.getOperands(), op);
        if (!isFlat(call.getOperands(), op)) {
            return rexBuilder.makeCall(call.getType(), op, flattenedOperands);
        }
    }
    return node;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator)

Example 4 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class SqlParserUtil method toTreeEx.

/**
 * Converts a list of {expression, operator, expression, ...} into a tree,
 * taking operator precedence and associativity into account.
 *
 * @param list        List of operands and operators. This list is modified as
 *                    expressions are reduced.
 * @param start       Position of first operand in the list. Anything to the
 *                    left of this (besides the immediately preceding operand)
 *                    is ignored. Generally use value 1.
 * @param minPrec     Minimum precedence to consider. If the method encounters
 *                    an operator of lower precedence, it doesn't reduce any
 *                    further.
 * @param stopperKind If not {@link SqlKind#OTHER}, stop reading the list if
 *                    we encounter a token of this kind.
 * @return the root node of the tree which the list condenses into
 */
public static SqlNode toTreeEx(SqlSpecialOperator.TokenSequence list, int start, final int minPrec, final SqlKind stopperKind) {
    final Predicate<PrecedenceClimbingParser.Token> predicate = new PredicateImpl<PrecedenceClimbingParser.Token>() {

        public boolean test(PrecedenceClimbingParser.Token t) {
            if (t instanceof PrecedenceClimbingParser.Op) {
                final SqlOperator op = ((ToTreeListItem) t.o).op;
                return stopperKind != SqlKind.OTHER && op.kind == stopperKind || minPrec > 0 && op.getLeftPrec() < minPrec;
            } else {
                return false;
            }
        }
    };
    PrecedenceClimbingParser parser = list.parser(start, predicate);
    final int beforeSize = parser.all().size();
    parser.partialParse();
    final int afterSize = parser.all().size();
    final SqlNode node = convert(parser.all().get(0));
    list.replaceSublist(start, start + beforeSize - afterSize + 1, node);
    return node;
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) PredicateImpl(org.apache.calcite.runtime.PredicateImpl) PrecedenceClimbingParser(org.apache.calcite.util.PrecedenceClimbingParser) SqlNode(org.apache.calcite.sql.SqlNode)

Example 5 with SqlOperator

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator in project calcite by apache.

the class SqlLikeOperator method reduceExpr.

public ReduceResult reduceExpr(final int opOrdinal, TokenSequence list) {
    // Example:
    // a LIKE b || c ESCAPE d || e AND f
    // |  |    |      |      |      |
    // exp0    exp1          exp2
    SqlNode exp0 = list.node(opOrdinal - 1);
    SqlOperator op = list.op(opOrdinal);
    assert op instanceof SqlLikeOperator;
    SqlNode exp1 = SqlParserUtil.toTreeEx(list, opOrdinal + 1, getRightPrec(), SqlKind.ESCAPE);
    SqlNode exp2 = null;
    if ((opOrdinal + 2) < list.size()) {
        if (list.isOp(opOrdinal + 2)) {
            final SqlOperator op2 = list.op(opOrdinal + 2);
            if (op2.getKind() == SqlKind.ESCAPE) {
                exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.ESCAPE);
            }
        }
    }
    final SqlNode[] operands;
    int end;
    if (exp2 != null) {
        operands = new SqlNode[] { exp0, exp1, exp2 };
        end = opOrdinal + 4;
    } else {
        operands = new SqlNode[] { exp0, exp1 };
        end = opOrdinal + 2;
    }
    SqlCall call = createCall(SqlParserPos.ZERO, operands);
    return new ReduceResult(opOrdinal - 1, end, call);
}
Also used : SqlOperator(org.apache.calcite.sql.SqlOperator) SqlCall(org.apache.calcite.sql.SqlCall) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlOperator (org.apache.calcite.sql.SqlOperator)129 ArrayList (java.util.ArrayList)44 RexNode (org.apache.calcite.rex.RexNode)41 RelDataType (org.apache.calcite.rel.type.RelDataType)25 SqlCall (org.apache.calcite.sql.SqlCall)24 RexCall (org.apache.calcite.rex.RexCall)21 SqlNode (org.apache.calcite.sql.SqlNode)21 SqlKind (org.apache.calcite.sql.SqlKind)15 List (java.util.List)13 SqlFunction (org.apache.calcite.sql.SqlFunction)13 RelNode (org.apache.calcite.rel.RelNode)12 RexBuilder (org.apache.calcite.rex.RexBuilder)11 RexInputRef (org.apache.calcite.rex.RexInputRef)11 Test (org.junit.Test)11 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)10 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)10 NlsString (org.apache.calcite.util.NlsString)10 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)9 SqlOperator (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperator)9 RexLiteral (org.apache.calcite.rex.RexLiteral)9