Java Code Examples for org.apache.calcite.adapter.enumerable.PhysTypeImpl#of()

The following examples show how to use org.apache.calcite.adapter.enumerable.PhysTypeImpl#of() . 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: EnumerableToSparkConverter.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Result implementSpark(Implementor implementor) {
  // Generate:
  //   Enumerable source = ...;
  //   return SparkRuntime.createRdd(sparkContext, source);
  final BlockBuilder list = new BlockBuilder();
  final EnumerableRel child = (EnumerableRel) getInput();
  final PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(), getRowType(),
          JavaRowFormat.CUSTOM);
  final Expression source = null; // TODO:
  final Expression sparkContext =
      Expressions.call(
          SparkMethod.GET_SPARK_CONTEXT.method,
          implementor.getRootExpression());
  final Expression rdd =
      list.append(
          "rdd",
          Expressions.call(
              SparkMethod.CREATE_RDD.method,
              sparkContext,
              source));
  list.add(
      Expressions.return_(null, rdd));
  return implementor.result(physType, list.toBlock());
}
 
Example 3
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 4
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 5
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 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: 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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
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 18
Source File: JdbcToSparkConverter.java    From calcite with Apache License 2.0 4 votes vote down vote up
public SparkRel.Result implementSpark(SparkRel.Implementor implementor) {
  // Generate:
  //   ResultSetEnumerable.of(schema.getDataSource(), "select ...")
  final BlockBuilder list = new BlockBuilder();
  final JdbcRel child = (JdbcRel) getInput();
  final PhysType physType =
      PhysTypeImpl.of(
          implementor.getTypeFactory(), getRowType(),
          JavaRowFormat.CUSTOM);
  final JdbcConvention jdbcConvention =
      (JdbcConvention) child.getConvention();
  String sql = generateSql(jdbcConvention.dialect);
  if (CalciteSystemProperty.DEBUG.value()) {
    System.out.println("[" + sql + "]");
  }
  final Expression sqlLiteral =
      list.append("sql", Expressions.constant(sql));
  final List<Primitive> primitives = new ArrayList<>();
  for (int i = 0; i < getRowType().getFieldCount(); i++) {
    final Primitive primitive = Primitive.ofBoxOr(physType.fieldClass(i));
    primitives.add(primitive != null ? primitive : Primitive.OTHER);
  }
  final Expression primitivesLiteral =
      list.append("primitives",
          Expressions.constant(
              primitives.toArray(new Primitive[0])));
  final Expression enumerable =
      list.append(
          "enumerable",
          Expressions.call(
              BuiltInMethod.RESULT_SET_ENUMERABLE_OF.method,
              Expressions.call(
                  Expressions.convert_(
                      jdbcConvention.expression,
                      JdbcSchema.class),
                  BuiltInMethod.JDBC_SCHEMA_DATA_SOURCE.method),
              sqlLiteral,
              primitivesLiteral));
  list.add(
      Expressions.return_(null, enumerable));
  return implementor.result(physType, list.toBlock());
}
 
Example 19
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 20
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());
}