Search in sources :

Example 1 with BuiltInMethod

use of org.apache.calcite.util.BuiltInMethod in project calcite by apache.

the class LixToRelTranslator method translate.

public RelNode translate(Expression expression) {
    if (expression instanceof MethodCallExpression) {
        final MethodCallExpression call = (MethodCallExpression) expression;
        BuiltInMethod method = BuiltInMethod.MAP.get(call.method);
        if (method == null) {
            throw new UnsupportedOperationException("unknown method " + call.method);
        }
        RelNode input;
        switch(method) {
            case SELECT:
                input = translate(call.targetExpression);
                return LogicalProject.create(input, toRex(input, (FunctionExpression) call.expressions.get(0)), (List<String>) null);
            case WHERE:
                input = translate(call.targetExpression);
                return LogicalFilter.create(input, toRex((FunctionExpression) call.expressions.get(0), input));
            case AS_QUERYABLE:
                return LogicalTableScan.create(cluster, RelOptTableImpl.create(null, typeFactory.createJavaType(Types.toClass(Types.getElementType(call.targetExpression.getType()))), ImmutableList.<String>of(), call.targetExpression));
            case SCHEMA_GET_TABLE:
                return LogicalTableScan.create(cluster, RelOptTableImpl.create(null, typeFactory.createJavaType((Class) ((ConstantExpression) call.expressions.get(1)).value), ImmutableList.<String>of(), call.targetExpression));
            default:
                throw new UnsupportedOperationException("unknown method " + call.method);
        }
    }
    throw new UnsupportedOperationException("unknown expression type " + expression.getNodeType());
}
Also used : FunctionExpression(org.apache.calcite.linq4j.tree.FunctionExpression) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) RelNode(org.apache.calcite.rel.RelNode) BuiltInMethod(org.apache.calcite.util.BuiltInMethod) ConstantExpression(org.apache.calcite.linq4j.tree.ConstantExpression)

Aggregations

ConstantExpression (org.apache.calcite.linq4j.tree.ConstantExpression)1 FunctionExpression (org.apache.calcite.linq4j.tree.FunctionExpression)1 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)1 RelNode (org.apache.calcite.rel.RelNode)1 BuiltInMethod (org.apache.calcite.util.BuiltInMethod)1