Search in sources :

Example 1 with GeodeImplementContext

use of org.apache.calcite.adapter.geode.rel.GeodeRel.GeodeImplementContext in project calcite by apache.

the class GeodeToEnumerableConverter method implement.

/**
 * {@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);
    // 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, constantArrayList(Pair.zip(geodeFieldNames(rowType), physFieldClasses), Pair.class), // physical fields
    constantArrayList(toListMapPairs(geodeImplementContext.selectFields), Pair.class), // selected fields
    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)));
    Hook.QUERY_PLAN.run(geodeImplementContext);
    return implementor.result(physType, blockBuilder.toBlock());
}
Also used : AbstractList(java.util.AbstractList) PhysType(org.apache.calcite.adapter.enumerable.PhysType) GeodeImplementContext(org.apache.calcite.adapter.geode.rel.GeodeRel.GeodeImplementContext) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Aggregations

AbstractList (java.util.AbstractList)1 PhysType (org.apache.calcite.adapter.enumerable.PhysType)1 GeodeImplementContext (org.apache.calcite.adapter.geode.rel.GeodeRel.GeodeImplementContext)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1