Search in sources :

Example 1 with SqlLikeOperator

use of org.apache.calcite.sql.fun.SqlLikeOperator in project hazelcast by hazelcast.

the class HazelcastLikeOperator method reduceExpr.

@Override
public ReduceResult reduceExpr(int opOrdinal, TokenSequence list) {
    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)) {
            SqlOperator op2 = list.op(opOrdinal + 2);
            if (op2.getKind() == SqlKind.ESCAPE) {
                exp2 = SqlParserUtil.toTreeEx(list, opOrdinal + 3, getRightPrec(), SqlKind.ESCAPE);
            }
        }
    }
    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) SqlLikeOperator(org.apache.calcite.sql.fun.SqlLikeOperator) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlCall (org.apache.calcite.sql.SqlCall)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlOperator (org.apache.calcite.sql.SqlOperator)1 SqlLikeOperator (org.apache.calcite.sql.fun.SqlLikeOperator)1