Search in sources :

Example 1 with OptimizeShuttle

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

the class BlockBuilderTest method testTestCustomOptimizer.

@Test
public void testTestCustomOptimizer() {
    BlockBuilder b = new BlockBuilder() {

        @Override
        protected Shuttle createOptimizeShuttle() {
            return new OptimizeShuttle() {

                @Override
                public Expression visit(BinaryExpression binary, Expression expression0, Expression expression1) {
                    if (binary.getNodeType() == ExpressionType.Add && ONE.equals(expression0) && TWO.equals(expression1)) {
                        return FOUR;
                    }
                    return super.visit(binary, expression0, expression1);
                }
            };
        }
    };
    b.add(Expressions.return_(null, Expressions.add(ONE, TWO)));
    assertEquals("{\n  return 4;\n}\n", b.toBlock().toString());
}
Also used : BinaryExpression(org.apache.calcite.linq4j.tree.BinaryExpression) BinaryExpression(org.apache.calcite.linq4j.tree.BinaryExpression) Expression(org.apache.calcite.linq4j.tree.Expression) OptimizeShuttle(org.apache.calcite.linq4j.tree.OptimizeShuttle) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder) Test(org.junit.Test)

Aggregations

BinaryExpression (org.apache.calcite.linq4j.tree.BinaryExpression)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 OptimizeShuttle (org.apache.calcite.linq4j.tree.OptimizeShuttle)1 Test (org.junit.Test)1