Java Code Examples for org.apache.calcite.linq4j.tree.Expressions#classDecl()
The following examples show how to use
org.apache.calcite.linq4j.tree.Expressions#classDecl() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveEnumerableRelImplementor.java From marble with Apache License 2.0 | 5 votes |
@Override protected void addMemberDeclaration( List<MemberDeclaration> memberDeclarations) { ClassDeclaration classDeclaration = Expressions.classDecl( Modifier.PUBLIC | Modifier.STATIC, "HiveUDFInstanceHolder", null, ImmutableList.of(Serializable.class), new ArrayList<>()); classDeclaration.memberDeclarations.addAll( HiveUDFInstanceCollecterPerSqlQuery.get() .getStashedFieldsForHiveUDFInstanceHolder()); memberDeclarations.add(classDeclaration); }
Example 2
Source File: RexNodeToJavaCodeCompiler.java From streamline with Apache License 2.0 | 5 votes |
/** 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); }
Example 3
Source File: RexToJavaCompiler.java From samza with Apache License 2.0 | 4 votes |
/** * 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 context, 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, context, 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); } }
Example 4
Source File: JaninoRexCompiler.java From calcite with Apache License 2.0 | 4 votes |
/** Given a method that implements {@link Scalar#execute(Context, Object[])}, * adds a bridge method that implements {@link Scalar#execute(Context)}, and * compiles. */ static Scalar baz(ParameterExpression context_, ParameterExpression outputValues_, BlockStatement block) { final List<MemberDeclaration> declarations = new ArrayList<>(); // public void execute(Context, Object[] outputValues) declarations.add( Expressions.methodDecl(Modifier.PUBLIC, void.class, BuiltInMethod.SCALAR_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(Scalar.class, "this"), BuiltInMethod.SCALAR_EXECUTE2.method, context_, values_))); builder.add( Expressions.return_(null, Expressions.arrayIndex(values_, Expressions.constant(0)))); declarations.add( Expressions.methodDecl(Modifier.PUBLIC, Object.class, BuiltInMethod.SCALAR_EXECUTE1.method.getName(), ImmutableList.of(context_), builder.toBlock())); final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, "Buzz", null, ImmutableList.of(Scalar.class), declarations); String s = Expressions.toString(declarations, "\n", false); if (CalciteSystemProperty.DEBUG.value()) { Util.debugCode(System.out, s); } try { return getScalar(classDeclaration, s); } catch (CompileException | IOException e) { throw new RuntimeException(e); } }