org.apache.calcite.adapter.enumerable.EnumerableRelImplementor Java Examples

The following examples show how to use org.apache.calcite.adapter.enumerable.EnumerableRelImplementor. 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: GremlinTraversalToEnumerableRelConverter.java    From sql-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
    public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
        final BlockBuilder list = new BlockBuilder();
        final GremlinTraversalRel.Implementor gremlinImplementor =
                new GremlinTraversalRel.Implementor();
        gremlinImplementor.visitChild(0, getInput());

        PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(),
                getRowType(), pref.preferArray());

        return implementor.result(
                physType,
                Blocks.toBlock(
                        Expressions.call(GremlinTraversalScan.class,
                                "scan")));
//        return null;
    }
 
Example #2
Source File: CsvTableScan.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(),
          getRowType(),
          pref.preferArray());

  if (table instanceof JsonTable) {
    return implementor.result(
        physType,
        Blocks.toBlock(
            Expressions.call(table.getExpression(JsonTable.class),
                "enumerable")));
  }
  return implementor.result(
      physType,
      Blocks.toBlock(
          Expressions.call(table.getExpression(CsvTranslatableTable.class),
              "project", implementor.getRootExpression(),
              Expressions.constant(fields))));
}
 
Example #3
Source File: SparkToEnumerableConverter.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  // Generate:
  //   RDD rdd = ...;
  //   return SparkRuntime.asEnumerable(rdd);
  final BlockBuilder list = new BlockBuilder();
  final SparkRel child = (SparkRel) getInput();
  final PhysType physType =
      PhysTypeImpl.of(implementor.getTypeFactory(),
          getRowType(),
          JavaRowFormat.CUSTOM);
  SparkRel.Implementor sparkImplementor =
      new SparkImplementorImpl(implementor);
  final SparkRel.Result result = child.implementSpark(sparkImplementor);
  final Expression rdd = list.append("rdd", result.block);
  final Expression enumerable =
      list.append(
          "enumerable",
          Expressions.call(
              SparkMethod.AS_ENUMERABLE.method,
              rdd));
  list.add(
      Expressions.return_(null, enumerable));
  return implementor.result(physType, list.toBlock());
}
 
Example #4
Source File: PigToEnumerableConverter.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>This implementation does not actually execute the associated Pig Latin
 * script and return results. Instead it returns an empty
 * {@link org.apache.calcite.adapter.enumerable.EnumerableRel.Result}
 * in order to allow for testing and verification of every step of query
 * processing up to actual physical execution and result verification.
 *
 * <p>Next step is to invoke Pig from here, likely in local mode, have it
 * store results in a predefined file so they can be read here and returned as
 * a {@code Result} object.
 */
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  final BlockBuilder list = new BlockBuilder();
  final PhysType physType =
      PhysTypeImpl.of(implementor.getTypeFactory(), rowType,
          pref.prefer(JavaRowFormat.ARRAY));
  PigRel.Implementor impl = new PigRel.Implementor();
  impl.visitChild(0, getInput());
  Hook.QUERY_PLAN.run(impl.getScript()); // for script validation in tests
  list.add(
      Expressions.return_(null,
          Expressions.call(
              BuiltInMethod.EMPTY_ENUMERABLE.method)));
  return implementor.result(physType, list.toBlock());
}
 
Example #5
Source File: ProcessorStatusTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(ProcessorStatusTable.class), "project", Expressions.constant(fields))));
}
 
Example #6
Source File: BulletinTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(BulletinTable.class), "project", Expressions.constant(fields))));
}
 
Example #7
Source File: ProcessGroupStatusTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(ProcessGroupStatusTable.class), "project", Expressions.constant(fields))));
}
 
Example #8
Source File: JvmMetricsTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(JvmMetricsTable.class), "project", Expressions.constant(fields))));
}
 
Example #9
Source File: ConnectionStatusTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(ConnectionStatusTable.class), "project", Expressions.constant(fields))));
}
 
Example #10
Source File: ConnectionStatusPredictionsTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(ConnectionStatusPredictionsTable.class), "project", Expressions.constant(fields))));
}
 
Example #11
Source File: ProvenanceTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(ProvenanceTable.class), "project", Expressions.constant(fields))));
}
 
