Java Code Examples for org.apache.calcite.adapter.enumerable.EnumerableRelImplementor#result()

The following examples show how to use org.apache.calcite.adapter.enumerable.EnumerableRelImplementor#result() . 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: 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 3
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 4
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 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: 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 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: 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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
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 18
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 19
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());
}
 
Example 20
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;
    }