本文整理汇总了Java中org.apache.calcite.linq4j.tree.BlockStatement类的典型用法代码示例。如果您正苦于以下问题:Java BlockStatement类的具体用法?Java BlockStatement怎么用?Java BlockStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockStatement类属于org.apache.calcite.linq4j.tree包,在下文中一共展示了BlockStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finalizeExpression
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
private String finalizeExpression(BlockStatement blockStatement, RelDataType inputRowType)
{
String s = Expressions.toString(blockStatement.statements.get(0));
int idx = 0;
for (RelDataTypeField field : inputRowType.getFieldList()) {
String fieldName = OperatorUtils.getFieldName(field);
s = s.replaceAll(String.format("inputValues\\[%d\\]", idx++), "\\{\\$." + Matcher.quoteReplacement(fieldName) + "\\}");
}
return s.substring(0, s.length() - 2);
}
示例2: compileToBlock
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public BlockStatement compileToBlock(List<RexNode> nodes, RelDataType inputRowType) {
final RexProgramBuilder programBuilder =
new RexProgramBuilder(inputRowType, rexBuilder);
for (RexNode node : nodes) {
programBuilder.addProject(node, null);
}
return compileToBlock(programBuilder.getProgram());
}
示例3: baz
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
/** Given a method that implements {@link ExecutableExpression#execute(Context, Object[])},
* adds a bridge method that implements {@link ExecutableExpression#execute(Context)}, and
* compiles. */
static String baz(ParameterExpression context_,
ParameterExpression outputValues_, BlockStatement block, String className) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Context, Object[] outputValues)
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, void.class,
StreamlineBuiltInMethod.EXPR_EXECUTE2.method.getName(),
ImmutableList.of(context_, outputValues_), block));
// public Object execute(Context)
final BlockBuilder builder = new BlockBuilder();
final Expression values_ = builder.append("values",
Expressions.newArrayBounds(Object.class, 1,
Expressions.constant(1)));
builder.add(
Expressions.statement(
Expressions.call(
Expressions.parameter(ExecutableExpression.class, "this"),
StreamlineBuiltInMethod.EXPR_EXECUTE2.method, context_, values_)));
builder.add(
Expressions.return_(null,
Expressions.arrayIndex(values_, Expressions.constant(0))));
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, Object.class,
StreamlineBuiltInMethod.EXPR_EXECUTE1.method.getName(),
ImmutableList.of(context_), builder.toBlock()));
final ClassDeclaration classDeclaration =
Expressions.classDecl(Modifier.PUBLIC, className, null,
ImmutableList.<Type>of(ExecutableExpression.class), declarations);
return Expressions.toString(Lists.newArrayList(classDeclaration), "\n", false);
}
示例4: toRexList
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public List<RexNode> toRexList(BlockStatement statement) {
final List<Expression> simpleList = simpleList(statement);
final List<RexNode> list = new ArrayList<>();
for (Expression expression1 : simpleList) {
list.add(toRex(expression1));
}
return list;
}
示例5: simpleList
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
private static List<Expression> simpleList(BlockStatement statement) {
Expression simple = Blocks.simple(statement);
if (simple instanceof NewExpression) {
NewExpression newExpression = (NewExpression) simple;
return newExpression.arguments;
} else {
return Collections.singletonList(simple);
}
}
示例6: checkBlockBuilder
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的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());
}
示例7: testBlockBuilder2
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的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());
}
示例8: overridingMethodDecl
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
/** Declares a method that overrides another method. */
public static MethodDeclaration overridingMethodDecl(Method method,
Iterable<ParameterExpression> parameters,
BlockStatement body) {
return Expressions.methodDecl(
method.getModifiers() & ~Modifier.ABSTRACT,
method.getReturnType(),
method.getName(),
parameters,
body);
}
示例9: implementResult
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的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;
}
示例10: createSamzaExpressionFromCalcite
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
/**
* This method takes the java statement block, inputs, outputs needed by the statement block to create an object
* of class that implements the interface {@link Expression}
*
* for e.g.
* Query : select id from profile
* where profile table has relational schema with id(NUMBER) and name(VARCHAR) columns.
* This query will result in the following relational plan
* LogicalProject(id=[$1])
* LogicalTableScan(table=[[profile]])
*
*
* And the corresponding expressions are
* inputs : EnumerableTableScan (Which is the output of LogicalTableScan)
* nodes : [$1] Which essentially means take pick the first column from the input
*
* This expression corresponding to the logicalProject "[$1]" gets converted into a java statement block
* {
* outputValues[0] = (Integer) inputValues[1];
* }
*
* This method converts this statement block into an equivalent {@link Expression} object whose execute methods
* execute the above java statement block
*
*/
static org.apache.samza.sql.data.Expression createSamzaExpressionFromCalcite(ParameterExpression executionContext,
ParameterExpression dataContext, ParameterExpression inputValues, ParameterExpression outputValues,
BlockStatement block) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Object[] inputValues, Object[] outputValues)
declarations.add(
Expressions.methodDecl(Modifier.PUBLIC, void.class, SamzaBuiltInMethod.EXPR_EXECUTE2.method.getName(),
ImmutableList.of(executionContext, dataContext, inputValues, outputValues), block));
final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, "SqlExpression", null,
ImmutableList.<Type>of(org.apache.samza.sql.data.Expression.class), declarations);
String s = Expressions.toString(declarations, "\n", false);
log.info("Generated code for expression: {}", s);
try {
return getExpression(classDeclaration, s);
} catch (Exception e) {
throw new SamzaException("Expression compilation failure.", e);
}
}
示例11: toRex
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public RexNode toRex(BlockStatement statement) {
return toRex(Blocks.simple(statement));
}
示例12: result
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public SparkRel.Result result(PhysType physType,
BlockStatement blockStatement) {
return new SparkRel.Result(physType, blockStatement);
}
示例13: Result
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public Result(PhysType physType, BlockStatement block) {
this.physType = physType;
this.block = block;
}
示例14: testBlockBuilder3
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的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());
}
示例15: optimizeExpression
import org.apache.calcite.linq4j.tree.BlockStatement; //导入依赖的package包/类
public static BlockStatement optimizeExpression(Expression expr) {
return optimizeStatement(Expressions.return_(null, expr));
}