Class RelBuilder
- Direct Known Subclasses:
PigRelBuilder
,PigRelBuilder
RelBuilder
does not make possible anything that you could not
also accomplish by calling the factory methods of the particular relational
expression. But it makes common tasks more straightforward and concise.
RelBuilder
uses factories to create relational expressions.
By default, it uses the default factories, which create logical relational
expressions (LogicalFilter
,
LogicalProject
and so forth).
But you could override those factories so that, say, filter
creates
instead a HiveFilter
.
It is not thread-safe.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Information necessary to create a call to an aggregate function.static interface
Configuration of RelBuilder.static interface
Information necessary to create the GROUP BY clause of an Aggregate.static interface
Call to a windowed aggregate function. -
Field Summary
Modifier and TypeFieldDescriptionprotected final RelOptCluster
protected final @Nullable RelOptSchema
-
Constructor Summary
ModifierConstructorDescriptionprotected
RelBuilder
(@Nullable Context context, RelOptCluster cluster, @Nullable RelOptSchema relOptSchema) -
Method Summary
Modifier and TypeMethodDescriptionadoptConvention
(Convention convention) Returns new RelBuilder that adopts the convention provided.aggregate
(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls) Creates anAggregate
with multiple calls.aggregate
(RelBuilder.GroupKey groupKey, List<AggregateCall> aggregateCalls) Creates anAggregate
with an array ofAggregateCall
s.aggregate
(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls) Creates anAggregate
with an array of calls.Creates a call to an aggregate function as a copy of anAggregateCall
.aggregateCall
(AggregateCall a, Mapping mapping) Creates a call to an aggregate function as a copy of anAggregateCall
, applying a mapping.protected RelBuilder.AggCall
aggregateCall
(SqlParserPos pos, SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable RexNode filter, @Nullable com.google.common.collect.ImmutableList<RexNode> distinctKeys, com.google.common.collect.ImmutableList<RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<RexNode> preOperands, com.google.common.collect.ImmutableList<RexNode> operands) Creates a call to an aggregate function with all applicable operands.aggregateCall
(SqlParserPos pos, SqlAggFunction aggFunction, Iterable<? extends RexNode> operands) Creates a call to an aggregate function.aggregateCall
(SqlParserPos pos, SqlAggFunction aggFunction, RexNode... operands) Creates a call to an aggregate function.protected RelBuilder.AggCall
aggregateCall
(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable RexNode filter, @Nullable com.google.common.collect.ImmutableList<RexNode> distinctKeys, com.google.common.collect.ImmutableList<RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<RexNode> preOperands, com.google.common.collect.ImmutableList<RexNode> operands) Creates a call to an aggregate function with all applicable operands.aggregateCall
(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, @Nullable String alias, Iterable<? extends RexNode> operands) Deprecated.aggregateCall
(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, @Nullable String alias, RexNode... operands) Deprecated.aggregateCall
(SqlAggFunction aggFunction, boolean distinct, RexNode filter, @Nullable String alias, Iterable<? extends RexNode> operands) Deprecated.aggregateCall
(SqlAggFunction aggFunction, boolean distinct, RexNode filter, @Nullable String alias, RexNode... operands) Deprecated.aggregateCall
(SqlAggFunction aggFunction, Iterable<? extends RexNode> operands) Creates a call to an aggregate function.aggregateCall
(SqlAggFunction aggFunction, RexNode... operands) Creates a call to an aggregate function.aggregateRex
(RelBuilder.GroupKey groupKey, boolean projectKey, Iterable<? extends RexNode> nodes) aggregateRex
(RelBuilder.GroupKey groupKey, RexNode... nodes) Returns an expression wrapped in an alias.all
(RexNode node, SqlOperator op, Function<RelBuilder, RelNode> f) Creates an ALL predicate.Creates an AND.Creates an AND.Creates an anti-join.Creates an anti-join.Creates an ARRAY sub-query.Assigns a table alias to the top entry on the stack.asofJoin
(JoinRelType joinType, RexNode condition, RexNode matchCondition) Creates aLogicalAsofJoin
with the specified conditions.Creates a call to theAVG
aggregate function, optionally distinct and with an alias.Creates a call to theAVG
aggregate function.avg
(SqlParserPos pos, boolean distinct, @Nullable String alias, RexNode operand) Creates a call to theAVG
aggregate function, optionally distinct and with an alias.avg
(SqlParserPos pos, RexNode operand) Creates a call to theAVG
aggregate function.Creates aBETWEEN
.build()
Returns the final relational expression.call
(SqlOperator operator, Iterable<? extends RexNode> operands) Creates a call to a scalar operator.call
(SqlOperator operator, RexNode... operands) Creates a call to a scalar operator.cast
(RexNode expr, SqlTypeName typeName) Creates an expression that casts an expression to a given type.cast
(RexNode expr, SqlTypeName typeName, int precision) Creates an expression that casts an expression to a type with a given name and precision or length.cast
(RexNode expr, SqlTypeName typeName, int precision, int scale) Creates an expression that casts an expression to a type with a given name, precision and scale.cast
(SqlParserPos pos, RexNode expr, SqlTypeName typeName) Creates an expression that casts an expression to a given type.cast
(SqlParserPos pos, RexNode expr, SqlTypeName typeName, int precision) Creates an expression that casts an expression to a type with a given name and precision or length.cast
(SqlParserPos pos, RexNode expr, 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.convert
(RelDataType castRowType, boolean rename) Creates a projection that converts the current relational expression's output to a desired row type.correlate
(JoinRelType joinType, CorrelationId correlationId, Iterable<? extends RexNode> requiredFields) Creates aCorrelate
with aCorrelationId
and a list of fields that are used by correlation.correlate
(JoinRelType joinType, CorrelationId correlationId, RexNode... requiredFields) Creates aCorrelate
with aCorrelationId
and an array of fields that are used by correlation.Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.Creates a call to theCOUNT
aggregate function.Creates a call to theCOUNT
aggregate function.Creates a call to theCOUNT(*)
aggregate function.static RelBuilder
create
(FrameworkConfig config) Creates a RelBuilder.Creates aCURRENT ROW
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.cursor
(int inputCount, int ordinal) Creates a RexCall to theCURSOR
function by ordinal.Converts a sort expression to descending.distinct()
Creates anAggregate
that makes the relational expression distinct on all fields.Creates an access to a field by ordinal.Creates an access to a field by name.empty()
Creates a relational expression that reads from an input and throws all of the rows away.Creates an=
.exchange
(RelDistribution distribution) Creates an Exchange by distribution.Creates an EXISTS predicate.field
(int fieldOrdinal) Creates a reference to an input field by ordinal.field
(int inputCount, int inputOrdinal, int fieldOrdinal) Creates a reference to a field of a given input relational expression by ordinal.Creates a reference to a field of given input relational expression by name.Creates a reference to a field which originated in a relation with the given alias.Creates a reference to a field by name.Creates a reference to a field of the current record which originated in a relation with a given alias.Returns a reference to a given field (by ordinal) of a record-valued expression.Returns a reference to a given field (by name, case-insensitive) of a record-valued expression.com.google.common.collect.ImmutableList<RexNode>
fields()
Returns references to the fields of the top input.com.google.common.collect.ImmutableList<RexNode>
fields
(int inputCount, int inputOrdinal) Returns references to the fields of a given input.com.google.common.collect.ImmutableList<RexNode>
Returns references to fields identified by name.com.google.common.collect.ImmutableList<RexNode>
Returns references to fields for a given list of input ordinals.com.google.common.collect.ImmutableList<RexNode>
fields
(RelCollation collation) Returns references to fields for a given collation.com.google.common.collect.ImmutableList<RexNode>
fields
(ImmutableBitSet ordinals) Returns references to fields for a given bit set of input ordinals.com.google.common.collect.ImmutableList<RexNode>
fields
(Mappings.TargetMapping mapping) Returns references to fields identified by a mapping.Creates aFilter
of a list of predicates.filter
(Iterable<CorrelationId> variablesSet, Iterable<? extends RexNode> predicates) Creates aFilter
of a list of correlation variables and a list of predicates.filter
(Iterable<CorrelationId> variablesSet, RexNode... predicates) Creates aFilter
of a list of correlation variables and an array of predicates.Creates aFilter
of an array of predicates.Creates abound FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.functionScan
(SqlOperator operator, int inputCount, Iterable<? extends RexNode> operands) Creates aTableFunctionScan
.functionScan
(SqlOperator operator, int inputCount, RexNode... operands) Creates aTableFunctionScan
.@Nullable RelOptSchema
Returns the builder forRexNode
expressions.Returns the type factory.greaterThan
(RexNode operand0, RexNode operand1) Creates a>
.greaterThanOrEqual
(RexNode operand0, RexNode operand1) Creates a>=
.groupKey()
Creates an empty group key.groupKey
(int... fieldOrdinals) Creates a group key of fields identified by ordinal.Creates a group key.groupKey
(Iterable<? extends RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends RexNode>> nodeLists) Deprecated.groupKey
(Iterable<? extends RexNode> nodes, Iterable<? extends Iterable<? extends RexNode>> nodeLists) Creates a group key with grouping sets.Creates a group key of fields identified by name.Creates a group key.groupKey
(ImmutableBitSet groupSet) Creates a group key, identified by field positions in the underlying relational expression.groupKey
(ImmutableBitSet groupSet, boolean indicator, @Nullable com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets) Deprecated.groupKey
(ImmutableBitSet groupSet, Iterable<? extends ImmutableBitSet> groupSets) Creates a group key with grouping sets, both identified by field positions in the underlying relational expression.Attaches multiple hints to the stack top relational expression.Attaches an array of hints to the stack top relational expression.Creates an IN predicate with a sub-query.Creates an IN predicate with a list of values.in
(RexNode arg, Function<RelBuilder, RelNode> f) Creates an IN predicate with a sub-query.Creates an IN predicate with a list of values.intersect
(boolean all) Creates anIntersect
of the two most recent relational expressions on the stack.intersect
(boolean all, int n) Creates anIntersect
of then
most recent relational expressions on the stack.isDistinctFrom
(RexNode operand0, RexNode operand1) Creates an expression equivalent too0 IS DISTINCT FROM o1
.isNotDistinctFrom
(RexNode operand0, RexNode operand1) Creates an expression equivalent to "o0 IS NOT DISTINCT FROM o1
".Creates anIS NOT NULL
.Creates abIS NULL
.join
(JoinRelType joinType, Iterable<? extends RexNode> conditions) Creates aJoin
with multiple conditions.join
(JoinRelType joinType, String... fieldNames) Creates aJoin
using USING syntax.join
(JoinRelType joinType, RexNode condition) Creates aJoin
with one condition.join
(JoinRelType joinType, RexNode condition, Set<CorrelationId> variablesSet) Creates aJoin
with correlating variables.join
(JoinRelType joinType, RexNode condition0, RexNode... conditions) Creates aJoin
with an array of conditions.Creates a<
.lessThanOrEqual
(RexNode operand0, RexNode operand1) Creates a<=
.<R> R
let
(Function<RelBuilder, R> consumer) Performs an action on this RelBuilder.limit
(int offset, int fetch) Creates a limit and/or offset without a sort.Creates a literal (constant expression).literalAgg
(@Nullable Object value) Creates a call to theLITERAL_AGG
aggregate function.Creates a MAP sub-query.match
(RexNode pattern, boolean strictStart, boolean strictEnd, Map<String, RexNode> patternDefinitions, Iterable<? extends RexNode> measureList, RexNode after, Map<String, ? extends SortedSet<String>> subsets, boolean allRows, Iterable<? extends RexNode> partitionKeys, Iterable<? extends RexNode> orderKeys, RexNode interval) Creates aMatch
.Creates a call to theMAX
aggregate function.Creates a call to theMAX
aggregate function, optionally with an alias.Creates a call to theMIN
aggregate function, optionally with an alias.Creates a call to theMIN
aggregate function.minus
(boolean all) Creates aMinus
of the two most recent relational expressions on the stack.minus
(boolean all, int n) Creates aMinus
of then
most recent relational expressions on the stack.Creates a MULTISET sub-query.Creates a NOT.Creates a<>
.nullsFirst
(RexNode node) Converts a sort expression to nulls first.Converts a sort expression to nulls last.Creates an OR.Creates an OR.patternAlter
(Iterable<? extends 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
(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)
.patternConcat
(Iterable<? extends 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
(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)
.patternExclude
(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)
.patternField
(String alpha, RelDataType type, int i) Creates a reference to a given field of the pattern.patternPermute
(Iterable<? extends 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
(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)
.patternQuantify
(Iterable<? extends 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
(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)
.peek()
Returns the relational expression at the top of the stack, but does not remove it.peek
(int n) Returns the relational expressionn
positions from the top of the stack, but does not remove it.peek
(int inputCount, int inputOrdinal) Returns the relational expressionn
positions from the top of the stack, but does not remove it.pivot
(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls, Iterable<? extends RexNode> axes, Iterable<? extends Map.Entry<String, ? extends Iterable<? extends RexNode>>> values) Creates a Pivot.Creates abound PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.Creates aProject
of the given list of expressions.Creates aProject
of the given list of expressions and field names.project
(Iterable<? extends RexNode> nodes, Iterable<? extends @Nullable String> fieldNames, boolean force) Creates aProject
of the given list of expressions, using the given names.project
(Iterable<? extends RexNode> nodes, Iterable<? extends @Nullable String> fieldNames, boolean force, Iterable<CorrelationId> variablesSet) The same withproject(Iterable, Iterable, boolean)
, with additional variablesSet param.Creates aProject
of the given expressions.projectExcept
(Iterable<RexNode> expressions) Creates aProject
of all original fields, except the given list of expressions.projectExcept
(RexNode... expressions) Creates aProject
of all original fields, except the given expressions.projectNamed
(Iterable<? extends RexNode> nodes, @Nullable Iterable<? extends @Nullable String> fieldNames, boolean force) Creates aProject
of the given expressions and field names, and optionally optimizing.projectNamed
(Iterable<? extends RexNode> nodes, @Nullable Iterable<? extends @Nullable String> fieldNames, boolean force, Iterable<CorrelationId> variablesSet) Creates aProject
of the given expressions and field names, and optionally optimizing.projectPlus
(Iterable<? extends RexNode> nodes) Creates aProject
of all original fields, plus the given list of expressions.projectPlus
(RexNode... nodes) Creates aProject
of all original fields, plus the given expressions.static RelBuilderFactory
Creates aRelBuilderFactory
that uses a given set of factories.static RelBuilderFactory
Creates aRelBuilderFactory
, a partially-created RelBuilder.Adds a relational expression to be the input to the next relational expression constructed.Pushes a collection of relational expressions.Ensures that the field names match those given.repeatUnion
(String tableName, boolean all) Creates aRepeatUnion
associated to aTransientTable
without a maximum number of iterations, i.e.repeatUnion
(String tableName, boolean all, int iterationLimit) Creates aRepeatUnion
associated to aTransientTable
of the two most recent relational expressions on the stack.sample
(boolean bernoulli, BigDecimal sampleRate, @Nullable Integer repeatableSeed) Creates aSample
.Creates a scalar sub-query.Creates aTableScan
of the table with a given name.Creates aTableScan
of the table with a given name.Creates aJoin
withJoinRelType.SEMI
.Creates aJoin
withJoinRelType.SEMI
.int
size()
Returns the size of the stack.Creates aSnapshot
of a given snapshot period.some
(RexNode node, SqlOperator op, Function<RelBuilder, RelNode> f) Creates a SOME (or ANY) predicate.sort
(int... fields) Creates aSort
by field ordinals.Creates aSort
by expressions.sort
(RelCollation collation) Creates aSort
by specifying collations.Creates aSort
by expressions.sortExchange
(RelDistribution distribution, RelCollation collation) Creates a SortExchange by distribution and collation.Creates aSort
by a list of expressions, with limit and offset.Creates aSort
by expressions, with limit and offset.sortLimit
(@Nullable RexNode offsetNode, @Nullable RexNode fetchNode, Iterable<? extends RexNode> nodes) Creates aSort
by a list of expressions, with limitNode and offsetNode.Creates a call to theSUM
aggregate function, optionally distinct and with an alias.Creates a call to theSUM
aggregate function.sum
(SqlParserPos pos, boolean distinct, @Nullable String alias, RexNode operand) Creates a call to theSUM
aggregate function, optionally distinct and with an alias.sum
(SqlParserPos pos, RexNode operand) Creates a call to theSUM
aggregate function.toString()
Converts this RelBuilder to a string.transform
(UnaryOperator<RelBuilder.Config> transform) Creates a copy of this RelBuilder, with the same state as this, applying a transform to the config.transientScan
(String tableName) Creates aTableScan
on aTransientTable
with the given name, using as type the top of the stack's type.transientScan
(String tableName, RelDataType rowType) Creates aTableScan
on aTransientTable
with the given name and type.Creates anUNBOUNDED FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.Creates anUNBOUNDED PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
.Creates anUncollect
with given item aliases.union
(boolean all) Creates aUnion
of the two most recent relational expressions on the stack.union
(boolean all, int n) Creates aUnion
of then
most recent relational expressions on the stack.Creates a UNIQUE predicate.unpivot
(boolean includeNulls, Iterable<String> measureNames, Iterable<String> axisNames, Iterable<? extends Map.Entry<? extends List<? extends RexLiteral>, ? extends List<? extends RexNode>>> axisMap) Creates an Unpivot.Creates aValues
.values
(Iterable<? extends List<RexLiteral>> tupleList, RelDataType rowType) Creates aValues
with a specified row type.values
(RelDataType rowType) Creates aValues
with a specified row type and zero rows.values
(RelDataType rowType, Object... columnValues) Creates aValues
with a specified row type.variable
(Consumer<RexCorrelVariable> consumer) Creates a correlation variable for the current input, and writes it into a Consumer.Deprecated.<E> E
with
(RelNode r, Function<RelBuilder, E> fn) Evaluates an expression with a relational expression temporarily on the stack.<E> E
withPredicates
(RelMetadataQuery mq, Function<RelBuilder, E> fn) Performs an action using predicates of thecurrent node
to simplify.<E> E
withSimplifier
(BiFunction<RelBuilder, RexSimplify, RexSimplify> simplifierTransform, Function<RelBuilder, E> fn) Performs an action with a temporary simplifier.
-
Field Details
-
cluster
-
relOptSchema
-
-
Constructor Details
-
RelBuilder
protected RelBuilder(@Nullable Context context, RelOptCluster cluster, @Nullable RelOptSchema relOptSchema)
-
-
Method Details
-
create
Creates a RelBuilder. -
transform
Creates a copy of this RelBuilder, with the same state as this, applying a transform to the config. -
let
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
Converts this RelBuilder to a string. The string is the string representation of all of the RelNodes on the stack. -
getTypeFactory
Returns the type factory. -
adoptConvention
Returns new RelBuilder that adopts the convention provided. RelNode will be created with such convention if corresponding factory is provided. -
getRexBuilder
Returns the builder forRexNode
expressions. -
proto
Creates aRelBuilderFactory
, a partially-created RelBuilder. Just add aRelOptCluster
and aRelOptSchema
-
proto
Creates aRelBuilderFactory
that uses a given set of factories. -
getCluster
-
getRelOptSchema
-
getScanFactory
-
push
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
Pushes a collection of relational expressions. -
size
public int size()Returns the size of the stack. -
build
Returns the final relational expression.Throws if the stack is empty.
-
peek
Returns the relational expression at the top of the stack, but does not remove it. -
peek
Returns the relational expressionn
positions from the top of the stack, but does not remove it. -
peek
Returns the relational expressionn
positions from the top of the stack, but does not remove it. -
with
Evaluates an expression with a relational expression temporarily on the stack. -
withSimplifier
public <E> E withSimplifier(BiFunction<RelBuilder, RexSimplify, RexSimplify> simplifierTransform, Function<RelBuilder, E> fn) Performs an action with a temporary simplifier. -
withPredicates
Performs an action using predicates of thecurrent node
to simplify. -
literal
Creates a literal (constant expression). -
variable
Deprecated. -
variable
Creates a correlation variable for the current input, and writes it into a Consumer.Often the Consumer will write to a
Holder
, as follows:RelBuilder builder; builder.scan("EMP") .variable(v::set) .filter(builder.equals(builder.field(0), v.get()))
-
field
Creates a reference to a field by name.Equivalent to
field(1, 0, fieldName)
.- Parameters:
fieldName
- Field name
-
field
Creates a reference to a field of given input relational expression by name.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldName
- Field name
-
field
Creates a reference to an input field by ordinal.Equivalent to
field(1, 0, ordinal)
.- Parameters:
fieldOrdinal
- Field ordinal
-
field
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
Creates a reference to a field of the current record which originated in a relation with a given alias. -
field
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
Returns a reference to a given field (by name, case-insensitive) of a record-valued expression. -
field
Returns a reference to a given field (by ordinal) of a record-valued expression. -
fields
Returns references to the fields of the top input. -
fields
Returns references to the fields of a given input. -
fields
Returns references to fields for a given collation. -
fields
Returns references to fields for a given list of input ordinals. -
fields
Returns references to fields for a given bit set of input ordinals. -
fields
Returns references to fields identified by name. -
fields
Returns references to fields identified by a mapping. -
dot
Creates an access to a field by name. -
dot
Creates an access to a field by ordinal. -
call
Creates a call to a scalar operator. -
call
Creates a call to a scalar operator. -
in
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
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
Creates an IN predicate with a sub-query. -
in
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
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
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
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
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
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
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
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
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
Creates an AND. -
and
Creates an AND.Simplifies the expression a little:
e AND TRUE
becomese
;e AND e2 AND NOT e
becomese2
. -
or
Creates an OR. -
or
Creates an OR. -
not
Creates a NOT. -
equals
Creates an=
. -
greaterThan
Creates a>
. -
greaterThanOrEqual
Creates a>=
. -
lessThan
Creates a<
. -
lessThanOrEqual
Creates a<=
. -
notEquals
Creates a<>
. -
isNotDistinctFrom
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
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
Creates aBETWEEN
. -
isNull
Creates abIS NULL
. -
isNotNull
Creates anIS NOT NULL
. -
cast
Creates an expression that casts an expression to a given type. -
cast
Creates an expression that casts an expression to a given type. -
cast
Creates an expression that casts an expression to a type with a given name and precision or length. -
cast
Creates an expression that casts an expression to a type with a given name and precision or length. -
cast
Creates an expression that casts an expression to a type with a given name, precision and scale. -
cast
Creates an expression that casts an expression to a type with a given name, precision and scale. -
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
Converts a sort expression to descending. -
nullsLast
Converts a sort expression to nulls last. -
nullsFirst
Converts a sort expression to nulls first. -
unboundedPreceding
Creates anUNBOUNDED PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
. -
preceding
Creates abound PRECEDING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
. -
currentRow
Creates aCURRENT ROW
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
. -
following
Creates abound FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
. -
unboundedFollowing
Creates anUNBOUNDED FOLLOWING
window bound, for use in methods such asRelBuilder.OverCall.rowsFrom(RexWindowBound)
andRelBuilder.OverCall.rangeBetween(RexWindowBound, RexWindowBound)
. -
groupKey
Creates an empty group key. -
groupKey
Creates a group key. -
groupKey
Creates a group key. -
groupKey
public RelBuilder.GroupKey groupKey(Iterable<? extends RexNode> nodes, Iterable<? extends Iterable<? extends RexNode>> nodeLists) Creates a group key with grouping sets. -
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(Iterable<? extends RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends RexNode>> nodeLists) Deprecated.Now that indicator is deprecated, usegroupKey(Iterable, Iterable)
, which has the same behavior as calling this method withindicator = false
. -
groupKey
Creates a group key of fields identified by ordinal. -
groupKey
Creates a group key of fields identified by name. -
groupKey
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(ImmutableBitSet groupSet, Iterable<? extends 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(ImmutableBitSet groupSet, boolean indicator, @Nullable com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets) Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, @Nullable String alias, RexNode... operands) Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, @Nullable String alias, RexNode... operands) Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, @Nullable String alias, Iterable<? extends RexNode> operands) Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, @Nullable String alias, Iterable<? extends RexNode> operands) Deprecated. -
aggregateCall
public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, Iterable<? extends 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(SqlParserPos pos, SqlAggFunction aggFunction, Iterable<? extends 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(SqlParserPos pos, SqlAggFunction aggFunction, 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
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
Creates a call to an aggregate function as a copy of anAggregateCall
. -
aggregateCall
Creates a call to an aggregate function as a copy of anAggregateCall
, applying a mapping. -
aggregateCall
protected RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable RexNode filter, @Nullable com.google.common.collect.ImmutableList<RexNode> distinctKeys, com.google.common.collect.ImmutableList<RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<RexNode> preOperands, com.google.common.collect.ImmutableList<RexNode> operands) Creates a call to an aggregate function with all applicable operands. -
aggregateCall
protected RelBuilder.AggCall aggregateCall(SqlParserPos pos, SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable RexNode filter, @Nullable com.google.common.collect.ImmutableList<RexNode> distinctKeys, com.google.common.collect.ImmutableList<RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<RexNode> preOperands, com.google.common.collect.ImmutableList<RexNode> operands) Creates a call to an aggregate function with all applicable operands. -
count
Creates a call to theCOUNT
aggregate function. -
count
Creates a call to theCOUNT
aggregate function. -
count
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 RexNode> operands) Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias. -
countStar
Creates a call to theCOUNT(*)
aggregate function. -
sum
Creates a call to theSUM
aggregate function. -
sum
Creates a call to theSUM
aggregate function. -
sum
Creates a call to theSUM
aggregate function, optionally distinct and with an alias. -
sum
public RelBuilder.AggCall sum(SqlParserPos pos, boolean distinct, @Nullable String alias, RexNode operand) Creates a call to theSUM
aggregate function, optionally distinct and with an alias. -
avg
Creates a call to theAVG
aggregate function. -
avg
Creates a call to theAVG
aggregate function. -
avg
Creates a call to theAVG
aggregate function, optionally distinct and with an alias. -
avg
public RelBuilder.AggCall avg(SqlParserPos pos, boolean distinct, @Nullable String alias, RexNode operand) Creates a call to theAVG
aggregate function, optionally distinct and with an alias. -
min
Creates a call to theMIN
aggregate function. -
min
Creates a call to theMIN
aggregate function, optionally with an alias. -
max
Creates a call to theMAX
aggregate function, optionally with an alias. -
max
Creates a call to theMAX
aggregate function. -
literalAgg
Creates a call to theLITERAL_AGG
aggregate function. -
patternField
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
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
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
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
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
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
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
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
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
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
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
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
Creates aSnapshot
of a given snapshot period.Returns this builder.
- Parameters:
period
- Name of table (can optionally be qualified)
-
cursor
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
Creates aTableFunctionScan
. -
functionScan
public RelBuilder functionScan(SqlOperator operator, int inputCount, Iterable<? extends RexNode> operands) Creates aTableFunctionScan
. -
filter
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
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
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<CorrelationId> variablesSet, Iterable<? extends 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
Creates aProject
of the given expressions. -
project
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 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 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
-
project
public RelBuilder project(Iterable<? extends RexNode> nodes, Iterable<? extends @Nullable String> fieldNames, boolean force, Iterable<CorrelationId> variablesSet) The same withproject(Iterable, Iterable, boolean)
, with additional variablesSet param.- Parameters:
nodes
- ExpressionsfieldNames
- Suggested field namesforce
- create project even if it is identityvariablesSet
- Correlating variables that are set when reading a row from the input, and which may be referenced from the projection expressions
-
projectPlus
Creates aProject
of all original fields, plus the given expressions. -
projectPlus
Creates aProject
of all original fields, plus the given list of expressions. -
projectExcept
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
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 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
-
projectNamed
public RelBuilder projectNamed(Iterable<? extends RexNode> nodes, @Nullable Iterable<? extends @Nullable String> fieldNames, boolean force, Iterable<CorrelationId> variablesSet) 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 trivialvariablesSet
- Correlating variables that are set when reading a row from the input, and which may be referenced from the projection expressions
-
uncollect
Creates anUncollect
with given item aliases.- Parameters:
itemAliases
- Operand item aliases, never nullwithOrdinality
- IfwithOrdinality
, the output contains an extraORDINALITY
column
-
rename
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
Creates anAggregate
that makes the relational expression distinct on all fields. -
aggregate
Creates anAggregate
with an array of calls. -
aggregate
Creates anAggregate
with an array ofAggregateCall
s. -
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls) Creates anAggregate
with multiple calls. -
aggregateRex
-
aggregateRex
public RelBuilder aggregateRex(RelBuilder.GroupKey groupKey, boolean projectKey, Iterable<? extends RexNode> nodes) -
union
Creates aUnion
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create UNION ALL
-
union
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
Creates anIntersect
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create INTERSECT ALL
-
intersect
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
Creates aMinus
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
minus
Creates aMinus
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
transientScan
Creates aTableScan
on aTransientTable
with the given name, using as type the top of the stack's type.- Parameters:
tableName
- table name
-
transientScan
Creates aTableScan
on aTransientTable
with the given name and type.- Parameters:
tableName
- table namerowType
- row type of the table
-
repeatUnion
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
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
-
asofJoin
Creates aLogicalAsofJoin
with the specified conditions. -
join
Creates aJoin
with an array of conditions. -
join
Creates aJoin
with multiple conditions. -
join
Creates aJoin
with one condition. -
join
Creates aJoin
with correlating variables. -
correlate
public RelBuilder correlate(JoinRelType joinType, CorrelationId correlationId, RexNode... requiredFields) Creates aCorrelate
with aCorrelationId
and an array of fields that are used by correlation. -
correlate
public RelBuilder correlate(JoinRelType joinType, CorrelationId correlationId, Iterable<? extends RexNode> requiredFields) Creates aCorrelate
with aCorrelationId
and a list of fields that are used by correlation. -
join
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
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
Creates aJoin
withJoinRelType.SEMI
.- See Also:
-
antiJoin
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
Creates an anti-join.- See Also:
-
as
Assigns a table alias to the top entry on the stack. -
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.The
fieldNames
array must not be null or empty, but may contain null values.If there are zero rows, or if all values of 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
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
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
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
Creates aValues
with a specified row type and zero rows.- Parameters:
rowType
- Row type
-
limit
Creates a limit and/or offset without a sort.- Parameters:
offset
- Number of rows to skip; non-positive means don't skip anyfetch
- Maximum number of rows to fetch; negative means no limit
-
exchange
Creates an Exchange by distribution. -
sortExchange
Creates a SortExchange by distribution and collation. -
sort
Creates aSort
by field ordinals.Negative fields mean descending: -1 means field(0) descending, -2 means field(1) descending, etc.
-
sort
Creates aSort
by expressions. -
sort
Creates aSort
by expressions. -
sortLimit
Creates aSort
by expressions, with limit and offset. -
sort
Creates aSort
by specifying collations. -
sortLimit
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 RexNode offsetNode, @Nullable RexNode fetchNode, Iterable<? extends 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
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
-
sample
public RelBuilder sample(boolean bernoulli, BigDecimal sampleRate, @Nullable Integer repeatableSeed) Creates aSample
. (Repeatable if seed is not null.) -
match
public RelBuilder match(RexNode pattern, boolean strictStart, boolean strictEnd, Map<String, RexNode> patternDefinitions, Iterable<? extends RexNode> measureList, RexNode after, Map<String, ? extends SortedSet<String>> subsets, boolean allRows, Iterable<? extends RexNode> partitionKeys, Iterable<? extends RexNode> orderKeys, RexNode interval) Creates aMatch
. -
pivot
public RelBuilder pivot(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls, Iterable<? extends RexNode> axes, Iterable<? extends Map.Entry<String, ? extends Iterable<? extends 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 RexLiteral>, ? extends List<? extends 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
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
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.
-
groupKey(Iterable, Iterable)
, which has the same behavior as calling this method withindicator = false
.