Search in sources :

Example 6 with ConstantExpression

use of org.apache.calcite.linq4j.tree.ConstantExpression 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)6 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)4 Method (java.lang.reflect.Method)3 Test (org.junit.Test)3 Expression (org.apache.calcite.linq4j.tree.Expression)2 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)2 BuiltInMethod (org.apache.calcite.util.BuiltInMethod)2 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ByteString (org.apache.calcite.avatica.util.ByteString)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 ClassDeclaration (org.apache.calcite.linq4j.tree.ClassDeclaration)1 ConditionalStatement (org.apache.calcite.linq4j.tree.ConditionalStatement)1 FunctionExpression (org.apache.calcite.linq4j.tree.FunctionExpression)1 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)1 NewArrayExpression (org.apache.calcite.linq4j.tree.NewArrayExpression)1 NewExpression (org.apache.calcite.linq4j.tree.NewExpression)1 Types (org.apache.calcite.linq4j.tree.Types)1 UnaryExpression (org.apache.calcite.linq4j.tree.UnaryExpression)1