use of org.apache.calcite.linq4j.tree.DeclarationStatement in project calcite by apache.
the class ExpressionTest method testWriteWhile.
@Test
public void testWriteWhile() {
DeclarationStatement xDecl;
DeclarationStatement yDecl;
Node node = Expressions.block(xDecl = Expressions.declare(0, "x", Expressions.constant(10)), yDecl = Expressions.declare(0, "y", Expressions.constant(0)), Expressions.while_(Expressions.lessThan(xDecl.parameter, Expressions.constant(5)), Expressions.statement(Expressions.preIncrementAssign(yDecl.parameter))));
assertEquals("{\n" + " int x = 10;\n" + " int y = 0;\n" + " while (x < 5) {\n" + " ++y;\n" + " }\n" + "}\n", Expressions.toString(node));
}
use of org.apache.calcite.linq4j.tree.DeclarationStatement in project calcite by apache.
the class InlinerTest method testInlineConstant.
@Test
public void testInlineConstant() {
DeclarationStatement decl = Expressions.declare(16, "x", ONE);
b.add(decl);
b.add(Expressions.return_(null, Expressions.add(decl.parameter, decl.parameter)));
assertEquals("{\n return 1 + 1;\n}\n", b.toBlock().toString());
}
use of org.apache.calcite.linq4j.tree.DeclarationStatement in project calcite by apache.
the class InlinerTest method testInlineSingleUsage.
@Test
public void testInlineSingleUsage() {
DeclarationStatement decl = Expressions.declare(16, "x", Expressions.add(ONE, TWO));
b.add(decl);
b.add(Expressions.return_(null, decl.parameter));
assertEquals("{\n return 1 + 2;\n}\n", b.toBlock().toString());
}
use of org.apache.calcite.linq4j.tree.DeclarationStatement in project calcite by apache.
the class InlinerTest method testInlineParameter.
@Test
public void testInlineParameter() {
ParameterExpression pe = Expressions.parameter(int.class, "p");
DeclarationStatement decl = Expressions.declare(16, "x", pe);
b.add(decl);
b.add(Expressions.return_(null, Expressions.add(decl.parameter, decl.parameter)));
assertEquals("{\n return p + p;\n}\n", b.toBlock().toString());
}
use of org.apache.calcite.linq4j.tree.DeclarationStatement in project calcite by apache.
the class EnumerableWindow method getPartitionIterator.
private Pair<Expression, Expression> getPartitionIterator(BlockBuilder builder, Expression source_, PhysType inputPhysType, Group group, Expression comparator_) {
//
if (group.keys.isEmpty()) {
// If partition key is empty, no need to partition.
//
// final List<Employee> tempList =
// source.into(new ArrayList<Employee>());
// Iterator<Employee[]> iterator =
// SortedMultiMap.singletonArrayIterator(comparator, tempList);
// final List<Xxx> list = new ArrayList<Xxx>(tempList.size());
final Expression tempList_ = builder.append("tempList", Expressions.convert_(Expressions.call(source_, BuiltInMethod.INTO.method, Expressions.new_(ArrayList.class)), List.class));
return Pair.of(tempList_, builder.append("iterator", Expressions.call(null, BuiltInMethod.SORTED_MULTI_MAP_SINGLETON.method, comparator_, tempList_)));
}
Expression multiMap_ = builder.append("multiMap", Expressions.new_(SortedMultiMap.class));
final BlockBuilder builder2 = new BlockBuilder();
final ParameterExpression v_ = Expressions.parameter(inputPhysType.getJavaRowType(), builder2.newName("v"));
Pair<Type, List<Expression>> selector = inputPhysType.selector(v_, group.keys.asList(), JavaRowFormat.CUSTOM);
final ParameterExpression key_;
if (selector.left instanceof Types.RecordType) {
Types.RecordType keyJavaType = (Types.RecordType) selector.left;
List<Expression> initExpressions = selector.right;
key_ = Expressions.parameter(keyJavaType, "key");
builder2.add(Expressions.declare(0, key_, null));
builder2.add(Expressions.statement(Expressions.assign(key_, Expressions.new_(keyJavaType))));
List<Types.RecordField> fieldList = keyJavaType.getRecordFields();
for (int i = 0; i < initExpressions.size(); i++) {
Expression right = initExpressions.get(i);
builder2.add(Expressions.statement(Expressions.assign(Expressions.field(key_, fieldList.get(i)), right)));
}
} else {
DeclarationStatement declare = Expressions.declare(0, "key", selector.right.get(0));
builder2.add(declare);
key_ = declare.parameter;
}
builder2.add(Expressions.statement(Expressions.call(multiMap_, BuiltInMethod.SORTED_MULTI_MAP_PUT_MULTI.method, key_, v_)));
builder2.add(Expressions.return_(null, Expressions.constant(null)));
builder.add(Expressions.statement(Expressions.call(source_, BuiltInMethod.ENUMERABLE_FOREACH.method, Expressions.lambda(builder2.toBlock(), v_))));
return Pair.of(multiMap_, builder.append("iterator", Expressions.call(multiMap_, BuiltInMethod.SORTED_MULTI_MAP_ARRAYS.method, comparator_)));
}
Aggregations