Example #12
Source File: FlowFileTableScan.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());

    return implementor.result(physType, Blocks.toBlock(
        Expressions.call(table.getExpression(FlowFileTable.class), "project", Expressions.constant(fields))));
}
 
Example #13
Source File: JdbcToEnumerableConverter.java    From calcite with Apache License 2.0 5 votes vote down vote up
private UnaryExpression getTimeZoneExpression(
    EnumerableRelImplementor implementor) {
  return Expressions.convert_(
      Expressions.call(
          implementor.getRootExpression(),
          "get",
          Expressions.constant("timeZone")),
      TimeZone.class);
}
 
Example #14
Source File: FileTableScan.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(),
          getRowType(),
          pref.preferArray());

  return implementor.result(
      physType,
      Blocks.toBlock(
          Expressions.call(table.getExpression(FileTable.class), "project",
              Expressions.constant(fields))));
}
 
Example #15
Source File: KylinEnumerableUnion.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    Expression unionExp = null;
    for (Ord<RelNode> ord : Ord.zip(inputs)) {
        EnumerableRel input = (EnumerableRel) ord.e;
        final Result result = implementor.visitChild(this, ord.i, input, pref);
        Expression childExp =
                builder.append(
                        "child" + ord.i,
                        result.block);

        if (unionExp == null) {
            unionExp = childExp;
        } else {
            unionExp = createUnionExpression(unionExp, childExp, result.format == JavaRowFormat.ARRAY);
        }
    }

    builder.add(unionExp);
    final PhysType physType =
            PhysTypeImpl.of(
                    implementor.getTypeFactory(),
                    getRowType(),
                    pref.prefer(JavaRowFormat.CUSTOM));
    return implementor.result(physType, builder.toBlock());
}
 
Example #16
Source File: OLAPJoinRel.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

    context.setReturnTupleInfo(rowType, columnRowType);

    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());
    RelOptTable factTable = context.firstTableScan.getTable();
    MethodCallExpression exprCall = Expressions.call(factTable.getExpression(OLAPTable.class), "executeOLAPQuery",
            implementor.getRootExpression(), Expressions.constant(context.id));
    return implementor.result(physType, Blocks.toBlock(exprCall));
}
 
Example #17
Source File: OLAPTableScan.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

    context.setReturnTupleInfo(rowType, columnRowType);
    String execFunction = genExecFunc();

    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.ARRAY);
    MethodCallExpression exprCall = Expressions.call(table.getExpression(OLAPTable.class), execFunction,
            implementor.getRootExpression(), Expressions.constant(context.id));
    return implementor.result(physType, Blocks.toBlock(exprCall));
}
 
Example #18
Source File: OLAPTableScan.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

    context.setReturnTupleInfo(rowType, columnRowType);
    String execFunction = genExecFunc();

    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), JavaRowFormat.ARRAY);
    MethodCallExpression exprCall = Expressions.call(table.getExpression(OLAPTable.class), execFunction,
            implementor.getRootExpression(), Expressions.constant(context.id));
    return implementor.result(physType, Blocks.toBlock(exprCall));
}
 
Example #19
Source File: QuarkTableScan.java    From quark with Apache License 2.0 5 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(),
          getRowType(),
          pref.preferArray());

  return implementor.result(
      physType,
      Blocks.toBlock(
          Expressions.call(table.getExpression(QuarkTable.class),
              "project",
              Expressions.constant(QuarkEnumerator.identityList(
                  getRowType().getFieldCount())))));
}
 
Example #20
Source File: QuarkTileScan.java    From quark with Apache License 2.0 5 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(),
          getRowType(),
          pref.preferArray());

  return implementor.result(
      physType,
      Blocks.toBlock(
          Expressions.call(table.getExpression(QuarkTileTable.class),
              "project", Expressions.constant(
                  QuarkEnumerator.identityList(getRowType().getFieldCount())))));
}
 
