All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.calcite.linq4j.EnumerableQueryable Maven / Gradle / Ivy

/*
 * 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 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 Expression expression;

  EnumerableQueryable(QueryProvider provider, Class elementType,
      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;
  }

  public Iterator iterator() {
    return enumerable.iterator();
  }

  public Enumerator enumerator() {
    return enumerable.enumerator();
  }

  // Disambiguate

  public Queryable union(Enumerable source1) {
    return EnumerableDefaults.union(getThis(), source1).asQueryable();
  }

  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();
  }

  public Queryable take(int count) {
    return EnumerableDefaults.take(getThis(), count).asQueryable();
  }

  public Queryable skip(int count) {
    return EnumerableDefaults.skip(getThis(), count).asQueryable();
  }

  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 defaultIfEmpty() {
    return EnumerableDefaults.defaultIfEmpty(getThis()).asQueryable();
  }

  public  Queryable cast(Class clazz) {
    return EnumerableDefaults.cast(getThis(), clazz).asQueryable();
  }

  // Queryable methods

  public Type getElementType() {
    return elementType;
  }

  public Expression getExpression() {
    return expression;
  }

  public QueryProvider getProvider() {
    return provider;
  }

  // .............

  public T aggregate(FunctionExpression> selector) {
    return EnumerableDefaults.aggregate(getThis(), selector.getFunction());
  }

  public  TAccumulate aggregate(TAccumulate seed,
      FunctionExpression> selector) {
    return EnumerableDefaults.aggregate(getThis(), seed,
        selector.getFunction());
  }

  public  TResult aggregate(TAccumulate seed,
      FunctionExpression> func,
      FunctionExpression> selector) {
    return EnumerableDefaults.aggregate(getThis(), seed, func.getFunction(),
        selector.getFunction());
  }

  public boolean all(FunctionExpression> predicate) {
    return EnumerableDefaults.all(getThis(), predicate.getFunction());
  }

  public boolean any(FunctionExpression> predicate) {
    return EnumerableDefaults.any(getThis(), predicate.getFunction());
  }

  public BigDecimal averageBigDecimal(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public BigDecimal averageNullableBigDecimal(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public double averageDouble(FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public Double averageNullableDouble(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public int averageInteger(FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public Integer averageNullableInteger(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public float averageFloat(FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public Float averageNullableFloat(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public long averageLong(FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public Long averageNullableLong(
      FunctionExpression> selector) {
    return EnumerableDefaults.average(getThis(), selector.getFunction());
  }

  public Queryable concat(Enumerable source2) {
    return EnumerableDefaults.concat(getThis(), source2).asQueryable();
  }

  public int count(FunctionExpression> predicate) {
    return EnumerableDefaults.count(getThis(), predicate.getFunction());
  }

  public T first(FunctionExpression> predicate) {
    return EnumerableDefaults.first(getThis(), predicate.getFunction());
  }

  public T firstOrDefault(FunctionExpression> predicate) {
    return EnumerableDefaults.firstOrDefault(getThis(),
        predicate.getFunction());
  }

  public  Queryable> groupBy(
      FunctionExpression> keySelector) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction())
        .asQueryable();
  }

  public  Queryable> groupBy(
      FunctionExpression> keySelector,
      EqualityComparer comparer) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        comparer).asQueryable();
  }

  public  Queryable> groupBy(
      FunctionExpression> keySelector,
      FunctionExpression> elementSelector) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        elementSelector.getFunction()).asQueryable();
  }

  public  Queryable> groupBy(
      FunctionExpression> keySelector,
      FunctionExpression> elementSelector,
      EqualityComparer comparer) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        elementSelector.getFunction(), comparer).asQueryable();
  }

  public  Queryable groupByK(
      FunctionExpression> keySelector,
      FunctionExpression, TResult>> resultSelector) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        resultSelector.getFunction()).asQueryable();
  }

  public  Queryable groupByK(
      FunctionExpression> keySelector,
      FunctionExpression, TResult>> resultSelector,
      EqualityComparer comparer) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        resultSelector.getFunction(), comparer).asQueryable();
  }

  public  Queryable groupBy(
      FunctionExpression> keySelector,
      FunctionExpression> elementSelector,
      FunctionExpression, TResult>> resultSelector) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        elementSelector.getFunction(), resultSelector.getFunction())
        .asQueryable();
  }

  public  Queryable groupBy(
      FunctionExpression> keySelector,
      FunctionExpression> elementSelector,
      FunctionExpression, TResult>> resultSelector,
      EqualityComparer comparer) {
    return EnumerableDefaults.groupBy(getThis(), keySelector.getFunction(),
        elementSelector.getFunction(), resultSelector.getFunction(), comparer)
        .asQueryable();
  }

  public  Queryable groupJoin(
      Enumerable inner,
      FunctionExpression> outerKeySelector,
      FunctionExpression> innerKeySelector,
      FunctionExpression, TResult>> resultSelector) {
    return EnumerableDefaults.groupJoin(getThis(), inner,
        outerKeySelector.getFunction(), innerKeySelector.getFunction(),
        resultSelector.getFunction()).asQueryable();
  }

  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();
  }

  public  Queryable join(
      Enumerable inner,
      FunctionExpression> outerKeySelector,
      FunctionExpression> innerKeySelector,
      FunctionExpression> resultSelector) {
    return EnumerableDefaults.hashJoin(getThis(), inner,
        outerKeySelector.getFunction(), innerKeySelector.getFunction(),
        resultSelector.getFunction()).asQueryable();
  }

  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();
  }

  public T last(FunctionExpression> predicate) {
    return EnumerableDefaults.last(getThis(), predicate.getFunction());
  }

  public T lastOrDefault(FunctionExpression> predicate) {
    return EnumerableDefaults.lastOrDefault(getThis(), predicate.getFunction());
  }

  public long longCount(FunctionExpression> predicate) {
    return EnumerableDefaults.longCount(getThis(), predicate.getFunction());
  }

  public > TResult max(
      FunctionExpression> selector) {
    return EnumerableDefaults.max(getThis(), selector.getFunction());
  }

  public > TResult min(
      FunctionExpression> selector) {
    return EnumerableDefaults.min(getThis(), selector.getFunction());
  }

  public  OrderedQueryable orderBy(
      FunctionExpression> keySelector) {
    return EnumerableDefaults.asOrderedQueryable(
        EnumerableDefaults.orderBy(getThis(), keySelector.getFunction()));
  }

  public  OrderedQueryable orderBy(
      FunctionExpression> keySelector,
      Comparator comparator) {
    return EnumerableDefaults.asOrderedQueryable(
        EnumerableDefaults.orderBy(getThis(), keySelector.getFunction(),
            comparator));
  }

  public  OrderedQueryable orderByDescending(
      FunctionExpression> keySelector) {
    return EnumerableDefaults.asOrderedQueryable(
        EnumerableDefaults.orderByDescending(getThis(),
            keySelector.getFunction()));
  }

  public  OrderedQueryable orderByDescending(
      FunctionExpression> keySelector,
      Comparator comparator) {
    return EnumerableDefaults.asOrderedQueryable(
        EnumerableDefaults.orderByDescending(getThis(),
            keySelector.getFunction(), comparator));
  }

  public  Queryable select(
      FunctionExpression> selector) {
    return EnumerableDefaults.select(getThis(), selector.getFunction())
        .asQueryable();
  }

  public  Queryable selectN(
      FunctionExpression> selector) {
    return EnumerableDefaults.select(getThis(), selector.getFunction())
        .asQueryable();
  }

  public  Queryable selectMany(
      FunctionExpression>> selector) {
    return EnumerableDefaults.selectMany(getThis(), selector.getFunction())
        .asQueryable();
  }

  public  Queryable selectManyN(
      FunctionExpression>> selector) {
    return EnumerableDefaults.selectMany(getThis(), selector.getFunction())
        .asQueryable();
  }

  public  Queryable selectMany(
      FunctionExpression>>
        collectionSelector,
      FunctionExpression> resultSelector) {
    return EnumerableDefaults.selectMany(getThis(),
        collectionSelector.getFunction(), resultSelector.getFunction())
        .asQueryable();
  }

  public  Queryable selectManyN(
      FunctionExpression>>
        collectionSelector,
      FunctionExpression> resultSelector) {
    return EnumerableDefaults.selectMany(getThis(),
        collectionSelector.getFunction(), resultSelector.getFunction())
        .asQueryable();
  }

  public T single(FunctionExpression> predicate) {
    return EnumerableDefaults.single(getThis(), predicate.getFunction());
  }

  public T singleOrDefault(FunctionExpression> predicate) {
    return EnumerableDefaults.singleOrDefault(getThis(),
        predicate.getFunction());
  }

  public Queryable skipWhile(FunctionExpression> predicate) {
    return EnumerableDefaults.skipWhile(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public Queryable skipWhileN(
      FunctionExpression> predicate) {
    return EnumerableDefaults.skipWhile(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public BigDecimal sumBigDecimal(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public BigDecimal sumNullableBigDecimal(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public double sumDouble(FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public Double sumNullableDouble(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public int sumInteger(FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public Integer sumNullableInteger(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public long sumLong(FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public Long sumNullableLong(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public float sumFloat(FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public Float sumNullableFloat(
      FunctionExpression> selector) {
    return EnumerableDefaults.sum(getThis(), selector.getFunction());
  }

  public Queryable takeWhile(FunctionExpression> predicate) {
    return EnumerableDefaults.takeWhile(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public Queryable takeWhileN(
      FunctionExpression> predicate) {
    return EnumerableDefaults.takeWhile(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public Queryable where(
      FunctionExpression> predicate) {
    return EnumerableDefaults.where(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public Queryable whereN(
      FunctionExpression> predicate) {
    return EnumerableDefaults.where(getThis(), predicate.getFunction())
        .asQueryable();
  }

  public  Queryable zip(Enumerable source1,
      FunctionExpression> resultSelector) {
    return EnumerableDefaults.zip(getThis(), source1,
        resultSelector.getFunction()).asQueryable();
  }

  public T aggregate(Function2 func) {
    return EnumerableDefaults.aggregate(getThis(), func);
  }


  public  TResult aggregate(TAccumulate seed,
      Function2 func,
      Function1 selector) {
    return EnumerableDefaults.aggregate(getThis(), seed, func, selector);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy