@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { if (getInput() instanceof OLAPFilterRel) { // merge project & filter OLAPFilterRel filter = (OLAPFilterRel) getInput(); RelNode inputOfFilter = inputs.get(0).getInput(0); RexProgram program = RexProgram.create(inputOfFilter.getRowType(), this.rewriteProjects, filter.getCondition(), this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // inputOfFilter, program); } else { // keep project for table scan EnumerableRel input = sole(inputs); RexProgram program = RexProgram.create(input.getRowType(), this.rewriteProjects, null, this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // input, program); } }
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(); } }
@Override public EnumerableRel implementEnumerable(List<EnumerableRel> inputs) { if (getInput() instanceof OLAPFilterRel) { // merge project & filter OLAPFilterRel filter = (OLAPFilterRel) getInput(); RelNode inputOfFilter = inputs.get(0).getInput(0); RexProgram program = RexProgram.create(inputOfFilter.getRowType(), this.rewriteProjects, filter.getCondition(), this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // inputOfFilter, program); } else { // keep project for table scan EnumerableRel input = sole(inputs); RexProgram program = RexProgram.create(input.getRowType(), this.rewriteProjects, null, this.rowType, getCluster().getRexBuilder()); return new EnumerableCalc(getCluster(), getCluster().traitSetOf(EnumerableConvention.INSTANCE), // input, program); } }