Class RelBuilder
- Direct Known Subclasses:
PigRelBuilder
,PigRelBuilder
public class RelBuilder extends Object
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
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 class
RelBuilder.ConfigBuilder
Deprecated.Use thewithXxx
methods inRelBuilder.Config
.static interface
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate. -
Field Summary
Fields Modifier and Type Field Description protected RelOptCluster
cluster
protected RelOptSchema
relOptSchema
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelBuilder(Context context, RelOptCluster cluster, RelOptSchema relOptSchema)
-
Method Summary
Modifier and Type Method Description RelBuilder
adoptConvention(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<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(AggregateCall a)
Creates a call to an aggregate function as a copy of anAggregateCall
.RelBuilder.AggCall
aggregateCall(AggregateCall a, Mapping mapping)
Creates a call to an aggregate function as a copy of anAggregateCall
, applying a mapping.protected RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, RexNode filter, com.google.common.collect.ImmutableList<RexNode> orderKeys, String alias, com.google.common.collect.ImmutableList<RexNode> operands)
Creates a call to an aggregate function with all applicable operands.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, Iterable<? extends RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, Iterable<? extends RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, Iterable<? extends RexNode> operands)
Creates a call to an aggregate function.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, RexNode... operands)
Creates a call to an aggregate function.RexNode
alias(RexNode expr, String alias)
Returns an expression wrapped in an alias.RexNode
and(Iterable<? extends RexNode> operands)
Creates an AND.RexNode
and(RexNode... operands)
Creates an AND.RelBuilder
antiJoin(Iterable<? extends RexNode> conditions)
Creates an anti-join.RelBuilder
antiJoin(RexNode... conditions)
Creates an anti-join.RelBuilder
as(String alias)
Assigns a table alias to the top entry on the stack.RelBuilder.AggCall
avg(boolean distinct, String alias, RexNode operand)
Creates a call to theAVG
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
avg(RexNode operand)
Creates a call to theAVG
aggregate function.RexNode
between(RexNode arg, RexNode lower, RexNode upper)
Creates aBETWEEN
.RelNode
build()
Returns the final relational expression.RexNode
call(SqlOperator operator, Iterable<? extends RexNode> operands)
Creates a call to a scalar operator.RexNode
call(SqlOperator operator, RexNode... operands)
Creates a call to a scalar operator.RexNode
cast(RexNode expr, SqlTypeName typeName)
Creates an expression that casts an expression to a given type.RexNode
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.RexNode
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.void
clear()
Clears the stack.RelBuilder
convert(RelDataType castRowType, boolean rename)
Creates a projection that converts the current relational expression's output to a desired row type.RelBuilder
correlate(JoinRelType joinType, CorrelationId correlationId, Iterable<? extends RexNode> requiredFields)
Creates aCorrelate
with aCorrelationId
and a list of fields that are used by correlation.RelBuilder
correlate(JoinRelType joinType, CorrelationId correlationId, RexNode... requiredFields)
Creates aCorrelate
with aCorrelationId
and an array of fields that are used by correlation.RelBuilder.AggCall
count(boolean distinct, String alias, Iterable<? extends RexNode> operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(boolean distinct, String alias, RexNode... operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(Iterable<? extends RexNode> operands)
Creates a call to theCOUNT
aggregate function.RelBuilder.AggCall
count(RexNode... operands)
Creates a call to theCOUNT
aggregate function.RelBuilder.AggCall
countStar(String alias)
Creates a call to theCOUNT(*)
aggregate function.static RelBuilder
create(FrameworkConfig config)
Creates a RelBuilder.RexNode
cursor(int inputCount, int ordinal)
Creates a RexCall to theCURSOR
function by ordinal.RexNode
desc(RexNode node)
Converts a sort expression to descending.RelBuilder
distinct()
Creates anAggregate
that makes the relational expression distinct on all fields.RexNode
dot(RexNode node, int fieldOrdinal)
Creates an access to a field by ordinal.RexNode
dot(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.RexNode
equals(RexNode operand0, RexNode operand1)
Creates an=
.RelBuilder
exchange(RelDistribution distribution)
Creates an Exchange by distribution.RexInputRef
field(int fieldOrdinal)
Creates a reference to an input field by ordinal.RexInputRef
field(int inputCount, int inputOrdinal, int fieldOrdinal)
Creates a reference to a field of a given input relational expression by ordinal.RexInputRef
field(int inputCount, int inputOrdinal, String fieldName)
Creates a reference to a field of given input relational expression by name.RexNode
field(int inputCount, String alias, String fieldName)
Creates a reference to a field which originated in a relation with the given alias.RexInputRef
field(String fieldName)
Creates a reference to a field by name.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.RexNode
field(RexNode e, String name)
Returns a reference to a given field 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>
fields(Iterable<String> fieldNames)
Returns references to fields identified by name.com.google.common.collect.ImmutableList<RexNode>
fields(List<? extends Number> ordinals)
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.RelBuilder
filter(Iterable<? extends RexNode> predicates)
Creates aFilter
of a list of predicates.RelBuilder
filter(Iterable<CorrelationId> variablesSet, Iterable<? extends RexNode> predicates)
Creates aFilter
of a list of correlation variables and a list of predicates.RelBuilder
filter(Iterable<CorrelationId> variablesSet, RexNode... predicates)
Creates aFilter
of a list of correlation variables and an array of predicates.RelBuilder
filter(RexNode... predicates)
Creates aFilter
of an array of predicates.RelBuilder
functionScan(SqlOperator operator, int inputCount, Iterable<? extends RexNode> operands)
Creates aTableFunctionScan
.RelBuilder
functionScan(SqlOperator operator, int inputCount, RexNode... operands)
Creates aTableFunctionScan
.RelOptCluster
getCluster()
RelOptSchema
getRelOptSchema()
RexBuilder
getRexBuilder()
Returns the builder forRexNode
expressions.RelFactories.TableScanFactory
getScanFactory()
RelDataTypeFactory
getTypeFactory()
Returns the type factory.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 RexNode> nodes)
Creates a group key.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
.RelBuilder.GroupKey
groupKey(Iterable<? extends RexNode> nodes, Iterable<? extends Iterable<? extends 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(RexNode... nodes)
Creates a group key.RelBuilder.GroupKey
groupKey(ImmutableBitSet groupSet)
Creates a group key, identified by field positions in the underlying relational expression.RelBuilder.GroupKey
groupKey(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
Deprecated.RelBuilder.GroupKey
groupKey(ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
Deprecated.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.RelBuilder
hints(Iterable<RelHint> hints)
Attaches multiple hints to the stack top relational expression.RelBuilder
hints(RelHint... hints)
Attaches an array of hints to the stack top relational expression.RexNode
in(RexNode arg, Iterable<? extends RexNode> ranges)
Creates an IN.RexNode
in(RexNode arg, RexNode... ranges)
Creates an IN.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.RexNode
isNotNull(RexNode operand)
Creates a IS NOT NULL.RexNode
isNull(RexNode operand)
Creates a IS NULL.RelBuilder
join(JoinRelType joinType, Iterable<? extends RexNode> conditions)
Creates aJoin
with multiple conditions.RelBuilder
join(JoinRelType joinType, String... fieldNames)
Creates aJoin
using USING syntax.RelBuilder
join(JoinRelType joinType, RexNode condition)
Creates aJoin
with one condition.RelBuilder
join(JoinRelType joinType, RexNode condition, Set<CorrelationId> variablesSet)
Creates aJoin
with correlating variables.RelBuilder
join(JoinRelType joinType, RexNode condition0, RexNode... conditions)
Creates aJoin
with an array of conditions.RelBuilder
limit(int offset, int fetch)
Creates a limit without a sort.RexNode
literal(Object value)
Creates a literal (constant expression).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
.RelBuilder.AggCall
max(String alias, RexNode operand)
Creates a call to theMAX
aggregate function.RelBuilder.AggCall
max(RexNode operand)
Creates a call to theMAX
aggregate function, optionally with an alias.RelBuilder.AggCall
min(String alias, RexNode operand)
Creates a call to theMIN
aggregate function, optionally with an alias.RelBuilder.AggCall
min(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.RexNode
not(RexNode operand)
Creates a NOT.RexNode
notEquals(RexNode operand0, RexNode operand1)
Creates a<>
.RexNode
nullsFirst(RexNode node)
Converts a sort expression to nulls first.RexNode
nullsLast(RexNode node)
Converts a sort expression to nulls last.RexNode
or(Iterable<? extends RexNode> operands)
Creates an OR.RexNode
or(RexNode... operands)
Creates an OR.RexNode
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)
.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)
.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)
.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)
.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)
.RexNode
patternField(String alpha, RelDataType type, int i)
Creates a reference to a given field of the pattern.RexNode
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)
.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)
.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)
.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)
.RelNode
peek()
Returns the relational expression at the top of the stack, but does not remove it.RelNode
peek(int n)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.RelNode
peek(int inputCount, int inputOrdinal)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.RelBuilder
permute(Mapping mapping)
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.RelBuilder
project(Iterable<? extends RexNode> nodes)
Creates aProject
of the given list of expressions.RelBuilder
project(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames)
Creates aProject
of the given list of expressions and field names.RelBuilder
project(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames, boolean force)
Creates aProject
of the given list of expressions, using the given names.RelBuilder
project(RexNode... nodes)
Creates aProject
of the given expressions.RelBuilder
projectExcept(Iterable<RexNode> expressions)
Creates aProject
of all original fields, except the given list of expressions.RelBuilder
projectExcept(RexNode... expressions)
Creates aProject
of all original fields, except the given expressions.RelBuilder
projectNamed(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames, boolean force)
Creates aProject
of the given expressions and field names, and optionally optimizing.RelBuilder
projectPlus(Iterable<RexNode> nodes)
Creates aProject
of all original fields, plus the given list of expressions.RelBuilder
projectPlus(RexNode... nodes)
Creates aProject
of all original fields, plus the given expressions.static RelBuilderFactory
proto(Object... factories)
Creates aRelBuilderFactory
that uses a given set of factories.static RelBuilderFactory
proto(Context context)
Creates aRelBuilderFactory
, a partially-created RelBuilder.RelBuilder
push(RelNode node)
Adds a relational expression to be the input to the next relational expression constructed.RelBuilder
pushAll(Iterable<? extends RelNode> nodes)
Pushes a collection of relational expressions.RelBuilder
rename(List<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.RelBuilder
repeatUnion(String tableName, boolean all, int iterationLimit)
Creates aRepeatUnion
associated to aTransientTable
of the two most recent relational expressions on the stack.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 RexNode> conditions)
Creates aJoin
withJoinRelType.SEMI
.RelBuilder
semiJoin(RexNode... conditions)
Creates aJoin
withJoinRelType.SEMI
.RelBuilder
snapshot(RexNode period)
Creates aSnapshot
of a given snapshot period.RelBuilder
sort(int... fields)
Creates aSort
by field ordinals.RelBuilder
sort(Iterable<? extends RexNode> nodes)
Creates aSort
by expressions.RelBuilder
sort(RelCollation collation)
Creates aSort
by specifying collations.RelBuilder
sort(RexNode... nodes)
Creates aSort
by expressions.RelBuilder
sortExchange(RelDistribution distribution, RelCollation collation)
Creates a SortExchange by distribution and collation.RelBuilder
sortLimit(int offset, int fetch, Iterable<? extends RexNode> nodes)
Creates aSort
by a list of expressions, with limit and offset.RelBuilder
sortLimit(int offset, int fetch, RexNode... nodes)
Creates aSort
by expressions, with limit and offset.RelBuilder.AggCall
sum(boolean distinct, String alias, RexNode operand)
Creates a call to theSUM
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
sum(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, RelDataType rowType)
Creates aTableScan
on aTransientTable
with the given name and type.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.RelBuilder
values(Iterable<? extends List<RexLiteral>> tupleList, RelDataType rowType)
Creates aValues
with a specified row type.RelBuilder
values(String[] fieldNames, Object... values)
Creates aValues
.RelBuilder
values(RelDataType rowType)
Creates aValues
with a specified row type and zero rows.RelBuilder
values(RelDataType rowType, Object... columnValues)
Creates aValues
with a specified row type.RelBuilder
variable(Holder<RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into a Holder.
-
Field Details
-
Constructor Details
-
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. -
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. -
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. -
literal
Creates a literal (constant expression). -
variable
Creates a correlation variable for the current input, and writes it into a Holder. -
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 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. -
in
Creates an IN. -
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=
. -
notEquals
Creates a<>
. -
between
Creates aBETWEEN
. -
isNull
Creates a IS NULL. -
isNotNull
Creates a IS NOT NULL. -
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, 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. -
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, @Nonnull 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
. -
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)Deprecated. -
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, RexNode... operands)Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, RexNode... operands)Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, Iterable<? extends RexNode> operands)Deprecated. -
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, 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
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, RexNode filter, com.google.common.collect.ImmutableList<RexNode> orderKeys, String alias, 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, 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, optionally distinct and with an alias. -
avg
Creates a call to theAVG
aggregate function. -
avg
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. -
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 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
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<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
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, Iterable<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
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
Creates anAggregate
with multiple calls. -
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
-
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:
semiJoin(Iterable)
-
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:
antiJoin(Iterable)
-
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.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
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 without a sort. -
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
-
convert
Creates a projection that converts the current relational expression's output to a desired row type.- Parameters:
castRowType
- row type after castrename
- if true, use field names from castRowType; if false, preserve field names from rel
-
permute
-
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
-
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.
-