Example #21
Source File: KylinEnumerableUnion.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    Expression unionExp = null;
    for (Ord<RelNode> ord : Ord.zip(inputs)) {
        EnumerableRel input = (EnumerableRel) ord.e;
        final Result result = implementor.visitChild(this, ord.i, input, pref);
        Expression childExp =
                builder.append(
                        "child" + ord.i,
                        result.block);

        if (unionExp == null) {
            unionExp = childExp;
        } else {
            unionExp = createUnionExpression(unionExp, childExp, result.format == JavaRowFormat.ARRAY);
        }
    }

    builder.add(unionExp);
    final PhysType physType =
            PhysTypeImpl.of(
                    implementor.getTypeFactory(),
                    getRowType(),
                    pref.prefer(JavaRowFormat.CUSTOM));
    return implementor.result(physType, builder.toBlock());
}
 
Example #22
Source File: OLAPJoinRel.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

    context.setReturnTupleInfo(rowType, columnRowType);

    PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());
    RelOptTable factTable = context.firstTableScan.getTable();
    MethodCallExpression exprCall = Expressions.call(factTable.getExpression(OLAPTable.class), "executeOLAPQuery",
            implementor.getRootExpression(), Expressions.constant(context.id));
    return implementor.result(physType, Blocks.toBlock(exprCall));
}
 
Example #23
Source File: VolcanoPlannerTraitTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public Result implement(EnumerableRelImplementor implementor,
    Prefer pref) {
  return null;
}
 
Example #24
Source File: OLAPRel.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public JavaImplementor(EnumerableRelImplementor enumImplementor) {
    super(enumImplementor.getRexBuilder(), new LinkedHashMap<String, Object>());
}
 
Example #25
Source File: ElasticsearchToEnumerableConverter.java    From dk-fitting with Apache License 2.0 4 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
        final ElasticsearchRelNode.Implementor esImplementor = new ElasticsearchRelNode.Implementor();
        esImplementor.visitChild(0, getInput());
        List<String> listField = esImplementor.getListField();
        List<String> listField2 = new ArrayList<String>();
        for (String field : listField){                            //数据处理函数expr$0 转为lower.fieldName
                listField2.add(field);
        }
        ElasticsearchTable esTable = esImplementor.elasticsearchTable;

        final RelDataType rowType2 = esImplementor.elasticsearchTable.getRowType2();
        final List<String> fieldNames1  = rowType2.getFieldNames();          //得到输出顺序
        PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType2,
                pref.prefer(JavaRowFormat.ARRAY));



        final RelDataType rowType = esImplementor.elasticsearchTable.getRowType();
        PhysType physType2 = PhysTypeImpl.of(implementor.getTypeFactory(), rowType,
                pref.prefer(JavaRowFormat.ARRAY));
//        esTable.setOutNames(fieldNames1);
        List<String> fieldNames = ElasticsearchRules.elasticsearchFieldNames(rowType2);
        List<ElasticSearchFieldType> typeList = new ArrayList<ElasticSearchFieldType>();
        for(int i = 0 ; i < fieldNames.size(); i++){

            Class type = physType.fieldClass(i);
            String typeName = type.toString().substring(type.toString().lastIndexOf(".") + 1).toLowerCase();
            if("integer".equals(typeName)){
                typeName = "int";
            }
            typeList.add(ElasticSearchFieldType.of(typeName));
        }
        boolean oneColumFlag = false;
        if(typeList.size() == 1){
            oneColumFlag = true;
        }
        TwoTuple<List<Object>, List<Object[]>> listTwoTuple = esTable.find(typeList,listField,oneColumFlag);
//        List<Object[]> resultList = esTable.find(typeList, oneColumFlag);
        ConstantExpression constant = oneColumFlag ? Expressions.constant(listTwoTuple.first.toArray()) : Expressions.constant(listTwoTuple.second.toArray());
        Result result = implementor.result(physType2,
                Blocks.toBlock(Expressions.call(BuiltInMethod.AS_ENUMERABLE2.method, constant)));
        return result;
    }
 
Example #26
Source File: GeodeToEnumerableConverter.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @param implementor GeodeImplementContext
 */
