Search in sources :

Example 1 with PhysicalSortProperty

use of io.ordinate.engine.builder.PhysicalSortProperty in project Mycat2 by MyCATApache.

the class HeapTopNPlan method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    Comparator<Record> recordComparator;
    if (physicalSortProperties.size() == 1) {
        recordComparator = physicalSortProperties.get(0).evaluateToSortComparator();
    } else {
        recordComparator = physicalSortProperties.get(0).evaluateToSortComparator();
        for (PhysicalSortProperty physicalSortProperty : physicalSortProperties.subList(1, physicalSortProperties.size())) {
            recordComparator = recordComparator.thenComparing(physicalSortProperty.evaluateToSortComparator());
        }
    }
    OutputLinq4jPhysicalPlan midPlan = OutputLinq4jPhysicalPlan.create(input);
    Observable<Object[]> observable = midPlan.executeToObject(rootContext);
    @NonNull Iterable<Record> objects = MycatRxJavaUtl.blockingIterable(observable.map(i -> RecordImpl.create(i)));
    Enumerable<Record> records = EnumerableDefaults.orderBy(Linq4j.asEnumerable(objects), i -> i, recordComparator, offset.getInt(null), fetch.getInt(null));
    return InputRecordPhysicalPlan.create(schema(), Observable.fromIterable(records)).execute(rootContext);
}
Also used : Schema(org.apache.arrow.vector.types.pojo.Schema) Linq4j(org.apache.calcite.linq4j.Linq4j) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) PhysicalSortProperty(io.ordinate.engine.builder.PhysicalSortProperty) Enumerable(org.apache.calcite.linq4j.Enumerable) MycatRxJavaUtl(io.mycat.MycatRxJavaUtl) NonNull(io.reactivex.rxjava3.annotations.NonNull) RootContext(io.ordinate.engine.record.RootContext) RecordImpl(io.ordinate.engine.record.RecordImpl) Record(io.ordinate.engine.record.Record) List(java.util.List) EnumerableDefaults(org.apache.calcite.linq4j.EnumerableDefaults) Observable(io.reactivex.rxjava3.core.Observable) IntFunction(io.ordinate.engine.function.IntFunction) Comparator(java.util.Comparator) Collections(java.util.Collections) PhysicalSortProperty(io.ordinate.engine.builder.PhysicalSortProperty) NonNull(io.reactivex.rxjava3.annotations.NonNull) Record(io.ordinate.engine.record.Record)

Aggregations

MycatRxJavaUtl (io.mycat.MycatRxJavaUtl)1 PhysicalSortProperty (io.ordinate.engine.builder.PhysicalSortProperty)1 IntFunction (io.ordinate.engine.function.IntFunction)1 Record (io.ordinate.engine.record.Record)1 RecordImpl (io.ordinate.engine.record.RecordImpl)1 RootContext (io.ordinate.engine.record.RootContext)1 NonNull (io.reactivex.rxjava3.annotations.NonNull)1 Observable (io.reactivex.rxjava3.core.Observable)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1 Enumerable (org.apache.calcite.linq4j.Enumerable)1 EnumerableDefaults (org.apache.calcite.linq4j.EnumerableDefaults)1 Linq4j (org.apache.calcite.linq4j.Linq4j)1