Class RelBuilder
- java.lang.Object
-
- org.apache.calcite.tools.RelBuilder
-
- Direct Known Subclasses:
FlinkRelBuilder
@Enclosing public class RelBuilder extends Object
Copied from calcite to workaround CALCITE-4668FLINK modifications are at lines
- Should be removed after fix of FLINK-29804: Lines 2945 ~ 2948
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RelBuilder.AggCall
Information necessary to create a call to an aggregate function.static interface
RelBuilder.Config
Configuration of RelBuilder.static interface
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate.static interface
RelBuilder.OverCall
Call to a windowed aggregate function.
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.calcite.plan.RelOptCluster
cluster
protected @Nullable org.apache.calcite.plan.RelOptSchema
relOptSchema
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelBuilder(@Nullable org.apache.calcite.plan.Context context, org.apache.calcite.plan.RelOptCluster cluster, @Nullable org.apache.calcite.plan.RelOptSchema relOptSchema)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RelBuilder
adoptConvention(org.apache.calcite.plan.Convention convention)
Returns new RelBuilder that adopts the convention provided.RelBuilder
aggregate(RelBuilder.GroupKey groupKey, Iterable<RelBuilder.AggCall> aggCalls)
Creates anAggregate
with multiple calls.RelBuilder
aggregate(RelBuilder.GroupKey groupKey, List<org.apache.calcite.rel.core.AggregateCall> aggregateCalls)
Creates anAggregate
with an array ofAggregateCall
s.RelBuilder
aggregate(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls)
Creates anAggregate
with an array of calls.RelBuilder.AggCall
aggregateCall(org.apache.calcite.rel.core.AggregateCall a)
Creates a call to an aggregate function as a copy of anAggregateCall
.RelBuilder.AggCall
aggregateCall(org.apache.calcite.rel.core.AggregateCall a, org.apache.calcite.util.mapping.Mapping mapping)
Creates a call to an aggregate function as a copy of anAggregateCall
, applying a mapping.protected RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable org.apache.calcite.rex.RexNode filter, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> distinctKeys, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function with all applicable operands.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function.RelBuilder.AggCall
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, org.apache.calcite.rex.RexNode... operands)
Creates a call to an aggregate function.org.apache.calcite.rex.RexNode
alias(org.apache.calcite.rex.RexNode expr, @Nullable String alias)
Returns an expression wrapped in an alias.org.apache.calcite.rex.RexNode
all(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ALL predicate.org.apache.calcite.rex.RexNode
and(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an AND.org.apache.calcite.rex.RexNode
and(org.apache.calcite.rex.RexNode... operands)
Creates an AND.RelBuilder
antiJoin(Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates an anti-join.RelBuilder
antiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates an anti-join.org.apache.calcite.rex.RexSubQuery
arrayQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ARRAY sub-query.RelBuilder
as(String alias)
Assigns a table alias to the top entry on the stack.RelBuilder.AggCall
avg(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theAVG
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
avg(org.apache.calcite.rex.RexNode operand)
Creates a call to theAVG
aggregate function.org.apache.calcite.rex.RexNode
between(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode lower, org.apache.calcite.rex.RexNode upper)
Creates aBETWEEN
.org.apache.calcite.rel.RelNode
build()
Returns the final relational expression.org.apache.calcite.rex.RexNode
call(org.apache.calcite.sql.SqlOperator operator, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to a scalar operator.org.apache.calcite.rex.RexNode
call(org.apache.calcite.sql.SqlOperator operator, org.apache.calcite.rex.RexNode... operands)
Creates a call to a scalar operator.org.apache.calcite.rex.RexNode
cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName)
Creates an expression that casts an expression to a given type.org.apache.calcite.rex.RexNode
cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision)
Creates an expression that casts an expression to a type with a given name and precision or length.org.apache.calcite.rex.RexNode
cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision, int scale)
Creates an expression that casts an expression to a type with a given name, precision and scale.void
clear()
Clears the stack.RelBuilder
convert(org.apache.calcite.rel.type.RelDataType castRowType, boolean rename)
Creates a projection that converts the current relational expression's output to a desired row type.RelBuilder
correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, Iterable<? extends org.apache.calcite.rex.RexNode> requiredFields)
Creates aCorrelate
with aCorrelationId
and a list of fields that are used by correlation.RelBuilder
correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, org.apache.calcite.rex.RexNode... requiredFields)
Creates aCorrelate
with aCorrelationId
and an array of fields that are used by correlation.RelBuilder.AggCall
count(boolean distinct, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to theCOUNT
aggregate function.RelBuilder.AggCall
count(org.apache.calcite.rex.RexNode... operands)
Creates a call to theCOUNT
aggregate function.RelBuilder.AggCall
countStar(@Nullable String alias)
Creates a call to theCOUNT(*)
aggregate function.static RelBuilder
create(org.apache.calcite.tools.FrameworkConfig config)
Creates a RelBuilder.org.apache.calcite.rex.RexWindowBound
currentRow()
Creates aCURRENT ROW
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.org.apache.calcite.rex.RexNode
cursor(int inputCount, int ordinal)
Creates a RexCall to theCURSOR
function by ordinal.org.apache.calcite.rex.RexNode
desc(org.apache.calcite.rex.RexNode node)
Converts a sort expression to descending.RelBuilder
distinct()
Creates anAggregate
that makes the relational expression distinct on all fields.org.apache.calcite.rex.RexNode
dot(org.apache.calcite.rex.RexNode node, int fieldOrdinal)
Creates an access to a field by ordinal.org.apache.calcite.rex.RexNode
dot(org.apache.calcite.rex.RexNode node, String fieldName)
Creates an access to a field by name.RelBuilder
empty()
Creates a relational expression that reads from an input and throws all of the rows away.org.apache.calcite.rex.RexNode
equals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an=
.RelBuilder
exchange(org.apache.calcite.rel.RelDistribution distribution)
Creates an Exchange by distribution.org.apache.calcite.rex.RexSubQuery
exists(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an EXISTS predicate.org.apache.calcite.rex.RexInputRef
field(int fieldOrdinal)
Creates a reference to an input field by ordinal.org.apache.calcite.rex.RexInputRef
field(int inputCount, int inputOrdinal, int fieldOrdinal)
Creates a reference to a field of a given input relational expression by ordinal.org.apache.calcite.rex.RexInputRef
field(int inputCount, int inputOrdinal, String fieldName)
Creates a reference to a field of given input relational expression by name.org.apache.calcite.rex.RexNode
field(int inputCount, String alias, String fieldName)
Creates a reference to a field which originated in a relation with the given alias.org.apache.calcite.rex.RexInputRef
field(String fieldName)
Creates a reference to a field by name.org.apache.calcite.rex.RexNode
field(String alias, String fieldName)
Creates a reference to a field of the current record which originated in a relation with a given alias.org.apache.calcite.rex.RexNode
field(org.apache.calcite.rex.RexNode e, String name)
Returns a reference to a given field of a record-valued expression.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields()
Returns references to the fields of the top input.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(int inputCount, int inputOrdinal)
Returns references to the fields of a given input.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(Iterable<String> fieldNames)
Returns references to fields identified by name.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(List<? extends Number> ordinals)
Returns references to fields for a given list of input ordinals.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(org.apache.calcite.rel.RelCollation collation)
Returns references to fields for a given collation.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(org.apache.calcite.util.ImmutableBitSet ordinals)
Returns references to fields for a given bit set of input ordinals.com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode>
fields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.RelBuilder
filter(Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates aFilter
of a list of predicates.RelBuilder
filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet, Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates aFilter
of a list of correlation variables and a list of predicates.RelBuilder
filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet, org.apache.calcite.rex.RexNode... predicates)
Creates aFilter
of a list of correlation variables and an array of predicates.RelBuilder
filter(org.apache.calcite.rex.RexNode... predicates)
Creates aFilter
of an array of predicates.org.apache.calcite.rex.RexWindowBound
following(org.apache.calcite.rex.RexNode bound)
Creates abound FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.RelBuilder
functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates aTableFunctionScan
.RelBuilder
functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, org.apache.calcite.rex.RexNode... operands)
Creates aTableFunctionScan
.org.apache.calcite.plan.RelOptCluster
getCluster()
@Nullable org.apache.calcite.plan.RelOptSchema
getRelOptSchema()
org.apache.calcite.rex.RexBuilder
getRexBuilder()
Returns the builder forRexNode
expressions.org.apache.calcite.rel.core.RelFactories.TableScanFactory
getScanFactory()
org.apache.calcite.rel.type.RelDataTypeFactory
getTypeFactory()
Returns the type factory.org.apache.calcite.rex.RexNode
greaterThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a>
.org.apache.calcite.rex.RexNode
greaterThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a>=
.RelBuilder.GroupKey
groupKey()
Creates an empty group key.RelBuilder.GroupKey
groupKey(int... fieldOrdinals)
Creates a group key of fields identified by ordinal.RelBuilder.GroupKey
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a group key.RelBuilder.GroupKey
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Deprecated.Now that indicator is deprecated, usegroupKey(Iterable, Iterable)
, which has the same behavior as calling this method withindicator = false
.RelBuilder.GroupKey
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Creates a group key with grouping sets.RelBuilder.GroupKey
groupKey(String... fieldNames)
Creates a group key of fields identified by name.RelBuilder.GroupKey
groupKey(org.apache.calcite.rex.RexNode... nodes)
Creates a group key.RelBuilder.GroupKey
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet)
Creates a group key, identified by field positions in the underlying relational expression.RelBuilder.GroupKey
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet, boolean indicator, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets)
Deprecated.RelBuilder.GroupKey
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet, Iterable<? extends org.apache.calcite.util.ImmutableBitSet> groupSets)
Creates a group key with grouping sets, both identified by field positions in the underlying relational expression.RelBuilder
hints(Iterable<org.apache.calcite.rel.hint.RelHint> hints)
Attaches multiple hints to the stack top relational expression.RelBuilder
hints(org.apache.calcite.rel.hint.RelHint... hints)
Attaches an array of hints to the stack top relational expression.org.apache.calcite.rex.RexSubQuery
in(org.apache.calcite.rel.RelNode rel, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates an IN predicate with a sub-query.org.apache.calcite.rex.RexNode
in(org.apache.calcite.rex.RexNode arg, Iterable<? extends org.apache.calcite.rex.RexNode> ranges)
Creates an IN predicate with a list of values.org.apache.calcite.rex.RexNode
in(org.apache.calcite.rex.RexNode arg, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an IN predicate with a sub-query.org.apache.calcite.rex.RexNode
in(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode... ranges)
Creates an IN predicate with a list of values.RelBuilder
intersect(boolean all)
Creates anIntersect
of the two most recent relational expressions on the stack.RelBuilder
intersect(boolean all, int n)
Creates anIntersect
of then
most recent relational expressions on the stack.org.apache.calcite.rex.RexNode
isDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent too0 IS DISTINCT FROM o1
.org.apache.calcite.rex.RexNode
isNotDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent to "o0 IS NOT DISTINCT FROM o1
".org.apache.calcite.rex.RexNode
isNotNull(org.apache.calcite.rex.RexNode operand)
Creates anIS NOT NULL
.org.apache.calcite.rex.RexNode
isNull(org.apache.calcite.rex.RexNode operand)
Creates abIS NULL
.RelBuilder
join(org.apache.calcite.rel.core.JoinRelType joinType, Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates aJoin
with multiple conditions.RelBuilder
join(org.apache.calcite.rel.core.JoinRelType joinType, String... fieldNames)
Creates aJoin
using USING syntax.RelBuilder
join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition)
Creates aJoin
with one condition.RelBuilder
join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition, Set<org.apache.calcite.rel.core.CorrelationId> variablesSet)
Creates aJoin
with correlating variables.RelBuilder
join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition0, org.apache.calcite.rex.RexNode... conditions)
Creates aJoin
with an array of conditions.org.apache.calcite.rex.RexNode
lessThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<
.org.apache.calcite.rex.RexNode
lessThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<=
.<R> R
let(Function<RelBuilder,R> consumer)
Performs an action on this RelBuilder.RelBuilder
limit(int offset, int fetch)
Creates a limit without a sort.org.apache.calcite.rex.RexLiteral
literal(@Nullable Object value)
Creates a literal (constant expression).org.apache.calcite.rex.RexSubQuery
mapQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MAP sub-query.RelBuilder
match(org.apache.calcite.rex.RexNode pattern, boolean strictStart, boolean strictEnd, Map<String,org.apache.calcite.rex.RexNode> patternDefinitions, Iterable<? extends org.apache.calcite.rex.RexNode> measureList, org.apache.calcite.rex.RexNode after, Map<String,? extends SortedSet<String>> subsets, boolean allRows, Iterable<? extends org.apache.calcite.rex.RexNode> partitionKeys, Iterable<? extends org.apache.calcite.rex.RexNode> orderKeys, org.apache.calcite.rex.RexNode interval)
Creates aMatch
.RelBuilder.AggCall
max(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theMAX
aggregate function.RelBuilder.AggCall
max(org.apache.calcite.rex.RexNode operand)
Creates a call to theMAX
aggregate function, optionally with an alias.RelBuilder.AggCall
min(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theMIN
aggregate function, optionally with an alias.RelBuilder.AggCall
min(org.apache.calcite.rex.RexNode operand)
Creates a call to theMIN
aggregate function.RelBuilder
minus(boolean all)
Creates aMinus
of the two most recent relational expressions on the stack.RelBuilder
minus(boolean all, int n)
Creates aMinus
of then
most recent relational expressions on the stack.org.apache.calcite.rex.RexSubQuery
multisetQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MULTISET sub-query.org.apache.calcite.rex.RexNode
not(org.apache.calcite.rex.RexNode operand)
Creates a NOT.org.apache.calcite.rex.RexNode
notEquals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<>
.org.apache.calcite.rex.RexNode
nullsFirst(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls first.org.apache.calcite.rex.RexNode
nullsLast(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls last.org.apache.calcite.rex.RexNode
or(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an OR.org.apache.calcite.rex.RexNode
or(org.apache.calcite.rex.RexNode... operands)
Creates an OR.org.apache.calcite.rex.RexNode
patternAlter(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates alternate patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternAlter(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates alternate patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternConcat(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that concatenates patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternConcat(org.apache.calcite.rex.RexNode... nodes)
Creates a call that concatenates patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternExclude(org.apache.calcite.rex.RexNode node)
Creates a call that creates an exclude pattern; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternField(String alpha, org.apache.calcite.rel.type.RelDataType type, int i)
Creates a reference to a given field of the pattern.org.apache.calcite.rex.RexNode
patternPermute(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates permute patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternPermute(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates permute patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternQuantify(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates quantify patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rex.RexNode
patternQuantify(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates quantify patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.org.apache.calcite.rel.RelNode
peek()
Returns the relational expression at the top of the stack, but does not remove it.org.apache.calcite.rel.RelNode
peek(int n)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.org.apache.calcite.rel.RelNode
peek(int inputCount, int inputOrdinal)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.RelBuilder
permute(org.apache.calcite.util.mapping.Mapping mapping)
RelBuilder
pivot(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls, Iterable<? extends org.apache.calcite.rex.RexNode> axes, Iterable<? extends Map.Entry<String,? extends Iterable<? extends org.apache.calcite.rex.RexNode>>> values)
Creates a Pivot.org.apache.calcite.rex.RexWindowBound
preceding(org.apache.calcite.rex.RexNode bound)
Creates abound PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.RelBuilder
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aProject
of the given list of expressions.RelBuilder
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends @Nullable String> fieldNames)
Creates aProject
of the given list of expressions and field names.RelBuilder
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends @Nullable String> fieldNames, boolean force)
Creates aProject
of the given list of expressions, using the given names.RelBuilder
project(org.apache.calcite.rex.RexNode... nodes)
Creates aProject
of the given expressions.RelBuilder
projectExcept(Iterable<org.apache.calcite.rex.RexNode> expressions)
Creates aProject
of all original fields, except the given list of expressions.RelBuilder
projectExcept(org.apache.calcite.rex.RexNode... expressions)
Creates aProject
of all original fields, except the given expressions.RelBuilder
projectNamed(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, @Nullable Iterable<? extends @Nullable String> fieldNames, boolean force)
Creates aProject
of the given expressions and field names, and optionally optimizing.RelBuilder
projectPlus(Iterable<org.apache.calcite.rex.RexNode> nodes)
Creates aProject
of all original fields, plus the given list of expressions.RelBuilder
projectPlus(org.apache.calcite.rex.RexNode... nodes)
Creates aProject
of all original fields, plus the given expressions.static org.apache.calcite.tools.RelBuilderFactory
proto(Object... factories)
Creates aRelBuilderFactory
that uses a given set of factories.static org.apache.calcite.tools.RelBuilderFactory
proto(org.apache.calcite.plan.Context context)
Creates aRelBuilderFactory
, a partially-created RelBuilder.RelBuilder
push(org.apache.calcite.rel.RelNode node)
Adds a relational expression to be the input to the next relational expression constructed.RelBuilder
pushAll(Iterable<? extends org.apache.calcite.rel.RelNode> nodes)
Pushes a collection of relational expressions.RelBuilder
rename(List<? extends @Nullable String> fieldNames)
Ensures that the field names match those given.RelBuilder
repeatUnion(String tableName, boolean all)
Creates aRepeatUnion
associated to aTransientTable
without a maximum number of iterations, i.e. repeatUnion(tableName, all, -1).RelBuilder
repeatUnion(String tableName, boolean all, int iterationLimit)
Creates aRepeatUnion
associated to aTransientTable
of the two most recent relational expressions on the stack.org.apache.calcite.rex.RexSubQuery
scalarQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a scalar sub-query.RelBuilder
scan(Iterable<String> tableNames)
Creates aTableScan
of the table with a given name.RelBuilder
scan(String... tableNames)
Creates aTableScan
of the table with a given name.RelBuilder
semiJoin(Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates aJoin
withJoinRelType.SEMI
.RelBuilder
semiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates aJoin
withJoinRelType.SEMI
.int
size()
Returns the size of the stack.RelBuilder
snapshot(org.apache.calcite.rex.RexNode period)
Creates aSnapshot
of a given snapshot period.org.apache.calcite.rex.RexSubQuery
some(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a SOME (or ANY) predicate.RelBuilder
sort(int... fields)
Creates aSort
by field ordinals.RelBuilder
sort(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by expressions.RelBuilder
sort(org.apache.calcite.rel.RelCollation collation)
Creates aSort
by specifying collations.RelBuilder
sort(org.apache.calcite.rex.RexNode... nodes)
Creates aSort
by expressions.RelBuilder
sortExchange(org.apache.calcite.rel.RelDistribution distribution, org.apache.calcite.rel.RelCollation collation)
Creates a SortExchange by distribution and collation.RelBuilder
sortLimit(int offset, int fetch, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by a list of expressions, with limit and offset.RelBuilder
sortLimit(int offset, int fetch, org.apache.calcite.rex.RexNode... nodes)
Creates aSort
by expressions, with limit and offset.RelBuilder
sortLimit(@Nullable org.apache.calcite.rex.RexNode offsetNode, @Nullable org.apache.calcite.rex.RexNode fetchNode, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by a list of expressions, with limitNode and offsetNode.RelBuilder.AggCall
sum(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theSUM
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
sum(org.apache.calcite.rex.RexNode operand)
Creates a call to theSUM
aggregate function.String
toString()
Converts this RelBuilder to a string.RelBuilder
transform(UnaryOperator<RelBuilder.Config> transform)
Creates a copy of this RelBuilder, with the same state as this, applying a transform to the config.RelBuilder
transientScan(String tableName)
Creates aTableScan
on aTransientTable
with the given name, using as type the top of the stack's type.RelBuilder
transientScan(String tableName, org.apache.calcite.rel.type.RelDataType rowType)
Creates aTableScan
on aTransientTable
with the given name and type.org.apache.calcite.rex.RexWindowBound
unboundedFollowing()
Creates anUNBOUNDED FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.org.apache.calcite.rex.RexWindowBound
unboundedPreceding()
Creates anUNBOUNDED PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.RelBuilder
uncollect(List<String> itemAliases, boolean withOrdinality)
Creates anUncollect
with given item aliases.RelBuilder
union(boolean all)
Creates aUnion
of the two most recent relational expressions on the stack.RelBuilder
union(boolean all, int n)
Creates aUnion
of then
most recent relational expressions on the stack.org.apache.calcite.rex.RexSubQuery
unique(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a UNIQUE predicate.RelBuilder
unpivot(boolean includeNulls, Iterable<String> measureNames, Iterable<String> axisNames, Iterable<? extends Map.Entry<? extends List<? extends org.apache.calcite.rex.RexLiteral>,? extends List<? extends org.apache.calcite.rex.RexNode>>> axisMap)
Creates an Unpivot.RelBuilder
values(@Nullable String[] fieldNames, @Nullable Object... values)
Creates aValues
.RelBuilder
values(Iterable<? extends List<org.apache.calcite.rex.RexLiteral>> tupleList, org.apache.calcite.rel.type.RelDataType rowType)
Creates aValues
with a specified row type.RelBuilder
values(org.apache.calcite.rel.type.RelDataType rowType)
Creates aValues
with a specified row type and zero rows.RelBuilder
values(org.apache.calcite.rel.type.RelDataType rowType, Object... columnValues)
Creates aValues
with a specified row type.RelBuilder
variable(org.apache.calcite.util.Holder<org.apache.calcite.rex.RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into a Holder.<E> E
with(org.apache.calcite.rel.RelNode r, Function<RelBuilder,E> fn)
Evaluates an expression with a relational expression temporarily on the stack.<E> E
withPredicates(org.apache.calcite.rel.metadata.RelMetadataQuery mq, Function<RelBuilder,E> fn)
Performs an action using predicates of thecurrent node
to simplify.<E> E
withSimplifier(BiFunction<RelBuilder,org.apache.calcite.rex.RexSimplify,org.apache.calcite.rex.RexSimplify> simplifierTransform, Function<RelBuilder,E> fn)
Performs an action with a temporary simplifier.
-
-
-
Method Detail
-
create
public static RelBuilder create(org.apache.calcite.tools.FrameworkConfig config)
Creates a RelBuilder.
-
transform
public RelBuilder transform(UnaryOperator<RelBuilder.Config> transform)
Creates a copy of this RelBuilder, with the same state as this, applying a transform to the config.
-
let
public <R> R let(Function<RelBuilder,R> consumer)
Performs an action on this RelBuilder.For example, consider the following code:
RelNode filterAndRename(RelBuilder relBuilder, RelNode rel, RexNode condition, List<String> fieldNames) { relBuilder.push(rel) .filter(condition); if (fieldNames != null) { relBuilder.rename(fieldNames); } return relBuilder .build();
The pipeline is disrupted by the 'if'. The
let
method allows you to perform the flow as a single pipeline:RelNode filterAndRename(RelBuilder relBuilder, RelNode rel, RexNode condition, List<String> fieldNames) { return relBuilder.push(rel) .filter(condition) .let(r -> fieldNames == null ? r : r.rename(fieldNames)) .build();
In pipelined cases such as this one, the lambda must return this RelBuilder. But
let
return values of other types.
-
toString
public String toString()
Converts this RelBuilder to a string. The string is the string representation of all of the RelNodes on the stack.
-
getTypeFactory
public org.apache.calcite.rel.type.RelDataTypeFactory getTypeFactory()
Returns the type factory.
-
adoptConvention
public RelBuilder adoptConvention(org.apache.calcite.plan.Convention convention)
Returns new RelBuilder that adopts the convention provided. RelNode will be created with such convention if corresponding factory is provided.
-
getRexBuilder
public org.apache.calcite.rex.RexBuilder getRexBuilder()
Returns the builder forRexNode
expressions.
-
proto
public static org.apache.calcite.tools.RelBuilderFactory proto(org.apache.calcite.plan.Context context)
Creates aRelBuilderFactory
, a partially-created RelBuilder. Just add aRelOptCluster
and aRelOptSchema
-
proto
public static org.apache.calcite.tools.RelBuilderFactory proto(Object... factories)
Creates aRelBuilderFactory
that uses a given set of factories.
-
getCluster
public org.apache.calcite.plan.RelOptCluster getCluster()
-
getRelOptSchema
public @Nullable org.apache.calcite.plan.RelOptSchema getRelOptSchema()
-
getScanFactory
public org.apache.calcite.rel.core.RelFactories.TableScanFactory getScanFactory()
-
push
public RelBuilder push(org.apache.calcite.rel.RelNode node)
Adds a relational expression to be the input to the next relational expression constructed.This method is usual when you want to weave in relational expressions that are not supported by the builder. If, while creating such expressions, you need to use previously built expressions as inputs, call
build()
to pop those inputs.
-
pushAll
public RelBuilder pushAll(Iterable<? extends org.apache.calcite.rel.RelNode> nodes)
Pushes a collection of relational expressions.
-
size
public int size()
Returns the size of the stack.
-
build
public org.apache.calcite.rel.RelNode build()
Returns the final relational expression.Throws if the stack is empty.
-
peek
public org.apache.calcite.rel.RelNode peek()
Returns the relational expression at the top of the stack, but does not remove it.
-
peek
public org.apache.calcite.rel.RelNode peek(int n)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.
-
peek
public org.apache.calcite.rel.RelNode peek(int inputCount, int inputOrdinal)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.
-
with
public <E> E with(org.apache.calcite.rel.RelNode r, Function<RelBuilder,E> fn)
Evaluates an expression with a relational expression temporarily on the stack.
-
withSimplifier
public <E> E withSimplifier(BiFunction<RelBuilder,org.apache.calcite.rex.RexSimplify,org.apache.calcite.rex.RexSimplify> simplifierTransform, Function<RelBuilder,E> fn)
Performs an action with a temporary simplifier.
-
withPredicates
public <E> E withPredicates(org.apache.calcite.rel.metadata.RelMetadataQuery mq, Function<RelBuilder,E> fn)
Performs an action using predicates of thecurrent node
to simplify.
-
literal
public org.apache.calcite.rex.RexLiteral literal(@Nullable Object value)
Creates a literal (constant expression).
-
variable
public RelBuilder variable(org.apache.calcite.util.Holder<org.apache.calcite.rex.RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into a Holder.
-
field
public org.apache.calcite.rex.RexInputRef field(String fieldName)
Creates a reference to a field by name.Equivalent to
field(1, 0, fieldName)
.- Parameters:
fieldName
- Field name
-
field
public org.apache.calcite.rex.RexInputRef field(int inputCount, int inputOrdinal, String fieldName)
Creates a reference to a field of given input relational expression by name.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldName
- Field name
-
field
public org.apache.calcite.rex.RexInputRef field(int fieldOrdinal)
Creates a reference to an input field by ordinal.Equivalent to
field(1, 0, ordinal)
.- Parameters:
fieldOrdinal
- Field ordinal
-
field
public org.apache.calcite.rex.RexInputRef field(int inputCount, int inputOrdinal, int fieldOrdinal)
Creates a reference to a field of a given input relational expression by ordinal.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldOrdinal
- Field ordinal within input
-
field
public org.apache.calcite.rex.RexNode field(String alias, String fieldName)
Creates a reference to a field of the current record which originated in a relation with a given alias.
-
field
public org.apache.calcite.rex.RexNode field(int inputCount, String alias, String fieldName)
Creates a reference to a field which originated in a relation with the given alias. Searches for the relation starting at the top of the stack.
-
field
public org.apache.calcite.rex.RexNode field(org.apache.calcite.rex.RexNode e, String name)
Returns a reference to a given field of a record-valued expression.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields()
Returns references to the fields of the top input.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(int inputCount, int inputOrdinal)
Returns references to the fields of a given input.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.rel.RelCollation collation)
Returns references to fields for a given collation.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(List<? extends Number> ordinals)
Returns references to fields for a given list of input ordinals.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.util.ImmutableBitSet ordinals)
Returns references to fields for a given bit set of input ordinals.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(Iterable<String> fieldNames)
Returns references to fields identified by name.
-
fields
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.
-
dot
public org.apache.calcite.rex.RexNode dot(org.apache.calcite.rex.RexNode node, String fieldName)
Creates an access to a field by name.
-
dot
public org.apache.calcite.rex.RexNode dot(org.apache.calcite.rex.RexNode node, int fieldOrdinal)
Creates an access to a field by ordinal.
-
call
public org.apache.calcite.rex.RexNode call(org.apache.calcite.sql.SqlOperator operator, org.apache.calcite.rex.RexNode... operands)
Creates a call to a scalar operator.
-
call
public org.apache.calcite.rex.RexNode call(org.apache.calcite.sql.SqlOperator operator, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to a scalar operator.
-
in
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode... ranges)
Creates an IN predicate with a list of values.For example,
is equivalent to SQLb.scan("Emp") .filter(b.in(b.field("deptno"), b.literal(10), b.literal(20)))
SELECT * FROM Emp WHERE deptno IN (10, 20)
-
in
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, Iterable<? extends org.apache.calcite.rex.RexNode> ranges)
Creates an IN predicate with a list of values.For example,
b.scan("Emps") .filter( b.in(b.field("deptno"), Arrays.asList(b.literal(10), b.literal(20))))
is equivalent to the SQL
SELECT * FROM Emps WHERE deptno IN (10, 20)
-
in
public org.apache.calcite.rex.RexSubQuery in(org.apache.calcite.rel.RelNode rel, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates an IN predicate with a sub-query.
-
in
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an IN predicate with a sub-query.For example,
b.scan("Emps") .filter( b.in(b.field("deptno"), b2 -> b2.scan("Depts") .filter( b2.eq(b2.field("location"), b2.literal("Boston"))) .project(b.field("deptno")) .build()))
is equivalent to the SQL
SELECT * FROM Emps WHERE deptno IN (SELECT deptno FROM Dept WHERE location = 'Boston')
-
some
public org.apache.calcite.rex.RexSubQuery some(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a SOME (or ANY) predicate.For example,
b.scan("Emps") .filter( b.some(b.field("commission"), SqlStdOperatorTable.GREATER_THAN, b2 -> b2.scan("Emps") .filter( b2.eq(b2.field("job"), b2.literal("Manager"))) .project(b2.field("sal")) .build()))
is equivalent to the SQL
SELECT * FROM Emps WHERE commission > SOME (SELECT sal FROM Emps WHERE job = 'Manager')
or (since
SOME
andANY
are synonyms) the SQLSELECT * FROM Emps WHERE commission > ANY (SELECT sal FROM Emps WHERE job = 'Manager')
-
all
public org.apache.calcite.rex.RexNode all(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ALL predicate.For example,
b.scan("Emps") .filter( b.all(b.field("commission"), SqlStdOperatorTable.GREATER_THAN, b2 -> b2.scan("Emps") .filter( b2.eq(b2.field("job"), b2.literal("Manager"))) .project(b2.field("sal")) .build()))
is equivalent to the SQL
SELECT * FROM Emps WHERE commission > ALL (SELECT sal FROM Emps WHERE job = 'Manager')
Calcite translates
ALL
predicates toNOT SOME
. The following SQL is equivalent to the previous:SELECT * FROM Emps WHERE NOT (commission <= SOME (SELECT sal FROM Emps WHERE job = 'Manager'))
-
exists
public org.apache.calcite.rex.RexSubQuery exists(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an EXISTS predicate.For example,
b.scan("Depts") .filter( b.exists(b2 -> b2.scan("Emps") .filter( b2.eq(b2.field("job"), b2.literal("Manager"))) .build()))
is equivalent to the SQL
SELECT * FROM Depts WHERE EXISTS (SELECT 1 FROM Emps WHERE job = 'Manager')
-
unique
public org.apache.calcite.rex.RexSubQuery unique(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a UNIQUE predicate.For example,
b.scan("Depts") .filter( b.exists(b2 -> b2.scan("Emps") .filter( b2.eq(b2.field("job"), b2.literal("Manager"))) .project(b2.field("deptno") .build()))
is equivalent to the SQL
SELECT * FROM Depts WHERE UNIQUE (SELECT deptno FROM Emps WHERE job = 'Manager')
-
scalarQuery
public org.apache.calcite.rex.RexSubQuery scalarQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a scalar sub-query.For example,
b.scan("Depts") .project( b.field("deptno") b.scalarQuery(b2 -> b2.scan("Emps") .aggregate( b2.eq(b2.field("job"), b2.literal("Manager"))) .build()))
is equivalent to the SQL
SELECT deptno, (SELECT MAX(sal) FROM Emps) FROM Depts
-
arrayQuery
public org.apache.calcite.rex.RexSubQuery arrayQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ARRAY sub-query.For example,
b.scan("Depts") .project( b.field("deptno") b.arrayQuery(b2 -> b2.scan("Emps") .build()))
is equivalent to the SQL
SELECT deptno, ARRAY (SELECT * FROM Emps) FROM Depts
-
multisetQuery
public org.apache.calcite.rex.RexSubQuery multisetQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MULTISET sub-query.For example,
b.scan("Depts") .project( b.field("deptno") b.multisetQuery(b2 -> b2.scan("Emps") .build()))
is equivalent to the SQL
SELECT deptno, MULTISET (SELECT * FROM Emps) FROM Depts
-
mapQuery
public org.apache.calcite.rex.RexSubQuery mapQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MAP sub-query.For example,
b.scan("Depts") .project( b.field("deptno") b.multisetQuery(b2 -> b2.scan("Emps") .project(b2.field("empno"), b2.field("job")) .build()))
is equivalent to the SQL
SELECT deptno, MAP (SELECT empno, job FROM Emps) FROM Depts
-
and
public org.apache.calcite.rex.RexNode and(org.apache.calcite.rex.RexNode... operands)
Creates an AND.
-
and
public org.apache.calcite.rex.RexNode and(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an AND.Simplifies the expression a little:
e AND TRUE
becomese
;e AND e2 AND NOT e
becomese2
.
-
or
public org.apache.calcite.rex.RexNode or(org.apache.calcite.rex.RexNode... operands)
Creates an OR.
-
or
public org.apache.calcite.rex.RexNode or(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an OR.
-
not
public org.apache.calcite.rex.RexNode not(org.apache.calcite.rex.RexNode operand)
Creates a NOT.
-
equals
public org.apache.calcite.rex.RexNode equals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an=
.
-
greaterThan
public org.apache.calcite.rex.RexNode greaterThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a>
.
-
greaterThanOrEqual
public org.apache.calcite.rex.RexNode greaterThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a>=
.
-
lessThan
public org.apache.calcite.rex.RexNode lessThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<
.
-
lessThanOrEqual
public org.apache.calcite.rex.RexNode lessThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<=
.
-
notEquals
public org.apache.calcite.rex.RexNode notEquals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates a<>
.
-
isNotDistinctFrom
public org.apache.calcite.rex.RexNode isNotDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent to "o0 IS NOT DISTINCT FROM o1
". It is also equivalent to "o0 = o1 OR (o0 IS NULL AND o1 IS NULL)
".
-
isDistinctFrom
public org.apache.calcite.rex.RexNode isDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent too0 IS DISTINCT FROM o1
. It is also equivalent to "NOT (o0 = o1 OR (o0 IS NULL AND o1 IS NULL))
.
-
between
public org.apache.calcite.rex.RexNode between(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode lower, org.apache.calcite.rex.RexNode upper)
Creates aBETWEEN
.
-
isNull
public org.apache.calcite.rex.RexNode isNull(org.apache.calcite.rex.RexNode operand)
Creates abIS NULL
.
-
isNotNull
public org.apache.calcite.rex.RexNode isNotNull(org.apache.calcite.rex.RexNode operand)
Creates anIS NOT NULL
.
-
cast
public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName)
Creates an expression that casts an expression to a given type.
-
cast
public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision)
Creates an expression that casts an expression to a type with a given name and precision or length.
-
cast
public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision, int scale)
Creates an expression that casts an expression to a type with a given name, precision and scale.
-
alias
public org.apache.calcite.rex.RexNode alias(org.apache.calcite.rex.RexNode expr, @Nullable String alias)
Returns an expression wrapped in an alias.This method is idempotent: If the expression is already wrapped in the correct alias, does nothing; if wrapped in an incorrect alias, removes the incorrect alias and applies the correct alias.
-
desc
public org.apache.calcite.rex.RexNode desc(org.apache.calcite.rex.RexNode node)
Converts a sort expression to descending.
-
nullsLast
public org.apache.calcite.rex.RexNode nullsLast(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls last.
-
nullsFirst
public org.apache.calcite.rex.RexNode nullsFirst(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls first.
-
unboundedPreceding
public org.apache.calcite.rex.RexWindowBound unboundedPreceding()
Creates anUNBOUNDED PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.
-
preceding
public org.apache.calcite.rex.RexWindowBound preceding(org.apache.calcite.rex.RexNode bound)
Creates abound PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.
-
currentRow
public org.apache.calcite.rex.RexWindowBound currentRow()
Creates aCURRENT ROW
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.
-
following
public org.apache.calcite.rex.RexWindowBound following(org.apache.calcite.rex.RexNode bound)
Creates abound FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.
-
unboundedFollowing
public org.apache.calcite.rex.RexWindowBound unboundedFollowing()
Creates anUNBOUNDED FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.
-
groupKey
public RelBuilder.GroupKey groupKey()
Creates an empty group key.
-
groupKey
public RelBuilder.GroupKey groupKey(org.apache.calcite.rex.RexNode... nodes)
Creates a group key.
-
groupKey
public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a group key.
-
groupKey
public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Creates a group key with grouping sets.
-
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Deprecated.Now that indicator is deprecated, usegroupKey(Iterable, Iterable)
, which has the same behavior as calling this method withindicator = false
.
-
groupKey
public RelBuilder.GroupKey groupKey(int... fieldOrdinals)
Creates a group key of fields identified by ordinal.
-
groupKey
public RelBuilder.GroupKey groupKey(String... fieldNames)
Creates a group key of fields identified by name.
-
groupKey
public RelBuilder.GroupKey groupKey(org.apache.calcite.util.ImmutableBitSet groupSet)
Creates a group key, identified by field positions in the underlying relational expression.This method of creating a group key does not allow you to group on new expressions, only column projections, but is efficient, especially when you are coming from an existing
Aggregate
.
-
groupKey
public RelBuilder.GroupKey groupKey(org.apache.calcite.util.ImmutableBitSet groupSet, Iterable<? extends org.apache.calcite.util.ImmutableBitSet> groupSets)
Creates a group key with grouping sets, both identified by field positions in the underlying relational expression.This method of creating a group key does not allow you to group on new expressions, only column projections, but is efficient, especially when you are coming from an existing
Aggregate
.It is possible for
groupSet
to be strict superset of allgroupSets
. For example, in the pseudo SQLGROUP BY 0, 1, 2 GROUPING SETS ((0, 1), 0)
column 2 does not appear in either grouping set. This is not valid SQL. We can approximate in actual SQL by adding an extra grouping set and filtering out using
HAVING
, as follows:GROUP BY GROUPING SETS ((0, 1, 2), (0, 1), 0) HAVING GROUPING_ID(0, 1, 2) <> 0
-
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(org.apache.calcite.util.ImmutableBitSet groupSet, boolean indicator, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.
-
aggregateCall
public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function.To add other operands, apply
RelBuilder.AggCall.distinct()
,RelBuilder.AggCall.approximate(boolean)
,filter(RexNode...)
,RelBuilder.AggCall.sort(java.lang.Iterable<org.apache.calcite.rex.RexNode>)
,RelBuilder.AggCall.as(java.lang.String)
to the result.
-
aggregateCall
public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, org.apache.calcite.rex.RexNode... operands)
Creates a call to an aggregate function.To add other operands, apply
RelBuilder.AggCall.distinct()
,RelBuilder.AggCall.approximate(boolean)
,filter(RexNode...)
,RelBuilder.AggCall.sort(java.lang.Iterable<org.apache.calcite.rex.RexNode>)
,RelBuilder.AggCall.as(java.lang.String)
to the result.
-
aggregateCall
public RelBuilder.AggCall aggregateCall(org.apache.calcite.rel.core.AggregateCall a)
Creates a call to an aggregate function as a copy of anAggregateCall
.
-
aggregateCall
public RelBuilder.AggCall aggregateCall(org.apache.calcite.rel.core.AggregateCall a, org.apache.calcite.util.mapping.Mapping mapping)
Creates a call to an aggregate function as a copy of anAggregateCall
, applying a mapping.
-
aggregateCall
protected RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable org.apache.calcite.rex.RexNode filter, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> distinctKeys, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function with all applicable operands.
-
count
public RelBuilder.AggCall count(org.apache.calcite.rex.RexNode... operands)
Creates a call to theCOUNT
aggregate function.
-
count
public RelBuilder.AggCall count(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to theCOUNT
aggregate function.
-
count
public RelBuilder.AggCall count(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.
-
count
public RelBuilder.AggCall count(boolean distinct, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.
-
countStar
public RelBuilder.AggCall countStar(@Nullable String alias)
Creates a call to theCOUNT(*)
aggregate function.
-
sum
public RelBuilder.AggCall sum(org.apache.calcite.rex.RexNode operand)
Creates a call to theSUM
aggregate function.
-
sum
public RelBuilder.AggCall sum(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theSUM
aggregate function, optionally distinct and with an alias.
-
avg
public RelBuilder.AggCall avg(org.apache.calcite.rex.RexNode operand)
Creates a call to theAVG
aggregate function.
-
avg
public RelBuilder.AggCall avg(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theAVG
aggregate function, optionally distinct and with an alias.
-
min
public RelBuilder.AggCall min(org.apache.calcite.rex.RexNode operand)
Creates a call to theMIN
aggregate function.
-
min
public RelBuilder.AggCall min(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theMIN
aggregate function, optionally with an alias.
-
max
public RelBuilder.AggCall max(org.apache.calcite.rex.RexNode operand)
Creates a call to theMAX
aggregate function, optionally with an alias.
-
max
public RelBuilder.AggCall max(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
Creates a call to theMAX
aggregate function.
-
patternField
public org.apache.calcite.rex.RexNode patternField(String alpha, org.apache.calcite.rel.type.RelDataType type, int i)
Creates a reference to a given field of the pattern.- Parameters:
alpha
- the pattern nametype
- Type of fieldi
- Ordinal of field- Returns:
- Reference to field of pattern
-
patternConcat
public org.apache.calcite.rex.RexNode patternConcat(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that concatenates patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternConcat
public org.apache.calcite.rex.RexNode patternConcat(org.apache.calcite.rex.RexNode... nodes)
Creates a call that concatenates patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternAlter
public org.apache.calcite.rex.RexNode patternAlter(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates alternate patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternAlter
public org.apache.calcite.rex.RexNode patternAlter(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates alternate patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternQuantify
public org.apache.calcite.rex.RexNode patternQuantify(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates quantify patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternQuantify
public org.apache.calcite.rex.RexNode patternQuantify(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates quantify patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternPermute
public org.apache.calcite.rex.RexNode patternPermute(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates permute patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternPermute
public org.apache.calcite.rex.RexNode patternPermute(org.apache.calcite.rex.RexNode... nodes)
Creates a call that creates permute patterns; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
patternExclude
public org.apache.calcite.rex.RexNode patternExclude(org.apache.calcite.rex.RexNode node)
Creates a call that creates an exclude pattern; for use inmatch(org.apache.calcite.rex.RexNode, boolean, boolean, java.util.Map<java.lang.String, org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode, java.util.Map<java.lang.String, ? extends java.util.SortedSet<java.lang.String>>, boolean, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, java.lang.Iterable<? extends org.apache.calcite.rex.RexNode>, org.apache.calcite.rex.RexNode)
.
-
scan
public RelBuilder scan(Iterable<String> tableNames)
Creates aTableScan
of the table with a given name.Throws if the table does not exist.
Returns this builder.
- Parameters:
tableNames
- Name of table (can optionally be qualified)
-
scan
public RelBuilder scan(String... tableNames)
Creates aTableScan
of the table with a given name.Throws if the table does not exist.
Returns this builder.
- Parameters:
tableNames
- Name of table (can optionally be qualified)
-
snapshot
public RelBuilder snapshot(org.apache.calcite.rex.RexNode period)
Creates aSnapshot
of a given snapshot period.Returns this builder.
- Parameters:
period
- Name of table (can optionally be qualified)
-
cursor
public org.apache.calcite.rex.RexNode cursor(int inputCount, int ordinal)
Creates a RexCall to theCURSOR
function by ordinal.- Parameters:
inputCount
- Number of inputsordinal
- The reference to the relational input- Returns:
- RexCall to CURSOR function
-
functionScan
public RelBuilder functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, org.apache.calcite.rex.RexNode... operands)
Creates aTableFunctionScan
.
-
functionScan
public RelBuilder functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates aTableFunctionScan
.
-
filter
public RelBuilder filter(org.apache.calcite.rex.RexNode... predicates)
Creates aFilter
of an array of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If the result is TRUE no filter is created.
-
filter
public RelBuilder filter(Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates aFilter
of a list of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If the result is TRUE no filter is created.
-
filter
public RelBuilder filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet, org.apache.calcite.rex.RexNode... predicates)
Creates aFilter
of a list of correlation variables and an array of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If the result is TRUE no filter is created.
-
filter
public RelBuilder filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet, Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates aFilter
of a list of correlation variables and a list of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If simplification is on and the result is TRUE, no filter is created.
-
project
public RelBuilder project(org.apache.calcite.rex.RexNode... nodes)
Creates aProject
of the given expressions.
-
project
public RelBuilder project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aProject
of the given list of expressions.Infers names as would
project(Iterable, Iterable)
if all suggested names were null.- Parameters:
nodes
- Expressions
-
project
public RelBuilder project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends @Nullable String> fieldNames)
Creates aProject
of the given list of expressions and field names.- Parameters:
nodes
- ExpressionsfieldNames
- field names for expressions
-
project
public RelBuilder project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends @Nullable String> fieldNames, boolean force)
Creates aProject
of the given list of expressions, using the given names.Names are deduced as follows:
- If the length of
fieldNames
is greater than the index of the current entry innodes
, and the entry infieldNames
is not null, uses it; otherwise - If an expression projects an input field, or is a cast an input field, uses the input field name; otherwise
- If an expression is a call to
SqlStdOperatorTable.AS
(seealias(org.apache.calcite.rex.RexNode, java.lang.String)
), removes the call but uses the intended alias.
After the field names have been inferred, makes the field names unique by appending numeric suffixes.
- Parameters:
nodes
- ExpressionsfieldNames
- Suggested field namesforce
- create project even if it is identity
- If the length of
-
projectPlus
public RelBuilder projectPlus(org.apache.calcite.rex.RexNode... nodes)
Creates aProject
of all original fields, plus the given expressions.
-
projectPlus
public RelBuilder projectPlus(Iterable<org.apache.calcite.rex.RexNode> nodes)
Creates aProject
of all original fields, plus the given list of expressions.
-
projectExcept
public RelBuilder projectExcept(org.apache.calcite.rex.RexNode... expressions)
Creates aProject
of all original fields, except the given expressions.- Throws:
IllegalArgumentException
- if the given expressions contain duplicates or there is an expression that does not match an existing field
-
projectExcept
public RelBuilder projectExcept(Iterable<org.apache.calcite.rex.RexNode> expressions)
Creates aProject
of all original fields, except the given list of expressions.- Throws:
IllegalArgumentException
- if the given expressions contain duplicates or there is an expression that does not match an existing field
-
projectNamed
public RelBuilder projectNamed(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, @Nullable Iterable<? extends @Nullable String> fieldNames, boolean force)
Creates aProject
of the given expressions and field names, and optionally optimizing.If
fieldNames
is null, or if a particular entry infieldNames
is null, derives field names from the input expressions.If
force
is false, and the input is aProject
, and the expressions make the trivial projection ($0, $1, ...), modifies the input.- Parameters:
nodes
- ExpressionsfieldNames
- Suggested field names, or null to generateforce
- Whether to create a renaming Project if the projections are trivial
-
uncollect
public RelBuilder uncollect(List<String> itemAliases, boolean withOrdinality)
Creates anUncollect
with given item aliases.- Parameters:
itemAliases
- Operand item aliases, never nullwithOrdinality
- IfwithOrdinality
, the output contains an extraORDINALITY
column
-
rename
public RelBuilder rename(List<? extends @Nullable String> fieldNames)
Ensures that the field names match those given.If all fields have the same name, adds nothing; if any fields do not have the same name, adds a
Project
.Note that the names can be short-lived. Other
RelBuilder
operations make no guarantees about the field names of the rows they produce.- Parameters:
fieldNames
- List of desired field names; may contain null values or have fewer fields than the current row type
-
distinct
public RelBuilder distinct()
Creates anAggregate
that makes the relational expression distinct on all fields.
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls)
Creates anAggregate
with an array of calls.
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, List<org.apache.calcite.rel.core.AggregateCall> aggregateCalls)
Creates anAggregate
with an array ofAggregateCall
s.
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, Iterable<RelBuilder.AggCall> aggCalls)
Creates anAggregate
with multiple calls.
-
union
public RelBuilder union(boolean all)
Creates aUnion
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create UNION ALL
-
union
public RelBuilder union(boolean all, int n)
Creates aUnion
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create UNION ALLn
- Number of inputs to the UNION operator
-
intersect
public RelBuilder intersect(boolean all)
Creates anIntersect
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create INTERSECT ALL
-
intersect
public RelBuilder intersect(boolean all, int n)
Creates anIntersect
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create INTERSECT ALLn
- Number of inputs to the INTERSECT operator
-
minus
public RelBuilder minus(boolean all)
Creates aMinus
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
minus
public RelBuilder minus(boolean all, int n)
Creates aMinus
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
transientScan
public RelBuilder transientScan(String tableName)
Creates aTableScan
on aTransientTable
with the given name, using as type the top of the stack's type.- Parameters:
tableName
- table name
-
transientScan
public RelBuilder transientScan(String tableName, org.apache.calcite.rel.type.RelDataType rowType)
Creates aTableScan
on aTransientTable
with the given name and type.- Parameters:
tableName
- table namerowType
- row type of the table
-
repeatUnion
public RelBuilder repeatUnion(String tableName, boolean all)
Creates aRepeatUnion
associated to aTransientTable
without a maximum number of iterations, i.e. repeatUnion(tableName, all, -1).- Parameters:
tableName
- name of theTransientTable
associated to theRepeatUnion
all
- whether duplicates will be considered or not
-
repeatUnion
public RelBuilder repeatUnion(String tableName, boolean all, int iterationLimit)
Creates aRepeatUnion
associated to aTransientTable
of the two most recent relational expressions on the stack.Warning: if these relational expressions are not correctly defined, this operation might lead to an infinite loop.
The generated
RepeatUnion
operates as follows:- Evaluate its left term once, propagating the results into the
TransientTable
; - Evaluate its right term (which may contain a
TableScan
on theTransientTable
) over and over until it produces no more results (or until an optional maximum number of iterations is reached). On each iteration, the results are propagated into theTransientTable
, overwriting the results from the previous one.
- Parameters:
tableName
- Name of theTransientTable
associated to theRepeatUnion
all
- Whether duplicates are considerediterationLimit
- Maximum number of iterations; negative value means no limit
- Evaluate its left term once, propagating the results into the
-
join
public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition0, org.apache.calcite.rex.RexNode... conditions)
Creates aJoin
with an array of conditions.
-
join
public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates aJoin
with multiple conditions.
-
join
public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition)
Creates aJoin
with one condition.
-
join
public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition, Set<org.apache.calcite.rel.core.CorrelationId> variablesSet)
Creates aJoin
with correlating variables.
-
correlate
public RelBuilder correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, org.apache.calcite.rex.RexNode... requiredFields)
Creates aCorrelate
with aCorrelationId
and an array of fields that are used by correlation.
-
correlate
public RelBuilder correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, Iterable<? extends org.apache.calcite.rex.RexNode> requiredFields)
Creates aCorrelate
with aCorrelationId
and a list of fields that are used by correlation.
-
join
public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, String... fieldNames)
Creates aJoin
using USING syntax.For each of the field names, both left and right inputs must have a field of that name. Constructs a join condition that the left and right fields are equal.
- Parameters:
joinType
- Join typefieldNames
- Field names
-
semiJoin
public RelBuilder semiJoin(Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates aJoin
withJoinRelType.SEMI
.A semi-join is a form of join that combines two relational expressions according to some condition, and outputs only rows from the left input for which at least one row from the right input matches. It only outputs columns from the left input, and ignores duplicates on the right.
For example,
EMP semi-join DEPT
finds allEMP
records that do not have a correspondingDEPT
record, similar to the following SQL:SELECT * FROM EMP WHERE EXISTS (SELECT 1 FROM DEPT WHERE DEPT.DEPTNO = EMP.DEPTNO)
-
semiJoin
public RelBuilder semiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates aJoin
withJoinRelType.SEMI
.- See Also:
semiJoin(Iterable)
-
antiJoin
public RelBuilder antiJoin(Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates an anti-join.An anti-join is a form of join that combines two relational expressions according to some condition, but outputs only rows from the left input for which no rows from the right input match.
For example,
EMP anti-join DEPT
finds allEMP
records that do not have a correspondingDEPT
record, similar to the following SQL:SELECT * FROM EMP WHERE NOT EXISTS (SELECT 1 FROM DEPT WHERE DEPT.DEPTNO = EMP.DEPTNO)
-
antiJoin
public RelBuilder antiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates an anti-join.- See Also:
antiJoin(Iterable)
-
as
public RelBuilder as(String alias)
Assigns a table alias to the top entry on the stack.
-
values
public RelBuilder values(@Nullable String[] fieldNames, @Nullable Object... values)
Creates aValues
.The
values
array must have the same number of entries asfieldNames
, or an integer multiple if you wish to create multiple rows.If there are zero rows, or if all values of a any column are null, this method cannot deduce the type of columns. For these cases, call
values(Iterable, RelDataType)
.- Parameters:
fieldNames
- Field namesvalues
- Values
-
empty
public RelBuilder empty()
Creates a relational expression that reads from an input and throws all of the rows away.Note that this method always pops one relational expression from the stack.
values
, in contrast, does not pop any relational expressions, and always produces a leaf.The default implementation creates a
Values
with the same specified row type and aliases as the input, and ignores the input entirely. But schema-on-query systems such as Drill might override this method to create a relation expression that retains the input, just to read its schema.
-
values
public RelBuilder values(org.apache.calcite.rel.type.RelDataType rowType, Object... columnValues)
Creates aValues
with a specified row type.This method can handle cases that
values(String[], Object...)
cannot, such as all values of a column being null, or there being zero rows.- Parameters:
rowType
- Row typecolumnValues
- Values
-
values
public RelBuilder values(Iterable<? extends List<org.apache.calcite.rex.RexLiteral>> tupleList, org.apache.calcite.rel.type.RelDataType rowType)
Creates aValues
with a specified row type.This method can handle cases that
values(String[], Object...)
cannot, such as all values of a column being null, or there being zero rows.- Parameters:
tupleList
- Tuple listrowType
- Row type
-
values
public RelBuilder values(org.apache.calcite.rel.type.RelDataType rowType)
Creates aValues
with a specified row type and zero rows.- Parameters:
rowType
- Row type
-
limit
public RelBuilder limit(int offset, int fetch)
Creates a limit without a sort.
-
exchange
public RelBuilder exchange(org.apache.calcite.rel.RelDistribution distribution)
Creates an Exchange by distribution.
-
sortExchange
public RelBuilder sortExchange(org.apache.calcite.rel.RelDistribution distribution, org.apache.calcite.rel.RelCollation collation)
Creates a SortExchange by distribution and collation.
-
sort
public RelBuilder sort(int... fields)
Creates aSort
by field ordinals.Negative fields mean descending: -1 means field(0) descending, -2 means field(1) descending, etc.
-
sort
public RelBuilder sort(org.apache.calcite.rex.RexNode... nodes)
Creates aSort
by expressions.
-
sort
public RelBuilder sort(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by expressions.
-
sortLimit
public RelBuilder sortLimit(int offset, int fetch, org.apache.calcite.rex.RexNode... nodes)
Creates aSort
by expressions, with limit and offset.
-
sort
public RelBuilder sort(org.apache.calcite.rel.RelCollation collation)
Creates aSort
by specifying collations.
-
sortLimit
public RelBuilder sortLimit(int offset, int fetch, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by a list of expressions, with limit and offset.- Parameters:
offset
- Number of rows to skip; non-positive means don't skip anyfetch
- Maximum number of rows to fetch; negative means no limitnodes
- Sort expressions
-
sortLimit
public RelBuilder sortLimit(@Nullable org.apache.calcite.rex.RexNode offsetNode, @Nullable org.apache.calcite.rex.RexNode fetchNode, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates aSort
by a list of expressions, with limitNode and offsetNode.- Parameters:
offsetNode
- RexLiteral means number of rows to skip is deterministic, RexDynamicParam means number of rows to skip is dynamic.fetchNode
- RexLiteral means maximum number of rows to fetch is deterministic, RexDynamicParam mean maximum number is dynamic.nodes
- Sort expressions
-
convert
public RelBuilder convert(org.apache.calcite.rel.type.RelDataType castRowType, boolean rename)
Creates a projection that converts the current relational expression's output to a desired row type.The desired row type and the row type to be converted must have the same number of fields.
- Parameters:
castRowType
- row type after castrename
- if true, use field names from castRowType; if false, preserve field names from rel
-
permute
public RelBuilder permute(org.apache.calcite.util.mapping.Mapping mapping)
-
match
public RelBuilder match(org.apache.calcite.rex.RexNode pattern, boolean strictStart, boolean strictEnd, Map<String,org.apache.calcite.rex.RexNode> patternDefinitions, Iterable<? extends org.apache.calcite.rex.RexNode> measureList, org.apache.calcite.rex.RexNode after, Map<String,? extends SortedSet<String>> subsets, boolean allRows, Iterable<? extends org.apache.calcite.rex.RexNode> partitionKeys, Iterable<? extends org.apache.calcite.rex.RexNode> orderKeys, org.apache.calcite.rex.RexNode interval)
Creates aMatch
.
-
pivot
public RelBuilder pivot(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls, Iterable<? extends org.apache.calcite.rex.RexNode> axes, Iterable<? extends Map.Entry<String,? extends Iterable<? extends org.apache.calcite.rex.RexNode>>> values)
Creates a Pivot.To achieve the same effect as the SQL
SELECT * FROM (SELECT mgr, deptno, job, sal FROM emp) PIVOT (SUM(sal) AS ss, COUNT(*) AS c FOR (job, deptno) IN (('CLERK', 10) AS c10, ('MANAGER', 20) AS m20))
use the builder as follows:
RelBuilder b; b.scan("EMP"); final RelBuilder.GroupKey groupKey = b.groupKey("MGR"); final List<RelBuilder.AggCall> aggCalls = Arrays.asList(b.sum(b.field("SAL")).as("SS"), b.count().as("C")); final List<RexNode> axes = Arrays.asList(b.field("JOB"), b.field("DEPTNO")); final ImmutableMap.Builder<String, List<RexNode>> valueMap = ImmutableMap.builder(); valueMap.put("C10", Arrays.asList(b.literal("CLERK"), b.literal(10))); valueMap.put("M20", Arrays.asList(b.literal("MANAGER"), b.literal(20))); b.pivot(groupKey, aggCalls, axes, valueMap.build().entrySet());
Note that the SQL uses a sub-query to project away columns (e.g.
HIREDATE
) that it does not reference, so that they do not appear in theGROUP BY
. You do not need to do that in this API, because thegroupKey
parameter specifies the keys.Pivot is implemented by desugaring. The above example becomes the following:
SELECT mgr, SUM(sal) FILTER (WHERE job = 'CLERK' AND deptno = 10) AS c10_ss, COUNT(*) FILTER (WHERE job = 'CLERK' AND deptno = 10) AS c10_c, SUM(sal) FILTER (WHERE job = 'MANAGER' AND deptno = 20) AS m20_ss, COUNT(*) FILTER (WHERE job = 'MANAGER' AND deptno = 20) AS m20_c FROM emp GROUP BY mgr
- Parameters:
groupKey
- Key columnsaggCalls
- Aggregate expressions to compute for each valueaxes
- Columns to pivotvalues
- Values to pivot, and the alias for each column group- Returns:
- this RelBuilder
-
unpivot
public RelBuilder unpivot(boolean includeNulls, Iterable<String> measureNames, Iterable<String> axisNames, Iterable<? extends Map.Entry<? extends List<? extends org.apache.calcite.rex.RexLiteral>,? extends List<? extends org.apache.calcite.rex.RexNode>>> axisMap)
Creates an Unpivot.To achieve the same effect as the SQL
SELECT * FROM (SELECT deptno, job, sal, comm FROM emp) UNPIVOT INCLUDE NULLS (remuneration FOR remuneration_type IN (comm AS 'commission', sal AS 'salary'))
use the builder as follows:
RelBuilder b; b.scan("EMP"); final List<String> measureNames = Arrays.asList("REMUNERATION"); final List<String> axisNames = Arrays.asList("REMUNERATION_TYPE"); final Map<List<RexLiteral>, List<RexNode>> axisMap = ImmutableMap.<List<RexLiteral>, List<RexNode>>builder() .put(Arrays.asList(b.literal("commission")), Arrays.asList(b.field("COMM"))) .put(Arrays.asList(b.literal("salary")), Arrays.asList(b.field("SAL"))) .build(); b.unpivot(false, measureNames, axisNames, axisMap);
The query generates two columns:
remuneration_type
(an axis column) andremuneration
(a measure column). Axis columns contain values to indicate the source of the row (in this case,'salary'
if the row came from thesal
column, and'commission'
if the row came from thecomm
column).- Parameters:
includeNulls
- Whether to include NULL values in the outputmeasureNames
- Names of columns to be generated to hold pivoted measuresaxisNames
- Names of columns to be generated to hold qualifying valuesaxisMap
- Mapping from the columns that hold measures to the values that the axis columns will hold in the generated rows- Returns:
- This RelBuilder
-
hints
public RelBuilder hints(org.apache.calcite.rel.hint.RelHint... hints)
Attaches an array of hints to the stack top relational expression.The redundant hints would be eliminated.
- Parameters:
hints
- Hints- Throws:
AssertionError
- if the top relational expression does not implementHintable
-
hints
public RelBuilder hints(Iterable<org.apache.calcite.rel.hint.RelHint> hints)
Attaches multiple hints to the stack top relational expression.The redundant hints would be eliminated.
- Parameters:
hints
- Hints- Throws:
AssertionError
- if the top relational expression does not implementHintable
-
clear
public void clear()
Clears the stack.The builder's state is now the same as when it was created.
-
-