@Override public Result implement(EnumerableRelImplementor implementor, Prefer pref) {

  // travers all relations form this to the scan leaf
  final GeodeImplementContext geodeImplementContext = new GeodeImplementContext();
  ((GeodeRel) getInput()).implement(geodeImplementContext);

  final RelDataType rowType = getRowType();

  // PhysType is Enumerable Adapter class that maps SQL types (getRowType)
  // with physical Java types (getJavaTypes())
  final PhysType physType = PhysTypeImpl.of(
      implementor.getTypeFactory(),
      rowType,
      pref.prefer(JavaRowFormat.ARRAY));

  final List<Class> physFieldClasses = new AbstractList<Class>() {
    public Class get(int index) {
      return physType.fieldClass(index);
    }

    public int size() {
      return rowType.getFieldCount();
    }
  };

  // Expression meta-program for calling the GeodeTable.GeodeQueryable#query
  // method form the generated code
  final BlockBuilder blockBuilder = new BlockBuilder().append(
      Expressions.call(
          geodeImplementContext.table.getExpression(GeodeTable.GeodeQueryable.class),
          GEODE_QUERY_METHOD,
          // fields
          constantArrayList(Pair.zip(geodeFieldNames(rowType), physFieldClasses), Pair.class),
          // selected fields
          constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class),
          // aggregate functions
          constantArrayList(
              toListMapPairs(geodeImplementContext.oqlAggregateFunctions), Pair.class),
          constantArrayList(geodeImplementContext.groupByFields, String.class),
          constantArrayList(geodeImplementContext.whereClause, String.class),
          constantArrayList(geodeImplementContext.orderByFields, String.class),
          Expressions.constant(geodeImplementContext.limitValue)));

  return implementor.result(physType, blockBuilder.toBlock());
}
 
Example #27
Source File: VolcanoPlannerTraitTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public Result implement(EnumerableRelImplementor implementor,
    Prefer pref) {
  return null;
}
 
Example #28
Source File: JdbcToEnumerableConverter.java    From calcite with Apache License 2.0 4 votes vote down vote up
private void generateGet(EnumerableRelImplementor implementor,
    PhysType physType, BlockBuilder builder, ParameterExpression resultSet_,
    int i, Expression target, Expression calendar_,
    SqlDialect.CalendarPolicy calendarPolicy) {
  final Primitive primitive = Primitive.ofBoxOr(physType.fieldClass(i));
  final RelDataType fieldType =
      physType.getRowType().getFieldList().get(i).getType();
  final List<Expression> dateTimeArgs = new ArrayList<>();
  dateTimeArgs.add(Expressions.constant(i + 1));
  SqlTypeName sqlTypeName = fieldType.getSqlTypeName();
  boolean offset = false;
  switch (calendarPolicy) {
  case LOCAL:
    dateTimeArgs.add(calendar_);
    break;
  case NULL:
    // We don't specify a calendar at all, so we don't add an argument and
    // instead use the version of the getXXX that doesn't take a Calendar
    break;
  case DIRECT:
    sqlTypeName = SqlTypeName.ANY;
    break;
  case SHIFT:
    switch (sqlTypeName) {
    case TIMESTAMP:
    case DATE:
      offset = true;
    }
    break;
  }
  final Expression source;
  switch (sqlTypeName) {
  case DATE:
  case TIME:
  case TIMESTAMP:
    source = Expressions.call(
        getMethod(sqlTypeName, fieldType.isNullable(), offset),
        Expressions.<Expression>list()
            .append(
                Expressions.call(resultSet_,
                    getMethod2(sqlTypeName), dateTimeArgs))
        .appendIf(offset, getTimeZoneExpression(implementor)));
    break;
  case ARRAY:
    final Expression x = Expressions.convert_(
        Expressions.call(resultSet_, jdbcGetMethod(primitive),
            Expressions.constant(i + 1)),
        java.sql.Array.class);
    source = Expressions.call(BuiltInMethod.JDBC_ARRAY_TO_LIST.method, x);
    break;
  default:
    source = Expressions.call(
        resultSet_, jdbcGetMethod(primitive), Expressions.constant(i + 1));
  }
  builder.add(
      Expressions.statement(
          Expressions.assign(
              target, source)));

  // [CALCITE-596] If primitive type columns contain null value, returns null
  // object
  if (primitive != null) {
    builder.add(
        Expressions.ifThen(
            Expressions.call(resultSet_, "wasNull"),
            Expressions.statement(
                Expressions.assign(target,
                    Expressions.constant(null)))));
  }
}
 
