Java Code Examples for org.apache.calcite.util.Util#debugCode()
The following examples show how to use
org.apache.calcite.util.Util#debugCode() .
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: HiveEnumerableInterpretable.java From marble with Apache License 2.0 | 5 votes |
public static Bindable toBindable(Map<String, Object> parameters, CalcitePrepare.SparkHandler spark, EnumerableRel rel, EnumerableRel.Prefer prefer) { HiveEnumerableRelImplementor relImplementor = new HiveEnumerableRelImplementor(rel.getCluster().getRexBuilder(), parameters); final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer); String s = Expressions.toString(expr.memberDeclarations, "\n", false); if (CalcitePrepareImpl.DEBUG) { Util.debugCode(System.out, s); } Hook.JAVA_PLAN.run(s); try { if (spark != null && spark.enabled()) { return spark.compile(expr, s); } else { return getBindable(expr, s, rel.getRowType().getFieldCount()); } } catch (Exception e) { throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e); } }
Example 2
Source File: HiveRexExecutorImpl.java From marble with Apache License 2.0 | 5 votes |
private String compile(RexBuilder rexBuilder, List<RexNode> constExps, RexToLixTranslator.InputGetter getter, RelDataType rowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(rowType, rexBuilder); for (RexNode node : constExps) { programBuilder.addProject( node, "c" + programBuilder.getProjectList().size()); } final JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem()); final BlockBuilder blockBuilder = new BlockBuilder(); final ParameterExpression root0_ = Expressions.parameter(Object.class, "root0"); final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class))); final SqlConformance conformance = SqlConformanceEnum.HIVE; final RexProgram program = programBuilder.getProgram(); final List<Expression> expressions = RexToLixTranslator.translateProjects(program, javaTypeFactory, conformance, blockBuilder, null, root_, getter, null); blockBuilder.add( Expressions.return_(null, Expressions.newArrayInit(Object[].class, expressions))); final MethodDeclaration methodDecl = Expressions.methodDecl(Modifier.PUBLIC, Object[].class, BuiltInMethod.FUNCTION1_APPLY.method.getName(), ImmutableList.of(root0_), blockBuilder.toBlock()); String code = Expressions.toString(methodDecl); if (CalcitePrepareImpl.DEBUG) { Util.debugCode(System.out, code); } return code; }
Example 3
Source File: SparkHandlerImpl.java From calcite with Apache License 2.0 | 5 votes |
public ArrayBindable compile(ClassDeclaration expr, String s) { final String className = "CalciteProgram" + classId.getAndIncrement(); final String classFileName = className + ".java"; String source = "public class " + className + "\n" + " implements " + ArrayBindable.class.getName() + ", " + Serializable.class.getName() + " {\n" + s + "\n" + "}\n"; if (CalciteSystemProperty.DEBUG.value()) { Util.debugCode(System.out, source); } JaninoCompiler compiler = new JaninoCompiler(); compiler.getArgs().setDestdir(CLASS_DIR.getAbsolutePath()); compiler.getArgs().setSource(source, classFileName); compiler.getArgs().setFullClassName(className); compiler.compile(); try { @SuppressWarnings("unchecked") final Class<ArrayBindable> clazz = (Class<ArrayBindable>) compiler.getClassLoader().loadClass(className); final Constructor<ArrayBindable> constructor = clazz.getConstructor(); return constructor.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new RuntimeException(e); } }
Example 4
Source File: EnumerableInterpretable.java From calcite with Apache License 2.0 | 5 votes |
public static Bindable toBindable(Map<String, Object> parameters, CalcitePrepare.SparkHandler spark, EnumerableRel rel, EnumerableRel.Prefer prefer) { EnumerableRelImplementor relImplementor = new EnumerableRelImplementor(rel.getCluster().getRexBuilder(), parameters); final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer); String s = Expressions.toString(expr.memberDeclarations, "\n", false); if (CalciteSystemProperty.DEBUG.value()) { Util.debugCode(System.out, s); } Hook.JAVA_PLAN.run(s); try { if (spark != null && spark.enabled()) { return spark.compile(expr, s); } else { return getBindable(expr, s, rel.getRowType().getFieldCount()); } } catch (Exception e) { throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e); } }
Example 5
Source File: RexExecutorImpl.java From calcite with Apache License 2.0 | 5 votes |
private static String compile(RexBuilder rexBuilder, List<RexNode> constExps, RexToLixTranslator.InputGetter getter, RelDataType rowType) { final RexProgramBuilder programBuilder = new RexProgramBuilder(rowType, rexBuilder); for (RexNode node : constExps) { programBuilder.addProject( node, "c" + programBuilder.getProjectList().size()); } final JavaTypeFactoryImpl javaTypeFactory = new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem()); final BlockBuilder blockBuilder = new BlockBuilder(); final ParameterExpression root0_ = Expressions.parameter(Object.class, "root0"); final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class))); final SqlConformance conformance = SqlConformanceEnum.DEFAULT; final RexProgram program = programBuilder.getProgram(); final List<Expression> expressions = RexToLixTranslator.translateProjects(program, javaTypeFactory, conformance, blockBuilder, null, root_, getter, null); blockBuilder.add( Expressions.return_(null, Expressions.newArrayInit(Object[].class, expressions))); final MethodDeclaration methodDecl = Expressions.methodDecl(Modifier.PUBLIC, Object[].class, BuiltInMethod.FUNCTION1_APPLY.method.getName(), ImmutableList.of(root0_), blockBuilder.toBlock()); String code = Expressions.toString(methodDecl); if (CalciteSystemProperty.DEBUG.value()) { Util.debugCode(System.out, code); } return code; }
Example 6
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); } }