本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockBuilder.toBlock方法的典型用法代码示例。如果您正苦于以下问题:Java BlockBuilder.toBlock方法的具体用法?Java BlockBuilder.toBlock怎么用?Java BlockBuilder.toBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.linq4j.tree.BlockBuilder
的用法示例。
在下文中一共展示了BlockBuilder.toBlock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkBlockBuilder
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
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());
}
示例2: testBlockBuilder2
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@Test public void testBlockBuilder2() {
BlockBuilder statements = new BlockBuilder();
Expression element =
statements.append(
"element", Expressions.constant(null));
Expression comparator =
statements.append(
"comparator", Expressions.constant(null, Comparator.class));
Expression treeSet =
statements.append(
"treeSet",
Expressions.new_(
TreeSet.class,
Arrays.asList(comparator)));
statements.add(
Expressions.return_(
null,
Expressions.call(
treeSet,
"add",
element)));
BlockStatement expression = statements.toBlock();
final String expected = "{\n"
+ " final java.util.TreeSet treeSet = new java.util.TreeSet(\n"
+ " (java.util.Comparator) null);\n"
+ " return treeSet.add(null);\n"
+ "}\n";
assertThat(Expressions.toString(expression), is(expected));
expression.accept(new Shuttle());
}
示例3: implementResult
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public final Expression implementResult(AggContext info,
final AggResultContext result) {
if (!needTrackEmptySet) {
return RexToLixTranslator.convert(
implementNotNullResult(info, result), info.returnType());
}
String tmpName = result.accumulator().isEmpty()
? "ar"
: (result.accumulator().get(0) + "$Res");
ParameterExpression res = Expressions.parameter(0, info.returnType(),
result.currentBlock().newName(tmpName));
List<Expression> acc = result.accumulator();
final BlockBuilder thenBlock = result.nestBlock();
Expression nonNull = RexToLixTranslator.convert(
implementNotNullResult(info, result), info.returnType());
result.exitBlock();
thenBlock.add(Expressions.statement(Expressions.assign(res, nonNull)));
BlockStatement thenBranch = thenBlock.toBlock();
Expression seenNotNullRows =
trackNullsPerRow
? acc.get(acc.size() - 1)
: ((WinAggResultContext) result).hasRows();
if (thenBranch.statements.size() == 1) {
return Expressions.condition(seenNotNullRows,
nonNull, RexImpTable.getDefaultValue(res.getType()));
}
result.currentBlock().add(Expressions.declare(0, res, null));
result.currentBlock().add(
Expressions.ifThenElse(seenNotNullRows,
thenBranch,
Expressions.statement(
Expressions.assign(res,
RexImpTable.getDefaultValue(res.getType())))));
return res;
}
示例4: testBlockBuilder3
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
@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());
}
示例5: implementResult
import org.apache.calcite.linq4j.tree.BlockBuilder; //导入方法依赖的package包/类
public Expression implementResult(AggContext info,
AggResultContext result) {
WinAggResultContext winResult = (WinAggResultContext) result;
List<RexNode> rexArgs = winResult.rexArguments();
ParameterExpression res = Expressions.parameter(0, info.returnType(),
result.currentBlock().newName(isLead ? "lead" : "lag"));
Expression offset;
RexToLixTranslator currentRowTranslator =
winResult.rowTranslator(
winResult.computeIndex(Expressions.constant(0), SeekType.SET));
if (rexArgs.size() >= 2) {
// lead(x, offset) or lead(x, offset, default)
offset = currentRowTranslator.translate(
rexArgs.get(1), int.class);
} else {
offset = Expressions.constant(1);
}
if (!isLead) {
offset = Expressions.negate(offset);
}
Expression dstIndex = winResult.computeIndex(offset, SeekType.SET);
Expression rowInRange = winResult.rowInPartition(dstIndex);
BlockBuilder thenBlock = result.nestBlock();
Expression lagResult = winResult.rowTranslator(dstIndex).translate(
rexArgs.get(0), res.type);
thenBlock.add(Expressions.statement(Expressions.assign(res, lagResult)));
result.exitBlock();
BlockStatement thenBranch = thenBlock.toBlock();
Expression defaultValue = rexArgs.size() == 3
? currentRowTranslator.translate(rexArgs.get(2), res.type)
: getDefaultValue(res.type);
result.currentBlock().add(Expressions.declare(0, res, null));
result.currentBlock().add(
Expressions.ifThenElse(rowInRange, thenBranch,
Expressions.statement(Expressions.assign(res, defaultValue))));
return res;
}