Java Code Examples for org.codehaus.commons.compiler.IClassBodyEvaluator#setExtendedClass()
The following examples show how to use
org.codehaus.commons.compiler.IClassBodyEvaluator#setExtendedClass() .
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 | 6 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[]{Bindable.class, Typed.class} : new Class[]{ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalcitePrepareImpl.DEBUG) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } return (Bindable) cbe.createInstance(new StringReader(s)); }
Example 2
Source File: EnumerableInterpretable.java From Quicksql with MIT License | 5 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException, ExecutionException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } final IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[] {Bindable.class, Typed.class} : new Class[] {ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } if (CalciteSystemProperty.BINDABLE_CACHE_MAX_SIZE.value() != 0) { StaticFieldDetector detector = new StaticFieldDetector(); expr.accept(detector); if (!detector.containsStaticField) { return BINDABLE_CACHE.get(s, () -> (Bindable) cbe.createInstance(new StringReader(s))); } } return (Bindable) cbe.createInstance(new StringReader(s)); }
Example 3
Source File: EnumerableInterpretable.java From calcite with Apache License 2.0 | 5 votes |
static Bindable getBindable(ClassDeclaration expr, String s, int fieldCount) throws CompileException, IOException, ExecutionException { ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } final IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(expr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( fieldCount == 1 ? new Class[] {Bindable.class, Typed.class} : new Class[] {ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); if (CalciteSystemProperty.DEBUG.value()) { // Add line numbers to the generated janino class cbe.setDebuggingInformation(true, true, true); } if (CalciteSystemProperty.BINDABLE_CACHE_MAX_SIZE.value() != 0) { StaticFieldDetector detector = new StaticFieldDetector(); expr.accept(detector); if (!detector.containsStaticField) { return BINDABLE_CACHE.get(s, () -> (Bindable) cbe.createInstance(new StringReader(s))); } } return (Bindable) cbe.createInstance(new StringReader(s)); }
Example 4
Source File: CodeGenerationBenchmark.java From calcite with Apache License 2.0 | 4 votes |
@Setup(Level.Trial) public void setup() { planInfos = new PlanInfo[queries]; VolcanoPlanner planner = new VolcanoPlanner(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRule(FilterToCalcRule.INSTANCE); planner.addRule(ProjectToCalcRule.INSTANCE); planner.addRule(EnumerableRules.ENUMERABLE_CALC_RULE); planner.addRule(EnumerableRules.ENUMERABLE_JOIN_RULE); planner.addRule(EnumerableRules.ENUMERABLE_VALUES_RULE); RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(org.apache.calcite.rel.type.RelDataTypeSystem.DEFAULT); RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory)); RelTraitSet desiredTraits = cluster.traitSet().replace(EnumerableConvention.INSTANCE); RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(cluster, null); // Generates queries of the following form depending on the configuration parameters. // SELECT `t`.`name` // FROM (VALUES (1, 'Value0')) AS `t` (`id`, `name`) // INNER JOIN (VALUES (1, 'Value1')) AS `t` (`id`, `name`) AS `t0` ON `t`.`id` = `t0`.`id` // INNER JOIN (VALUES (2, 'Value2')) AS `t` (`id`, `name`) AS `t1` ON `t`.`id` = `t1`.`id` // INNER JOIN (VALUES (3, 'Value3')) AS `t` (`id`, `name`) AS `t2` ON `t`.`id` = `t2`.`id` // INNER JOIN ... // WHERE // `t`.`name` = 'name0' OR // `t`.`name` = 'name1' OR // `t`.`name` = 'name2' OR // ... // OR `t`.`id` = 0 // The last disjunction (i.e, t.id = $i) is what makes the queries different from one another // by assigning a different constant literal. for (int i = 0; i < queries; i++) { relBuilder.values(new String[]{"id", "name"}, 1, "Value" + 0); for (int j = 1; j <= joins; j++) { relBuilder .values(new String[]{"id", "name"}, j, "Value" + j) .join(JoinRelType.INNER, "id"); } List<RexNode> disjunctions = new ArrayList<>(); for (int j = 0; j < whereClauseDisjunctions; j++) { disjunctions.add( relBuilder.equals( relBuilder.field("name"), relBuilder.literal("name" + j))); } disjunctions.add( relBuilder.equals( relBuilder.field("id"), relBuilder.literal(i))); RelNode query = relBuilder .filter(relBuilder.or(disjunctions)) .project(relBuilder.field("name")) .build(); RelNode query0 = planner.changeTraits(query, desiredTraits); planner.setRoot(query0); PlanInfo info = new PlanInfo(); EnumerableRel plan = (EnumerableRel) planner.findBestExp(); EnumerableRelImplementor relImplementor = new EnumerableRelImplementor(plan.getCluster().getRexBuilder(), new HashMap<>()); info.classExpr = relImplementor.implementRoot(plan, EnumerableRel.Prefer.ARRAY); info.javaCode = Expressions.toString(info.classExpr.memberDeclarations, "\n", false); ICompilerFactory compilerFactory; try { compilerFactory = CompilerFactoryFactory.getDefaultCompilerFactory(); } catch (Exception e) { throw new IllegalStateException( "Unable to instantiate java compiler", e); } IClassBodyEvaluator cbe = compilerFactory.newClassBodyEvaluator(); cbe.setClassName(info.classExpr.name); cbe.setExtendedClass(Utilities.class); cbe.setImplementedInterfaces( plan.getRowType().getFieldCount() == 1 ? new Class[]{Bindable.class, Typed.class} : new Class[]{ArrayBindable.class}); cbe.setParentClassLoader(EnumerableInterpretable.class.getClassLoader()); info.cbe = cbe; planInfos[i] = info; } }