Search in sources :

Example 71 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testOrElseXX.

@Test
void testOrElseXX() {
    // x || x
    ParameterExpression x = Expressions.parameter(boolean.class, "x");
    assertEquals("{\n  return x;\n}\n", optimize(Expressions.orElse(x, x)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.jupiter.api.Test)

Example 72 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testOptimizeTernaryAeqBBA.

@Test
void testOptimizeTernaryAeqBBA() {
    // a == b ? b : a
    ParameterExpression a = Expressions.parameter(boolean.class, "a");
    ParameterExpression b = Expressions.parameter(boolean.class, "b");
    assertEquals("{\n  return a;\n}\n", optimize(Expressions.condition(Expressions.equal(a, b), b, a)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.jupiter.api.Test)

Example 73 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testNotEqualObjectNull.

@Test
void testNotEqualObjectNull() {
    // (Integer) x == null
    ParameterExpression x = Expressions.parameter(Integer.class, "x");
    assertEquals("{\n  return x != null;\n}\n", optimize(Expressions.notEqual(x, NULL)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.jupiter.api.Test)

Example 74 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project calcite by apache.

the class OptimizerTest method testAndAlsoXX.

@Test
void testAndAlsoXX() {
    // x && x
    ParameterExpression x = Expressions.parameter(boolean.class, "x");
    assertEquals("{\n  return x;\n}\n", optimize(Expressions.andAlso(x, x)));
}
Also used : ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Test(org.junit.jupiter.api.Test)

Example 75 with ParameterExpression

use of org.apache.calcite.linq4j.tree.ParameterExpression in project Mycat2 by MyCATApache.

the class MycatTableScan method implement.

@Override
public Result implement(MycatEnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.ARRAY);
    ParameterExpression root = implementor.getRootExpression();
    TableScan tableScan = (TableScan) this.relNode;
    MycatLogicTable mycatLogicTable = (MycatLogicTable) tableScan.getTable().unwrap(AbstractMycatTable.class);
    TableHandler table = mycatLogicTable.getTable();
    Method getObservable = Types.lookupMethod(NewMycatDataContext.class, "getTableObservable", String.class, String.class);
    builder.add(Expressions.call(root, getObservable, Expressions.constant(table.getSchemaName()), Expressions.constant(table.getTableName())));
    return implementor.result(physType, builder.toBlock());
}
Also used : PhysType(org.apache.calcite.adapter.enumerable.PhysType) TableScan(org.apache.calcite.rel.core.TableScan) TableHandler(io.mycat.TableHandler) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Method(java.lang.reflect.Method) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Aggregations

ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)144 Expression (org.apache.calcite.linq4j.tree.Expression)80 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)58 Test (org.junit.jupiter.api.Test)51 ArrayList (java.util.ArrayList)30 ConstantExpression (org.apache.calcite.linq4j.tree.ConstantExpression)30 RelDataType (org.apache.calcite.rel.type.RelDataType)30 Type (java.lang.reflect.Type)27 RexNode (org.apache.calcite.rex.RexNode)23 FunctionExpression (org.apache.calcite.linq4j.tree.FunctionExpression)19 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)12 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)11 BlockStatement (org.apache.calcite.linq4j.tree.BlockStatement)11 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)11 ImmutableList (com.google.common.collect.ImmutableList)10 List (java.util.List)10 EnumUtils.generateCollatorExpression (org.apache.calcite.adapter.enumerable.EnumUtils.generateCollatorExpression)10 PhysType (org.apache.calcite.adapter.enumerable.PhysType)10 Function1 (org.apache.calcite.linq4j.function.Function1)10 UnaryExpression (org.apache.calcite.linq4j.tree.UnaryExpression)10