Example #29
Source File: MongoToEnumerableConverter.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
  // Generates a call to "find" or "aggregate", depending upon whether
  // an aggregate is present.
  //
  //   ((MongoTable) schema.getTable("zips")).find(
  //     "{state: 'CA'}",
  //     "{city: 1, zipcode: 1}")
  //
  //   ((MongoTable) schema.getTable("zips")).aggregate(
  //     "{$filter: {state: 'CA'}}",
  //     "{$group: {_id: '$city', c: {$sum: 1}, p: {$sum: "$pop"}}")
  final BlockBuilder list = new BlockBuilder();
  final MongoRel.Implementor mongoImplementor = new MongoRel.Implementor();
  mongoImplementor.visitChild(0, getInput());
  int aggCount = 0;
  int findCount = 0;
  String project = null;
  String filter = null;
  for (Pair<String, String> op : mongoImplementor.list) {
    if (op.left == null) {
      ++aggCount;
    }
    if (op.right.startsWith("{$match:")) {
      filter = op.left;
      ++findCount;
    }
    if (op.right.startsWith("{$project:")) {
      project = op.left;
      ++findCount;
    }
  }
  final RelDataType rowType = getRowType();
  final PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(), rowType,
          pref.prefer(JavaRowFormat.ARRAY));
  final Expression fields =
      list.append("fields",
          constantArrayList(
              Pair.zip(MongoRules.mongoFieldNames(rowType),
                  new AbstractList<Class>() {
                    @Override public Class get(int index) {
                      return physType.fieldClass(index);
                    }

                    @Override public int size() {
                      return rowType.getFieldCount();
                    }
                  }),
              Pair.class));
  final Expression table =
      list.append("table",
          mongoImplementor.table.getExpression(
              MongoTable.MongoQueryable.class));
  List<String> opList = Pair.right(mongoImplementor.list);
  final Expression ops =
      list.append("ops",
          constantArrayList(opList, String.class));
  Expression enumerable =
      list.append("enumerable",
          Expressions.call(table,
              MongoMethod.MONGO_QUERYABLE_AGGREGATE.method, fields, ops));
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println("Mongo: " + opList);
  }
  Hook.QUERY_PLAN.run(opList);
  list.add(
      Expressions.return_(null, enumerable));
  return implementor.result(physType, list.toBlock());
}
 
Example #30
Source File: ElasticsearchToEnumerableConverter.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public Result implement(EnumerableRelImplementor relImplementor, Prefer prefer) {
  final BlockBuilder block = new BlockBuilder();
  final ElasticsearchRel.Implementor implementor = new ElasticsearchRel.Implementor();
  implementor.visitChild(0, getInput());

  final RelDataType rowType = getRowType();
  final PhysType physType = PhysTypeImpl.of(relImplementor.getTypeFactory(), rowType,
      prefer.prefer(JavaRowFormat.ARRAY));
  final Expression fields = block.append("fields",
      constantArrayList(
          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();
                }
              }),
          Pair.class));
  final Expression table = block.append("table",
      implementor.table
          .getExpression(ElasticsearchTable.ElasticsearchQueryable.class));
  final Expression ops = block.append("ops", Expressions.constant(implementor.list));
  final Expression sort = block.append("sort", constantArrayList(implementor.sort, Pair.class));
  final Expression groupBy = block.append("groupBy", Expressions.constant(implementor.groupBy));
  final Expression aggregations = block.append("aggregations",
      constantArrayList(implementor.aggregations, Pair.class));

  final Expression mappings = block.append("mappings",
      Expressions.constant(implementor.expressionItemMap));

  final Expression offset = block.append("offset", Expressions.constant(implementor.offset));
  final Expression fetch = block.append("fetch", Expressions.constant(implementor.fetch));

  Expression enumerable = block.append("enumerable",
      Expressions.call(table, ElasticsearchMethod.ELASTICSEARCH_QUERYABLE_FIND.method, ops,
          fields, sort, groupBy, aggregations, mappings, offset, fetch));
  block.add(Expressions.return_(null, enumerable));
  return relImplementor.result(physType, block.toBlock());
}