use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class GeodeToEnumerableConverter method implement.
/**
* {@inheritDoc}
*
* @param implementor GeodeImplementContext
*/
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
// travers all relations form this to the scan leaf
final GeodeImplementContext geodeImplementContext = new GeodeImplementContext();
((GeodeRel) getInput()).implement(geodeImplementContext);
// PhysType is Enumerable Adapter class that maps SQL types (getRowType)
// with physical Java types (getJavaTypes())
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType, pref.prefer(JavaRowFormat.ARRAY));
final List<Class> physFieldClasses = new AbstractList<Class>() {
public Class get(int index) {
return physType.fieldClass(index);
}
public int size() {
return rowType.getFieldCount();
}
};
// Expression meta-program for calling the GeodeTable.GeodeQueryable#query
// method form the generated code
final BlockBuilder blockBuilder = new BlockBuilder().append(Expressions.call(geodeImplementContext.table.getExpression(GeodeTable.GeodeQueryable.class), GEODE_QUERY_METHOD, constantArrayList(Pair.zip(geodeFieldNames(rowType), physFieldClasses), Pair.class), // physical fields
constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class), // selected fields
constantArrayList(toListMapPairs(geodeImplementContext.oqlAggregateFunctions), Pair.class), constantArrayList(geodeImplementContext.groupByFields, String.class), constantArrayList(geodeImplementContext.whereClause, String.class), constantArrayList(geodeImplementContext.orderByFields, String.class), Expressions.constant(geodeImplementContext.limitValue)));
Hook.QUERY_PLAN.run(geodeImplementContext);
return implementor.result(physType, blockBuilder.toBlock());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class SplunkTableScan method implement.
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
Map map = ImmutableMap.builder().put("search", search).put("earliest", Util.first(earliest, "")).put("latest", Util.first(latest, "")).put("fieldList", fieldList).build();
if (CalcitePrepareImpl.DEBUG) {
System.out.println("Splunk: " + map);
}
Hook.QUERY_PLAN.run(map);
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferCustom());
final BlockBuilder builder = new BlockBuilder();
return implementor.result(physType, builder.append(Expressions.call(table.getExpression(SplunkTable.SplunkTableQueryable.class), METHOD, Expressions.constant(search), Expressions.constant(earliest), Expressions.constant(latest), fieldList == null ? Expressions.constant(null) : constantStringList(fieldList))).toBlock());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class ExpressionTest method checkBlockBuilder.
public void checkBlockBuilder(boolean optimizing, String expected) {
BlockBuilder statements = new BlockBuilder(optimizing);
Expression one = statements.append("one", Expressions.constant(1));
Expression two = statements.append("two", Expressions.constant(2));
Expression three = statements.append("three", Expressions.add(one, two));
Expression six = statements.append("six", Expressions.multiply(three, two));
Expression nine = statements.append("nine", Expressions.multiply(three, three));
Expression eighteen = statements.append("eighteen", Expressions.add(Expressions.add(three, six), nine));
statements.add(Expressions.return_(null, eighteen));
BlockStatement expression = statements.toBlock();
assertEquals(expected, Expressions.toString(expression));
expression.accept(new Shuttle());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class ExpressionTest method testBlockBuilder3.
@Test
public void testBlockBuilder3() {
/*
int a = 1;
int b = a + 2;
int c = a + 3;
int d = a + 4;
int e = {
int b = a + 3;
foo(b);
}
bar(a, b, c, d, e);
*/
BlockBuilder builder0 = new BlockBuilder();
final Expression a = builder0.append("_a", Expressions.constant(1));
final Expression b = builder0.append("_b", Expressions.add(a, Expressions.constant(2)));
final Expression c = builder0.append("_c", Expressions.add(a, Expressions.constant(3)));
final Expression d = builder0.append("_d", Expressions.add(a, Expressions.constant(4)));
BlockBuilder builder1 = new BlockBuilder();
final Expression b1 = builder1.append("_b", Expressions.add(a, Expressions.constant(3)));
builder1.add(Expressions.statement(Expressions.call(ExpressionTest.class, "foo", b1)));
final Expression e = builder0.append("e", builder1.toBlock());
builder0.add(Expressions.statement(Expressions.call(ExpressionTest.class, "bar", a, b, c, d, e)));
// With the bug in BlockBuilder.append(String, BlockExpression),
// bar(1, _b, _c, _d, foo(_d));
// Correct result is
// bar(1, _b, _c, _d, foo(_c));
// because _c has the same expression (a + 3) as inner b.
BlockStatement expression = builder0.toBlock();
assertEquals("{\n" + " final int _b = 1 + 2;\n" + " final int _c = 1 + 3;\n" + " final int _d = 1 + 4;\n" + " org.apache.calcite.linq4j.test.ExpressionTest.bar(1, _b, _c, _d, org.apache.calcite.linq4j.test.ExpressionTest.foo(_c));\n" + "}\n", Expressions.toString(expression));
expression.accept(new Shuttle());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.BlockBuilder in project calcite by apache.
the class ExpressionTest method testFor.
@Test
public void testFor() throws NoSuchFieldException {
final BlockBuilder builder = new BlockBuilder();
final ParameterExpression i_ = Expressions.parameter(int.class, "i");
builder.add(Expressions.for_(Expressions.declare(0, i_, Expressions.constant(0)), Expressions.lessThan(i_, Expressions.constant(10)), Expressions.postIncrementAssign(i_), Expressions.block(Expressions.statement(Expressions.call(Expressions.field(null, System.class.getField("out")), "println", i_)))));
assertEquals("{\n" + " for (int i = 0; i < 10; i++) {\n" + " System.out.println(i);\n" + " }\n" + "}\n", Expressions.toString(builder.toBlock()));
}
Aggregations