private String toElasticsearchQuery(EnumerableRel root) { try { EnumerableRelImplementor relImplementor = new EnumerableRelImplementor(root.getCluster().getRexBuilder(), ImmutableMap.of()); final ElasticsearchRel.Implementor elasticsearchImplementor = new ElasticsearchRel.Implementor(); RelDataType rowType = root.getRowType(); final PhysType physType = PhysTypeImpl.of(relImplementor.getTypeFactory(), rowType, Prefer.ARRAY.prefer(JavaRowFormat.ARRAY)); List<Pair<String, Class>> pairs = Pair .zip(ElasticsearchRules.elasticsearchFieldNames(rowType), new AbstractList<Class>() { @Override public Class get(int index) { return physType.fieldClass(index); } @Override public int size() { return rowType.getFieldCount(); } }); return elasticsearchImplementor.convert(root.getInput(0), pairs); } catch (IOException ex) { throw new RuntimeException(ex); } finally { Prepare.CatalogReader.THREAD_LOCAL.remove(); } }
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 (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); } }
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 (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); } }