com.hazelcast.shaded.org.apache.calcite.prepare.QueryableRelBuilder 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 com.hazelcast.shaded.org.apache.calcite.prepare;
import com.hazelcast.shaded.org.apache.calcite.jdbc.CalciteSchema;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Enumerable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Grouping;
import com.hazelcast.shaded.org.apache.calcite.linq4j.OrderedQueryable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.Queryable;
import com.hazelcast.shaded.org.apache.calcite.linq4j.QueryableDefaults;
import com.hazelcast.shaded.org.apache.calcite.linq4j.QueryableFactory;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.BigDecimalFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.DoubleFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.EqualityComparer;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.FloatFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.Function1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.Function2;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.IntegerFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.LongFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.NullableBigDecimalFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.NullableDoubleFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.NullableFloatFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.NullableIntegerFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.NullableLongFunction1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.Predicate1;
import com.hazelcast.shaded.org.apache.calcite.linq4j.function.Predicate2;
import com.hazelcast.shaded.org.apache.calcite.linq4j.tree.FunctionExpression;
import com.hazelcast.shaded.org.apache.calcite.rel.RelNode;
import com.hazelcast.shaded.org.apache.calcite.rel.logical.LogicalFilter;
import com.hazelcast.shaded.org.apache.calcite.rel.logical.LogicalProject;
import com.hazelcast.shaded.org.apache.calcite.rel.logical.LogicalTableScan;
import com.hazelcast.shaded.org.apache.calcite.rex.RexNode;
import com.hazelcast.shaded.org.apache.calcite.schema.QueryableTable;
import com.hazelcast.shaded.org.apache.calcite.schema.TranslatableTable;
import com.hazelcast.shaded.org.apache.calcite.schema.impl.AbstractTableQueryable;
import com.hazelcast.shaded.com.google.common.collect.ImmutableList;
import com.hazelcast.shaded.com.google.common.collect.ImmutableSet;
import com.hazelcast.shaded.org.checkerframework.checker.nullness.qual.Nullable;
import com.hazelcast.shaded.org.checkerframework.checker.nullness.qual.PolyNull;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import static com.hazelcast.shaded.org.apache.calcite.linq4j.Nullness.castNonNull;
import static java.util.Objects.requireNonNull;
/**
* Implementation of {@link QueryableFactory}
* that builds a tree of {@link RelNode} planner nodes. Used by
* {@link LixToRelTranslator}.
*
* Each of the methods that implements a {@code Replayer} method creates
* a tree of {@code RelNode}s equivalent to the arguments, and calls
* {@link #setRel} to assign the root of that tree to the {@link #rel} member
* variable.
*
*
To comply with the {@link com.hazelcast.shaded.org.apache.calcite.linq4j.QueryableFactory}
* interface, which is after all a factory, each method returns a dummy result
* such as {@code null} or {@code 0}.
* The caller will not use the result.
* The real effect of the method is to
* call {@link #setRel} with a {@code RelNode}.
*
*
NOTE: Many methods currently throw {@link UnsupportedOperationException}.
* These method need to be implemented.
*
* @param Element type
*/
class QueryableRelBuilder implements QueryableFactory {
private final LixToRelTranslator translator;
private @Nullable RelNode rel;
QueryableRelBuilder(LixToRelTranslator translator) {
this.translator = translator;
}
RelNode toRel(Queryable queryable) {
if (queryable instanceof QueryableDefaults.Replayable) {
//noinspection unchecked
((QueryableDefaults.Replayable) queryable).replay(this);
return requireNonNull(rel, "rel");
}
if (queryable instanceof AbstractTableQueryable) {
final AbstractTableQueryable tableQueryable =
(AbstractTableQueryable) queryable;
final QueryableTable table = tableQueryable.table;
final CalciteSchema.TableEntry tableEntry =
CalciteSchema.from(tableQueryable.schema)
.add(tableQueryable.tableName, tableQueryable.table);
final RelOptTableImpl relOptTable =
RelOptTableImpl.create(null, table.getRowType(translator.typeFactory),
tableEntry, null);
if (table instanceof TranslatableTable) {
return ((TranslatableTable) table).toRel(translator.toRelContext(),
relOptTable);
} else {
return LogicalTableScan.create(translator.cluster, relOptTable, ImmutableList.of());
}
}
return translator.translate(
requireNonNull(
queryable.getExpression(),
() -> "null expression from " + queryable));
}
/** Sets the output of this event. */
private void setRel(RelNode rel) {
this.rel = rel;
}
// ~ Methods from QueryableFactory -----------------------------------------
@Override public TResult aggregate(
Queryable source,
TAccumulate seed,
FunctionExpression> func,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public T aggregate(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public TAccumulate aggregate(
Queryable source,
TAccumulate seed,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public boolean all(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public boolean any(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public boolean any(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public BigDecimal averageBigDecimal(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public BigDecimal averageNullableBigDecimal(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public double averageDouble(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Double averageNullableDouble(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public int averageInteger(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Integer averageNullableInteger(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public float averageFloat(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Float averageNullableFloat(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public long averageLong(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Long averageNullableLong(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Queryable concat(
Queryable source, Enumerable source2) {
throw new UnsupportedOperationException();
}
@Override public boolean contains(
Queryable source, T element) {
throw new UnsupportedOperationException();
}
@Override public boolean contains(
Queryable source, T element, EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public int count(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public int count(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public Queryable<@Nullable T> defaultIfEmpty(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public Queryable<@PolyNull T> defaultIfEmpty(Queryable source,
@PolyNull T value) {
throw new UnsupportedOperationException();
}
@Override public Queryable distinct(
Queryable source) {
throw new UnsupportedOperationException();
}
@Override public Queryable distinct(
Queryable source, EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public T elementAt(Queryable source, int index) {
throw new UnsupportedOperationException();
}
@Override public T elementAtOrDefault(Queryable source, int index) {
throw new UnsupportedOperationException();
}
@Override public Queryable except(
Queryable source, Enumerable enumerable) {
return except(source, enumerable, false);
}
@Override public Queryable except(
Queryable source, Enumerable enumerable, boolean all) {
throw new UnsupportedOperationException();
}
@Override public Queryable except(
Queryable source,
Enumerable enumerable,
EqualityComparer tEqualityComparer) {
return except(source, enumerable, tEqualityComparer, false);
}
@Override public Queryable except(
Queryable source,
Enumerable enumerable,
EqualityComparer tEqualityComparer,
boolean all) {
throw new UnsupportedOperationException();
}
@Override public T first(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T first(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public T firstOrDefault(
Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T firstOrDefault(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public Queryable> groupBy(
Queryable source,
FunctionExpression> keySelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable> groupBy(
Queryable source,
FunctionExpression> keySelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public Queryable> groupBy(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression> elementSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupByK(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression, TResult>>
resultSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable> groupBy(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupByK(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression, TResult>>
elementSelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupBy(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
FunctionExpression, TResult>>
resultSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupBy(
Queryable source,
FunctionExpression> keySelector,
FunctionExpression> elementSelector,
FunctionExpression, TResult>>
resultSelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupJoin(
Queryable source,
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression, TResult>>
resultSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable groupJoin(
Queryable source,
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression, TResult>>
resultSelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public Queryable intersect(
Queryable source, Enumerable enumerable) {
return intersect(source, enumerable, false);
}
@Override public Queryable intersect(
Queryable source, Enumerable enumerable, boolean all) {
throw new UnsupportedOperationException();
}
@Override public Queryable intersect(
Queryable source,
Enumerable enumerable,
EqualityComparer tEqualityComparer) {
return intersect(source, enumerable, tEqualityComparer, false);
}
@Override public Queryable intersect(
Queryable source,
Enumerable enumerable,
EqualityComparer tEqualityComparer, boolean all) {
throw new UnsupportedOperationException();
}
@Override public Queryable join(
Queryable source,
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression> resultSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable join(
Queryable source,
Enumerable inner,
FunctionExpression> outerKeySelector,
FunctionExpression> innerKeySelector,
FunctionExpression> resultSelector,
EqualityComparer comparer) {
throw new UnsupportedOperationException();
}
@Override public T last(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T last(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public T lastOrDefault(
Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T lastOrDefault(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public long longCount(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public long longCount(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public T max(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public > TResult max(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public T min(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public > TResult min(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Queryable ofType(
Queryable source, Class clazz) {
throw new UnsupportedOperationException();
}
@Override public Queryable cast(
Queryable source,
Class clazz) {
throw new UnsupportedOperationException();
}
@Override public OrderedQueryable orderBy(
Queryable source,
FunctionExpression> keySelector) {
throw new UnsupportedOperationException();
}
@Override public OrderedQueryable orderBy(
Queryable source,
FunctionExpression> keySelector,
Comparator comparator) {
throw new UnsupportedOperationException();
}
@Override public OrderedQueryable orderByDescending(
Queryable source,
FunctionExpression> keySelector) {
throw new UnsupportedOperationException();
}
@Override public OrderedQueryable orderByDescending(
Queryable source,
FunctionExpression> keySelector,
Comparator comparator) {
throw new UnsupportedOperationException();
}
@Override public Queryable reverse(
Queryable source) {
throw new UnsupportedOperationException();
}
@Override public Queryable select(
Queryable source,
FunctionExpression> selector) {
RelNode child = toRel(source);
List nodes = translator.toRexList(selector, child);
setRel(
LogicalProject.create(child, ImmutableList.of(), nodes, (List) null,
ImmutableSet.of()));
return castNonNull(null);
}
@Override public Queryable selectN(
Queryable source,
FunctionExpression> selector) {
throw new UnsupportedOperationException();
}
@Override public Queryable selectMany(
Queryable source,
FunctionExpression>> selector) {
throw new UnsupportedOperationException();
}
@Override public Queryable selectManyN(
Queryable source,
FunctionExpression>> selector) {
throw new UnsupportedOperationException();
}
@Override public Queryable selectMany(
Queryable source,
FunctionExpression>>
collectionSelector,
FunctionExpression> resultSelector) {
throw new UnsupportedOperationException();
}
@Override public Queryable selectManyN(
Queryable source,
FunctionExpression>>
collectionSelector,
FunctionExpression> resultSelector) {
throw new UnsupportedOperationException();
}
@Override public boolean sequenceEqual(
Queryable source, Enumerable enumerable) {
throw new UnsupportedOperationException();
}
@Override public boolean sequenceEqual(
Queryable source,
Enumerable enumerable,
EqualityComparer tEqualityComparer) {
throw new UnsupportedOperationException();
}
@Override public T single(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T single(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public T singleOrDefault(Queryable source) {
throw new UnsupportedOperationException();
}
@Override public T singleOrDefault(
Queryable source,
FunctionExpression> predicate) {
throw new UnsupportedOperationException();
}
@Override public Queryable skip(
Queryable