org.apache.calcite.linq4j.EnumerableQueryable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of calcite-linq4j Show documentation
Show all versions of calcite-linq4j Show documentation
Calcite APIs for LINQ (Language-Integrated Query) in Java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.calcite.linq4j;
import org.apache.calcite.linq4j.function.BigDecimalFunction1;
import org.apache.calcite.linq4j.function.DoubleFunction1;
import org.apache.calcite.linq4j.function.EqualityComparer;
import org.apache.calcite.linq4j.function.FloatFunction1;
import org.apache.calcite.linq4j.function.Function1;
import org.apache.calcite.linq4j.function.Function2;
import org.apache.calcite.linq4j.function.IntegerFunction1;
import org.apache.calcite.linq4j.function.LongFunction1;
import org.apache.calcite.linq4j.function.NullableBigDecimalFunction1;
import org.apache.calcite.linq4j.function.NullableDoubleFunction1;
import org.apache.calcite.linq4j.function.NullableFloatFunction1;
import org.apache.calcite.linq4j.function.NullableIntegerFunction1;
import org.apache.calcite.linq4j.function.NullableLongFunction1;
import org.apache.calcite.linq4j.function.Predicate1;
import org.apache.calcite.linq4j.function.Predicate2;
import org.apache.calcite.linq4j.tree.Expression;
import org.apache.calcite.linq4j.tree.FunctionExpression;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.Iterator;
/**
* Implementation of {@link Queryable} by a {@link Enumerable}.
*
* @param Element type
*/
class EnumerableQueryable extends DefaultEnumerable
implements Queryable {
private final QueryProvider provider;
private final Class elementType;
private final Enumerable enumerable;
private final @Nullable Expression expression;
EnumerableQueryable(QueryProvider provider, Class elementType,
@Nullable Expression expression, Enumerable enumerable) {
this.enumerable = enumerable;
this.elementType = elementType;
this.provider = provider;
this.expression = expression;
}
@Override protected Enumerable getThis() {
return enumerable;
}
/**
* Returns the target queryable. Usually this.
*
* @return Target queryable
*/
protected Queryable queryable() {
return this;
}
@Override public Iterator iterator() {
return enumerable.iterator();
}
@Override public Enumerator enumerator() {
return enumerable.enumerator();
}
// Disambiguate
@Override public Queryable union(Enumerable source1) {
return EnumerableDefaults.union(getThis(), source1).asQueryable();
}
@Override public Queryable union(Enumerable source1,
EqualityComparer comparer) {
return EnumerableDefaults.union(getThis(), source1, comparer).asQueryable();
}
@Override public Queryable intersect(Enumerable source1) {
return intersect(source1, false);
}
@Override public Queryable intersect(Enumerable source1, boolean all) {
return EnumerableDefaults.intersect(getThis(), source1, all).asQueryable();
}
@Override public Queryable intersect(Enumerable source1,
EqualityComparer comparer) {
return intersect(source1, comparer, false);
}
@Override public Queryable intersect(Enumerable source1,
EqualityComparer comparer, boolean all) {
return EnumerableDefaults.intersect(getThis(), source1, comparer, all)
.asQueryable();
}
@Override public Queryable except(Enumerable enumerable1,
EqualityComparer comparer) {
return except(enumerable1, comparer, false);
}
@Override public Queryable except(Enumerable enumerable1,
EqualityComparer comparer, boolean all) {
return EnumerableDefaults.except(getThis(), enumerable1, comparer, all)
.asQueryable();
}
@Override public Queryable except(Enumerable enumerable1) {
return except(enumerable1, false);
}
@Override public Queryable except(Enumerable enumerable1, boolean all) {
return EnumerableDefaults.except(getThis(), enumerable1, all).asQueryable();
}
@Override public Queryable take(int count) {
return EnumerableDefaults.take(getThis(), count).asQueryable();
}
@Override public Queryable skip(int count) {
return EnumerableDefaults.skip(getThis(), count).asQueryable();
}
@Override public Queryable reverse() {
return EnumerableDefaults.reverse(getThis()).asQueryable();
}
@Override public Queryable distinct() {
return EnumerableDefaults.distinct(getThis()).asQueryable();
}
@Override public Queryable distinct(EqualityComparer comparer) {
return EnumerableDefaults.distinct(getThis(), comparer).asQueryable();
}
@Override public Queryable ofType(Class clazz) {
return EnumerableDefaults.ofType(getThis(), clazz).asQueryable();
}
@Override public Queryable<@Nullable T> defaultIfEmpty() {
return EnumerableDefaults.defaultIfEmpty(getThis()).asQueryable();
}
@Override public Queryable cast(Class clazz) {
return EnumerableDefaults.cast(getThis(), clazz).asQueryable();
}
// Queryable methods
@Override public Type getElementType() {
return elementType;
}
@Override public @Nullable Expression getExpression() {
return expression;
}
@Override public QueryProvider getProvider() {
return provider;
}
// .............
@Override public @Nullable T aggregate(
FunctionExpression> selector) {
return EnumerableDefaults.aggregate(getThis(), selector.getFunction());
}
@Override public TAccumulate aggregate(TAccumulate seed,
FunctionExpression> selector) {
return EnumerableDefaults.aggregate(getThis(), seed,
selector.getFunction());
}
@Override public TResult aggregate(TAccumulate seed,
FunctionExpression> func,
FunctionExpression> selector) {
return EnumerableDefaults.aggregate(getThis(), seed, func.getFunction(),
selector.getFunction());
}
@Override public boolean all(FunctionExpression> predicate) {
return EnumerableDefaults.all(getThis(), predicate.getFunction());
}
@Override public boolean any(FunctionExpression> predicate) {
return EnumerableDefaults.any(getThis(), predicate.getFunction());
}
@Override public BigDecimal averageBigDecimal(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public BigDecimal averageNullableBigDecimal(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public double averageDouble(FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public Double averageNullableDouble(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public int averageInteger(FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public Integer averageNullableInteger(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public float averageFloat(FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public Float averageNullableFloat(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public long averageLong(FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public Long averageNullableLong(
FunctionExpression> selector) {
return EnumerableDefaults.average(getThis(), selector.getFunction());
}
@Override public Queryable concat(Enumerable source2) {
return EnumerableDefaults.concat(getThis(), source2).asQueryable();
}
@Override public int count(FunctionExpression> predicate) {
return EnumerableDefaults.count(getThis(), predicate.getFunction());
}
@Override public T first(FunctionExpression> predicate) {
return EnumerableDefaults.first(getThis(), predicate.getFunction());
}
@Override public @Nullable T firstOrDefault(FunctionExpression> predicate) {
return EnumerableDefaults.firstOrDefault(getThis(),
predicate.getFunction());
}
@Override public Queryable> groupBy(
FunctionExpression> keySelector) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction())
.asQueryable();
}
@Override public Queryable> groupBy(
FunctionExpression> keySelector,
EqualityComparer comparer) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
comparer).asQueryable();
}
@Override public Queryable> groupBy(
FunctionExpression> keySelector,
FunctionExpression> elementSelector) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
elementSelector.getFunction()).asQueryable();
}
@Override public Queryable> groupBy(
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
EqualityComparer comparer) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
elementSelector.getFunction(), comparer).asQueryable();
}
@Override public Queryable groupByK(
FunctionExpression> keySelector,
FunctionExpression, TResult>> resultSelector) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
resultSelector.getFunction()).asQueryable();
}
@Override public Queryable groupByK(
FunctionExpression> keySelector,
FunctionExpression, TResult>> resultSelector,
EqualityComparer comparer) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
resultSelector.getFunction(), comparer).asQueryable();
}
@Override public Queryable groupBy(
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
FunctionExpression, TResult>> resultSelector) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
elementSelector.getFunction(), resultSelector.getFunction())
.asQueryable();
}
@Override public Queryable groupBy(
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
FunctionExpression, TResult>> resultSelector,
EqualityComparer comparer) {
return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
elementSelector.getFunction(), resultSelector.getFunction(), comparer)
.asQueryable();
}
@Override public Queryable groupJoin(
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression, TResult>> resultSelector) {
return EnumerableDefaults.groupJoin(getThis(), inner,
outerKeySelector.getFunction(), innerKeySelector.getFunction(),
resultSelector.getFunction()).asQueryable();
}
@Override public Queryable groupJoin(
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression, TResult>> resultSelector,
EqualityComparer comparer) {
return EnumerableDefaults.groupJoin(getThis(), inner,
outerKeySelector.getFunction(), innerKeySelector.getFunction(),
resultSelector.getFunction(), comparer).asQueryable();
}
@Override public Queryable join(
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression> resultSelector) {
return EnumerableDefaults.hashJoin(getThis(), inner,
outerKeySelector.getFunction(), innerKeySelector.getFunction(),
resultSelector.getFunction()).asQueryable();
}
@Override public Queryable join(
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression> resultSelector,
EqualityComparer comparer) {
return EnumerableDefaults.hashJoin(getThis(), inner,
outerKeySelector.getFunction(), innerKeySelector.getFunction(),
resultSelector.getFunction(), comparer).asQueryable();
}
@Override public T last(FunctionExpression> predicate) {
return EnumerableDefaults.last(getThis(), predicate.getFunction());
}
@Override public @Nullable T lastOrDefault(FunctionExpression> predicate) {
return EnumerableDefaults.lastOrDefault(getThis(), predicate.getFunction());
}
@Override public long longCount(FunctionExpression> predicate) {
return EnumerableDefaults.longCount(getThis(), predicate.getFunction());
}
@Override public > @Nullable TResult max(
FunctionExpression> selector) {
return EnumerableDefaults.max(getThis(), selector.getFunction());
}
@Override public > @Nullable TResult min(
FunctionExpression> selector) {
return EnumerableDefaults.min(getThis(), selector.getFunction());
}
@Override public OrderedQueryable orderBy(
FunctionExpression> keySelector) {
return EnumerableDefaults.asOrderedQueryable(
EnumerableDefaults.orderBy(getThis(), keySelector.getFunction()));
}
@Override public OrderedQueryable orderBy(
FunctionExpression> keySelector,
Comparator comparator) {
return EnumerableDefaults.asOrderedQueryable(
EnumerableDefaults.orderBy(getThis(), keySelector.getFunction(),
comparator));
}
@Override public OrderedQueryable orderByDescending(
FunctionExpression> keySelector) {
return EnumerableDefaults.asOrderedQueryable(
EnumerableDefaults.orderByDescending(getThis(),
keySelector.getFunction()));
}
@Override public OrderedQueryable orderByDescending(
FunctionExpression> keySelector,
Comparator comparator) {
return EnumerableDefaults.asOrderedQueryable(
EnumerableDefaults.orderByDescending(getThis(),
keySelector.getFunction(), comparator));
}
@Override public Queryable select(
FunctionExpression> selector) {
return EnumerableDefaults.select(getThis(), selector.getFunction())
.asQueryable();
}
@Override public Queryable selectN(
FunctionExpression> selector) {
return EnumerableDefaults.select(getThis(), selector.getFunction())
.asQueryable();
}
@Override public Queryable selectMany(
FunctionExpression>> selector) {
return EnumerableDefaults.selectMany(getThis(), selector.getFunction())
.asQueryable();
}
@Override public Queryable selectManyN(
FunctionExpression>> selector) {
return EnumerableDefaults.selectMany(getThis(), selector.getFunction())
.asQueryable();
}
@Override public Queryable selectMany(
FunctionExpression>>
collectionSelector,
FunctionExpression> resultSelector) {
return EnumerableDefaults.selectMany(getThis(),
collectionSelector.getFunction(), resultSelector.getFunction())
.asQueryable();
}
@Override public Queryable selectManyN(
FunctionExpression>>
collectionSelector,
FunctionExpression> resultSelector) {
return EnumerableDefaults.selectMany(getThis(),
collectionSelector.getFunction(), resultSelector.getFunction())
.asQueryable();
}
@Override public T single(FunctionExpression> predicate) {
return EnumerableDefaults.single(getThis(), predicate.getFunction());
}
@Override public @Nullable T singleOrDefault(FunctionExpression> predicate) {
return EnumerableDefaults.singleOrDefault(getThis(),
predicate.getFunction());
}
@Override public Queryable skipWhile(FunctionExpression> predicate) {
return EnumerableDefaults.skipWhile(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public Queryable skipWhileN(
FunctionExpression> predicate) {
return EnumerableDefaults.skipWhile(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public BigDecimal sumBigDecimal(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public BigDecimal sumNullableBigDecimal(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public double sumDouble(FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public Double sumNullableDouble(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public int sumInteger(FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public Integer sumNullableInteger(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public long sumLong(FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public Long sumNullableLong(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public float sumFloat(FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public Float sumNullableFloat(
FunctionExpression> selector) {
return EnumerableDefaults.sum(getThis(), selector.getFunction());
}
@Override public Queryable takeWhile(FunctionExpression> predicate) {
return EnumerableDefaults.takeWhile(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public Queryable takeWhileN(
FunctionExpression> predicate) {
return EnumerableDefaults.takeWhile(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public Queryable where(
FunctionExpression extends Predicate1> predicate) {
return EnumerableDefaults.where(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public Queryable whereN(
FunctionExpression extends Predicate2> predicate) {
return EnumerableDefaults.where(getThis(), predicate.getFunction())
.asQueryable();
}
@Override public Queryable zip(Enumerable source1,
FunctionExpression> resultSelector) {
return EnumerableDefaults.zip(getThis(), source1,
resultSelector.getFunction()).asQueryable();
}
@Override public @Nullable T aggregate(Function2<@Nullable T, T, T> func) {
return EnumerableDefaults.aggregate(getThis(), func);
}
@Override public TResult aggregate(TAccumulate seed,
Function2 func,
Function1 selector) {
return EnumerableDefaults.aggregate(getThis(), seed, func, selector);
}
}