Class RelBuilder
- java.lang.Object
-
- org.apache.calcite.tools.RelBuilder
-
- Direct Known Subclasses:
PigRelBuilder
public class RelBuilder extends java.lang.Object
Builder for relational expressions.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 aHiveFilter
.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.private class
RelBuilder.AggCallImpl
Implementation ofRelBuilder.AggCall
.private static class
RelBuilder.AggCallImpl2
Implementation ofRelBuilder.AggCall
that wraps anAggregateCall
.private static class
RelBuilder.Field
A field that belongs to a stackRelBuilder.Frame
.private static class
RelBuilder.Frame
Builder stack frame.static interface
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate.protected static class
RelBuilder.GroupKeyImpl
Implementation ofRelBuilder.GroupKey
.private static class
RelBuilder.Registrar
Collects the extra expressions needed foraggregate(org.apache.calcite.tools.RelBuilder.GroupKey, org.apache.calcite.tools.RelBuilder.AggCall...)
.private class
RelBuilder.Shifter
Shuttle that shifts a predicate's inputs to the left, replacing early ones with references to aRexCorrelVariable
.
-
Field Summary
Fields Modifier and Type Field Description private RelFactories.AggregateFactory
aggregateFactory
protected RelOptCluster
cluster
private RelFactories.CorrelateFactory
correlateFactory
private RelFactories.ExchangeFactory
exchangeFactory
private RelFactories.FilterFactory
filterFactory
private RelFactories.JoinFactory
joinFactory
private RelFactories.MatchFactory
matchFactory
private RelFactories.ProjectFactory
projectFactory
protected RelOptSchema
relOptSchema
private RelFactories.TableScanFactory
scanFactory
private RelFactories.SemiJoinFactory
semiJoinFactory
private RelFactories.SetOpFactory
setOpFactory
private RexSimplify
simplifier
private boolean
simplify
private RelFactories.SortExchangeFactory
sortExchangeFactory
private RelFactories.SortFactory
sortFactory
private java.util.Deque<RelBuilder.Frame>
stack
private RelFactories.ValuesFactory
valuesFactory
-
Constructor Summary
Constructors Modifier Constructor Description protected
RelBuilder(Context context, RelOptCluster cluster, RelOptSchema relOptSchema)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RelBuilder
aggregate(RelBuilder.GroupKey groupKey, java.lang.Iterable<RelBuilder.AggCall> aggCalls)
Creates anAggregate
with a list of calls.RelBuilder
aggregate(RelBuilder.GroupKey groupKey, java.util.List<AggregateCall> aggregateCalls)
RelBuilder
aggregate(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls)
Creates anAggregate
with an array of calls.protected RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, com.google.common.collect.ImmutableList<RexNode> orderKeys, java.lang.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, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, java.lang.String alias, RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, java.lang.String alias, RexNode... operands)
Deprecated.RelBuilder.AggCall
aggregateCall(SqlAggFunction aggFunction, java.lang.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, java.lang.String alias)
Returns an expression wrapped in an alias.private boolean
allNull(java.lang.Object[] values, int column, int columnCount)
Returns whether all values for a given column are null.RexNode
and(java.lang.Iterable<? extends RexNode> operands)
Creates an AND.RexNode
and(RexNode... operands)
Creates an AND.RelBuilder
as(java.lang.String alias)
Assigns a table alias to the top entry on the stack.RelBuilder.AggCall
avg(boolean distinct, java.lang.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.RelNode
build()
Returns the final relational expression.RexNode
call(SqlOperator operator, java.lang.Iterable<? extends RexNode> operands)
Creates a call to a scalar operator.private RexNode
call(SqlOperator operator, java.util.List<RexNode> operandList)
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.private static RelFieldCollation
collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, java.util.List<RexNode> extraNodes)
RelBuilder
convert(RelDataType castRowType, boolean rename)
Creates a projection that converts the current relational expression's output to a desired row type.private static <E> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<E>>
copy(java.lang.Iterable<? extends java.util.List<E>> tupleList)
Converts an iterable of lists into an immutable list of immutable lists with the same contents.RelBuilder.AggCall
count(boolean distinct, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(boolean distinct, java.lang.String alias, RexNode... operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.RelBuilder.AggCall
count(java.lang.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(java.lang.String alias)
Creates a call to theCOUNT(*)
aggregate function.static RelBuilder
create(FrameworkConfig config)
Creates a RelBuilder.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, java.lang.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.private RexNode
field(int inputCount, int inputOrdinal, int fieldOrdinal, boolean alias)
Asfield(int, int, int)
, but ifalias
is true, the method may apply an alias to make sure that the field has the same name as in the input frame.RexInputRef
field(int inputCount, int inputOrdinal, java.lang.String fieldName)
Creates a reference to a field of given input relational expression by name.RexNode
field(int inputCount, java.lang.String alias, java.lang.String fieldName)
Creates a reference to a field which originated in a relation with the given alias.RexInputRef
field(java.lang.String fieldName)
Creates a reference to a field by name.RexNode
field(java.lang.String alias, java.lang.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, java.lang.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(java.lang.Iterable<java.lang.String> fieldNames)
Returns references to fields identified by name.com.google.common.collect.ImmutableList<RexNode>
fields(java.util.List<? extends java.lang.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(Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.RelBuilder
filter(java.lang.Iterable<? extends RexNode> predicates)
Creates aFilter
of a list of predicates.RelBuilder
filter(RexNode... predicates)
Creates aFilter
of an array of predicates.RexBuilder
getRexBuilder()
Returns the builder forRexNode
expressions.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(java.lang.Iterable<? extends RexNode> nodes)
Creates a group key.RelBuilder.GroupKey
groupKey(java.lang.Iterable<? extends RexNode> nodes, boolean indicator, java.lang.Iterable<? extends java.lang.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(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<? extends java.lang.Iterable<? extends RexNode>> nodeLists)
Creates a group key with grouping sets.RelBuilder.GroupKey
groupKey(java.lang.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)
RelBuilder.GroupKey
groupKey(ImmutableBitSet groupSet, java.lang.Iterable<? extends ImmutableBitSet> groupSets)
Creates a group key with grouping sets, both identified by field positions in the underlying relational expression.private RelBuilder.GroupKey
groupKey_(java.lang.Iterable<? extends RexNode> nodes, boolean indicator, java.lang.Iterable<? extends java.lang.Iterable<? extends RexNode>> nodeLists)
private RelBuilder.GroupKey
groupKey_(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
private java.lang.String
inferAlias(java.util.List<RexNode> exprList, RexNode expr, int i)
Infers the alias of an expression.private int
inputOffset(int inputCount, int inputOrdinal)
Returns the number of fields in all inputs before (to the left of) the given input.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, java.lang.Iterable<? extends RexNode> conditions)
Creates aJoin
with multiple conditions.RelBuilder
join(JoinRelType joinType, java.lang.String... fieldNames)
Creates aJoin
using USING syntax.RelBuilder
join(JoinRelType joinType, RexNode condition)
RelBuilder
join(JoinRelType joinType, RexNode condition, java.util.Set<CorrelationId> variablesSet)
Creates aJoin
with correlating variables.RelBuilder
join(JoinRelType joinType, RexNode condition0, RexNode... conditions)
Creates aJoin
.RelBuilder
limit(int offset, int fetch)
Creates a limit without a sort.RexNode
literal(java.lang.Object value)
Creates a literal (constant expression).RelBuilder
match(RexNode pattern, boolean strictStart, boolean strictEnd, java.util.Map<java.lang.String,RexNode> patternDefinitions, java.lang.Iterable<? extends RexNode> measureList, RexNode after, java.util.Map<java.lang.String,? extends java.util.SortedSet<java.lang.String>> subsets, boolean allRows, java.lang.Iterable<? extends RexNode> partitionKeys, java.lang.Iterable<? extends RexNode> orderKeys, RexNode interval)
Creates aMatch
.RelBuilder.AggCall
max(java.lang.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(java.lang.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(java.lang.Iterable<? extends RexNode> operands)
Creates an OR.RexNode
or(RexNode... operands)
Creates an OR.RexNode
patternAlter(java.lang.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(java.lang.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(java.lang.String alpha, RelDataType type, int i)
Creates a reference to a given field of the pattern.RexNode
patternPermute(java.lang.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(java.lang.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.private RelBuilder.Frame
peek_()
private RelBuilder.Frame
peek_(int n)
private RelBuilder.Frame
peek_(int inputCount, int inputOrdinal)
RelBuilder
permute(Mapping mapping)
RelBuilder
project(java.lang.Iterable<? extends RexNode> nodes)
Creates aProject
of the given list of expressions.RelBuilder
project(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.String> fieldNames)
Creates aProject
of the given list of expressions and field names.RelBuilder
project(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.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
projectNamed(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.String> fieldNames, boolean force)
Creates aProject
of the given expressions and field names, and optionally optimizing.RelBuilder
projectPlus(java.lang.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(java.lang.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(java.lang.Iterable<? extends RelNode> nodes)
Pushes a collection of relational expressions.RelBuilder
rename(java.util.List<java.lang.String> fieldNames)
Ensures that the field names match those given.private void
replaceTop(RelNode node)
Adds a rel node to the top of the stack while preserving the field names and aliases.RelBuilder
scan(java.lang.Iterable<java.lang.String> tableNames)
Creates aTableScan
of the table with a given name.RelBuilder
scan(java.lang.String... tableNames)
Creates aTableScan
of the table with a given name.RelBuilder
semiJoin(java.lang.Iterable<? extends RexNode> conditions)
Creates aSemiJoin
.RelBuilder
semiJoin(RexNode... conditions)
Creates aSemiJoin
.private RelBuilder
setOp(boolean all, SqlKind kind, int n)
protected boolean
shouldMergeProject()
Whether to attempt to merge consecutiveProject
operators.RelBuilder
sort(int... fields)
Creates aSort
by field ordinals.RelBuilder
sort(java.lang.Iterable<? extends RexNode> nodes)
Creates aSort
by expressions.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, java.lang.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, java.lang.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.java.lang.String
toString()
Converts this RelBuilder to a string.private com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>>
tupleList(int columnCount, java.lang.Object[] values)
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(java.lang.Iterable<? extends java.util.List<RexLiteral>> tupleList, RelDataType rowType)
Creates aValues
with a specified row type.RelBuilder
values(java.lang.String[] fieldNames, java.lang.Object... values)
Creates aValues
.RelBuilder
values(RelDataType rowType)
Creates aValues
with a specified row type and zero rows.RelBuilder
values(RelDataType rowType, java.lang.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 Detail
-
cluster
protected final RelOptCluster cluster
-
relOptSchema
protected final RelOptSchema relOptSchema
-
filterFactory
private final RelFactories.FilterFactory filterFactory
-
projectFactory
private final RelFactories.ProjectFactory projectFactory
-
aggregateFactory
private final RelFactories.AggregateFactory aggregateFactory
-
sortFactory
private final RelFactories.SortFactory sortFactory
-
exchangeFactory
private final RelFactories.ExchangeFactory exchangeFactory
-
sortExchangeFactory
private final RelFactories.SortExchangeFactory sortExchangeFactory
-
setOpFactory
private final RelFactories.SetOpFactory setOpFactory
-
joinFactory
private final RelFactories.JoinFactory joinFactory
-
semiJoinFactory
private final RelFactories.SemiJoinFactory semiJoinFactory
-
correlateFactory
private final RelFactories.CorrelateFactory correlateFactory
-
valuesFactory
private final RelFactories.ValuesFactory valuesFactory
-
scanFactory
private final RelFactories.TableScanFactory scanFactory
-
matchFactory
private final RelFactories.MatchFactory matchFactory
-
stack
private final java.util.Deque<RelBuilder.Frame> stack
-
simplify
private final boolean simplify
-
simplifier
private final RexSimplify simplifier
-
-
Constructor Detail
-
RelBuilder
protected RelBuilder(Context context, RelOptCluster cluster, RelOptSchema relOptSchema)
-
-
Method Detail
-
create
public static RelBuilder create(FrameworkConfig config)
Creates a RelBuilder.
-
toString
public java.lang.String toString()
Converts this RelBuilder to a string. The string is the string representation of all of the RelNodes on the stack.- Overrides:
toString
in classjava.lang.Object
-
getTypeFactory
public RelDataTypeFactory getTypeFactory()
Returns the type factory.
-
getRexBuilder
public RexBuilder getRexBuilder()
Returns the builder forRexNode
expressions.
-
proto
public static RelBuilderFactory proto(Context context)
Creates aRelBuilderFactory
, a partially-created RelBuilder. Just add aRelOptCluster
and aRelOptSchema
-
proto
public static RelBuilderFactory proto(java.lang.Object... factories)
Creates aRelBuilderFactory
that uses a given set of factories.
-
push
public RelBuilder push(RelNode node)
Adds a relational expression to be the input to the next relational expression constructed.This method is usual when you want to weave in relational expressions that are not supported by the builder. If, while creating such expressions, you need to use previously built expressions as inputs, call
build()
to pop those inputs.
-
replaceTop
private void replaceTop(RelNode node)
Adds a rel node to the top of the stack while preserving the field names and aliases.
-
pushAll
public RelBuilder pushAll(java.lang.Iterable<? extends RelNode> nodes)
Pushes a collection of relational expressions.
-
build
public RelNode build()
Returns the final relational expression.Throws if the stack is empty.
-
peek
public RelNode peek()
Returns the relational expression at the top of the stack, but does not remove it.
-
peek_
private RelBuilder.Frame peek_()
-
peek
public RelNode peek(int n)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.
-
peek_
private RelBuilder.Frame peek_(int n)
-
peek
public RelNode peek(int inputCount, int inputOrdinal)
Returns the relational expressionn
positions from the top of the stack, but does not remove it.
-
peek_
private RelBuilder.Frame peek_(int inputCount, int inputOrdinal)
-
inputOffset
private int inputOffset(int inputCount, int inputOrdinal)
Returns the number of fields in all inputs before (to the left of) the given input.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinal
-
literal
public RexNode literal(java.lang.Object value)
Creates a literal (constant expression).
-
variable
public RelBuilder variable(Holder<RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into a Holder.
-
field
public RexInputRef field(java.lang.String fieldName)
Creates a reference to a field by name.Equivalent to
field(1, 0, fieldName)
.- Parameters:
fieldName
- Field name
-
field
public RexInputRef field(int inputCount, int inputOrdinal, java.lang.String fieldName)
Creates a reference to a field of given input relational expression by name.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldName
- Field name
-
field
public RexInputRef field(int fieldOrdinal)
Creates a reference to an input field by ordinal.Equivalent to
field(1, 0, ordinal)
.- Parameters:
fieldOrdinal
- Field ordinal
-
field
public RexInputRef field(int inputCount, int inputOrdinal, int fieldOrdinal)
Creates a reference to a field of a given input relational expression by ordinal.- Parameters:
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldOrdinal
- Field ordinal within input
-
field
private RexNode field(int inputCount, int inputOrdinal, int fieldOrdinal, boolean alias)
Asfield(int, int, int)
, but ifalias
is true, the method may apply an alias to make sure that the field has the same name as in the input frame. If no alias is applied the expression is definitely aRexInputRef
.
-
field
public RexNode field(java.lang.String alias, java.lang.String fieldName)
Creates a reference to a field of the current record which originated in a relation with a given alias.
-
field
public RexNode field(int inputCount, java.lang.String alias, java.lang.String fieldName)
Creates a reference to a field which originated in a relation with the given alias. Searches for the relation starting at the top of the stack.
-
field
public RexNode field(RexNode e, java.lang.String name)
Returns a reference to a given field of a record-valued expression.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields()
Returns references to the fields of the top input.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields(int inputCount, int inputOrdinal)
Returns references to the fields of a given input.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields(RelCollation collation)
Returns references to fields for a given collation.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields(java.util.List<? extends java.lang.Number> ordinals)
Returns references to fields for a given list of input ordinals.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields(java.lang.Iterable<java.lang.String> fieldNames)
Returns references to fields identified by name.
-
fields
public com.google.common.collect.ImmutableList<RexNode> fields(Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.
-
dot
public RexNode dot(RexNode node, java.lang.String fieldName)
Creates an access to a field by name.
-
call
public RexNode call(SqlOperator operator, RexNode... operands)
Creates a call to a scalar operator.
-
call
private RexNode call(SqlOperator operator, java.util.List<RexNode> operandList)
Creates a call to a scalar operator.
-
call
public RexNode call(SqlOperator operator, java.lang.Iterable<? extends RexNode> operands)
Creates a call to a scalar operator.
-
and
public RexNode and(java.lang.Iterable<? extends RexNode> operands)
Creates an AND.Simplifies the expression a little:
e AND TRUE
becomese
;e AND e2 AND NOT e
becomese2
.
-
cast
public RexNode cast(RexNode expr, SqlTypeName typeName)
Creates an expression that casts an expression to a given type.
-
cast
public 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.
-
cast
public 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.
-
alias
public RexNode alias(RexNode expr, java.lang.String alias)
Returns an expression wrapped in an alias.
-
groupKey
public RelBuilder.GroupKey groupKey()
Creates an empty group key.
-
groupKey
public RelBuilder.GroupKey groupKey(RexNode... nodes)
Creates a group key.
-
groupKey
public RelBuilder.GroupKey groupKey(java.lang.Iterable<? extends RexNode> nodes)
Creates a group key.
-
groupKey
public RelBuilder.GroupKey groupKey(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<? extends java.lang.Iterable<? extends RexNode>> nodeLists)
Creates a group key with grouping sets.
-
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(java.lang.Iterable<? extends RexNode> nodes, boolean indicator, java.lang.Iterable<? extends java.lang.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_
private RelBuilder.GroupKey groupKey_(java.lang.Iterable<? extends RexNode> nodes, boolean indicator, java.lang.Iterable<? extends java.lang.Iterable<? extends RexNode>> nodeLists)
-
groupKey
public RelBuilder.GroupKey groupKey(int... fieldOrdinals)
Creates a group key of fields identified by ordinal.
-
groupKey
public RelBuilder.GroupKey groupKey(java.lang.String... fieldNames)
Creates a group key of fields identified by name.
-
groupKey
public RelBuilder.GroupKey groupKey(@Nonnull ImmutableBitSet groupSet)
Creates a group key, identified by field positions in the underlying relational expression.This method of creating a group key does not allow you to group on new expressions, only column projections, but is efficient, especially when you are coming from an existing
Aggregate
.
-
groupKey
public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, @Nonnull java.lang.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
public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
-
groupKey
@Deprecated public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
Deprecated.
-
groupKey_
private RelBuilder.GroupKey groupKey_(ImmutableBitSet groupSet, boolean indicator, @Nonnull com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, java.lang.String alias, RexNode... operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, java.lang.String alias, RexNode... operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Deprecated.
-
aggregateCall
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Deprecated.
-
aggregateCall
public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, java.lang.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(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
protected RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, com.google.common.collect.ImmutableList<RexNode> orderKeys, java.lang.String alias, com.google.common.collect.ImmutableList<RexNode> operands)
Creates a call to an aggregate function with all applicable operands.
-
count
public RelBuilder.AggCall count(RexNode... operands)
Creates a call to theCOUNT
aggregate function.
-
count
public RelBuilder.AggCall count(java.lang.Iterable<? extends RexNode> operands)
Creates a call to theCOUNT
aggregate function.
-
count
public RelBuilder.AggCall count(boolean distinct, java.lang.String alias, RexNode... operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.
-
count
public RelBuilder.AggCall count(boolean distinct, java.lang.String alias, java.lang.Iterable<? extends RexNode> operands)
Creates a call to theCOUNT
aggregate function, optionally distinct and with an alias.
-
countStar
public RelBuilder.AggCall countStar(java.lang.String alias)
Creates a call to theCOUNT(*)
aggregate function.
-
sum
public RelBuilder.AggCall sum(RexNode operand)
Creates a call to theSUM
aggregate function.
-
sum
public RelBuilder.AggCall sum(boolean distinct, java.lang.String alias, RexNode operand)
Creates a call to theSUM
aggregate function, optionally distinct and with an alias.
-
avg
public RelBuilder.AggCall avg(RexNode operand)
Creates a call to theAVG
aggregate function.
-
avg
public RelBuilder.AggCall avg(boolean distinct, java.lang.String alias, RexNode operand)
Creates a call to theAVG
aggregate function, optionally distinct and with an alias.
-
min
public RelBuilder.AggCall min(RexNode operand)
Creates a call to theMIN
aggregate function.
-
min
public RelBuilder.AggCall min(java.lang.String alias, RexNode operand)
Creates a call to theMIN
aggregate function, optionally with an alias.
-
max
public RelBuilder.AggCall max(RexNode operand)
Creates a call to theMAX
aggregate function, optionally with an alias.
-
max
public RelBuilder.AggCall max(java.lang.String alias, RexNode operand)
Creates a call to theMAX
aggregate function.
-
patternField
public RexNode patternField(java.lang.String alpha, RelDataType type, int i)
Creates a reference to a given field of the pattern.- Parameters:
alpha
- the pattern nametype
- Type of fieldi
- Ordinal of field- Returns:
- Reference to field of pattern
-
patternConcat
public RexNode patternConcat(java.lang.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
public 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)
.
-
patternAlter
public RexNode patternAlter(java.lang.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
public 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)
.
-
patternQuantify
public RexNode patternQuantify(java.lang.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
public 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)
.
-
patternPermute
public RexNode patternPermute(java.lang.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
public 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)
.
-
patternExclude
public 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)
.
-
scan
public RelBuilder scan(java.lang.Iterable<java.lang.String> tableNames)
Creates aTableScan
of the table with a given name.Throws if the table does not exist.
Returns this builder.
- Parameters:
tableNames
- Name of table (can optionally be qualified)
-
scan
public RelBuilder scan(java.lang.String... tableNames)
Creates aTableScan
of the table with a given name.Throws if the table does not exist.
Returns this builder.
- Parameters:
tableNames
- Name of table (can optionally be qualified)
-
filter
public RelBuilder filter(RexNode... predicates)
Creates aFilter
of an array of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If the result is TRUE no filter is created.
-
filter
public RelBuilder filter(java.lang.Iterable<? extends RexNode> predicates)
Creates aFilter
of a list of predicates.The predicates are combined using AND, and optimized in a similar way to the
and(org.apache.calcite.rex.RexNode...)
method. If the result is TRUE no filter is created.
-
project
public RelBuilder project(RexNode... nodes)
Creates aProject
of the given expressions.
-
project
public RelBuilder project(java.lang.Iterable<? extends RexNode> nodes)
Creates aProject
of the given list of expressions.Infers names as would
project(Iterable, Iterable)
if all suggested names were null.- Parameters:
nodes
- Expressions
-
project
public RelBuilder project(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.String> fieldNames)
Creates aProject
of the given list of expressions and field names.- Parameters:
nodes
- ExpressionsfieldNames
- field names for expressions
-
projectPlus
public RelBuilder projectPlus(RexNode... nodes)
Creates aProject
of all original fields, plus the given expressions.
-
projectPlus
public RelBuilder projectPlus(java.lang.Iterable<RexNode> nodes)
Creates aProject
of all original fields, plus the given list of expressions.
-
project
public RelBuilder project(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.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
-
shouldMergeProject
protected boolean shouldMergeProject()
Whether to attempt to merge consecutiveProject
operators.The default implementation returns
true
; sub-classes may disable merge by overriding to returnfalse
.
-
projectNamed
public RelBuilder projectNamed(java.lang.Iterable<? extends RexNode> nodes, java.lang.Iterable<java.lang.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
-
rename
public RelBuilder rename(java.util.List<java.lang.String> fieldNames)
Ensures that the field names match those given.If all fields have the same name, adds nothing; if any fields do not have the same name, adds a
Project
.Note that the names can be short-lived. Other
RelBuilder
operations make no guarantees about the field names of the rows they produce.- Parameters:
fieldNames
- List of desired field names; may contain null values or have fewer fields than the current row type
-
inferAlias
private java.lang.String inferAlias(java.util.List<RexNode> exprList, RexNode expr, int i)
Infers the alias of an expression.If the expression was created by
alias(org.apache.calcite.rex.RexNode, java.lang.String)
, replaces the expression in the project list.
-
distinct
public RelBuilder distinct()
Creates anAggregate
that makes the relational expression distinct on all fields.
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls)
Creates anAggregate
with an array of calls.
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, java.lang.Iterable<RelBuilder.AggCall> aggCalls)
Creates anAggregate
with a list of calls.
-
setOp
private RelBuilder setOp(boolean all, SqlKind kind, int n)
-
union
public RelBuilder union(boolean all)
Creates aUnion
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create UNION ALL
-
union
public RelBuilder union(boolean all, int n)
Creates aUnion
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create UNION ALLn
- Number of inputs to the UNION operator
-
intersect
public RelBuilder intersect(boolean all)
Creates anIntersect
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create INTERSECT ALL
-
intersect
public RelBuilder intersect(boolean all, int n)
Creates anIntersect
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create INTERSECT ALLn
- Number of inputs to the INTERSECT operator
-
minus
public RelBuilder minus(boolean all)
Creates aMinus
of the two most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
minus
public RelBuilder minus(boolean all, int n)
Creates aMinus
of then
most recent relational expressions on the stack.- Parameters:
all
- Whether to create EXCEPT ALL
-
join
public RelBuilder join(JoinRelType joinType, RexNode condition0, RexNode... conditions)
Creates aJoin
.
-
join
public RelBuilder join(JoinRelType joinType, java.lang.Iterable<? extends RexNode> conditions)
Creates aJoin
with multiple conditions.
-
join
public RelBuilder join(JoinRelType joinType, RexNode condition)
-
join
public RelBuilder join(JoinRelType joinType, RexNode condition, java.util.Set<CorrelationId> variablesSet)
Creates aJoin
with correlating variables.
-
join
public RelBuilder join(JoinRelType joinType, java.lang.String... fieldNames)
Creates aJoin
using USING syntax.For each of the field names, both left and right inputs must have a field of that name. Constructs a join condition that the left and right fields are equal.
- Parameters:
joinType
- Join typefieldNames
- Field names
-
semiJoin
public RelBuilder semiJoin(java.lang.Iterable<? extends RexNode> conditions)
Creates aSemiJoin
.
-
semiJoin
public RelBuilder semiJoin(RexNode... conditions)
Creates aSemiJoin
.
-
as
public RelBuilder as(java.lang.String alias)
Assigns a table alias to the top entry on the stack.
-
values
public RelBuilder values(java.lang.String[] fieldNames, java.lang.Object... values)
Creates aValues
.The
values
array must have the same number of entries asfieldNames
, or an integer multiple if you wish to create multiple rows.If there are zero rows, or if all values of a any column are null, this method cannot deduce the type of columns. For these cases, call
values(Iterable, RelDataType)
.- Parameters:
fieldNames
- Field namesvalues
- Values
-
tupleList
private com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>> tupleList(int columnCount, java.lang.Object[] values)
-
allNull
private boolean allNull(java.lang.Object[] values, int column, int columnCount)
Returns whether all values for a given column are null.
-
empty
public RelBuilder empty()
Creates a relational expression that reads from an input and throws all of the rows away.Note that this method always pops one relational expression from the stack.
values
, in contrast, does not pop any relational expressions, and always produces a leaf.The default implementation creates a
Values
with the same specified row type as the input, and ignores the input entirely. But schema-on-query systems such as Drill might override this method to create a relation expression that retains the input, just to read its schema.
-
values
public RelBuilder values(RelDataType rowType, java.lang.Object... columnValues)
Creates aValues
with a specified row type.This method can handle cases that
values(String[], Object...)
cannot, such as all values of a column being null, or there being zero rows.- Parameters:
rowType
- Row typecolumnValues
- Values
-
values
public RelBuilder values(java.lang.Iterable<? extends java.util.List<RexLiteral>> tupleList, RelDataType rowType)
Creates aValues
with a specified row type.This method can handle cases that
values(String[], Object...)
cannot, such as all values of a column being null, or there being zero rows.- Parameters:
tupleList
- Tuple listrowType
- Row type
-
values
public RelBuilder values(RelDataType rowType)
Creates aValues
with a specified row type and zero rows.- Parameters:
rowType
- Row type
-
copy
private static <E> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<E>> copy(java.lang.Iterable<? extends java.util.List<E>> tupleList)
Converts an iterable of lists into an immutable list of immutable lists with the same contents. Returns the same object if possible.
-
limit
public RelBuilder limit(int offset, int fetch)
Creates a limit without a sort.
-
exchange
public RelBuilder exchange(RelDistribution distribution)
Creates an Exchange by distribution.
-
sortExchange
public RelBuilder sortExchange(RelDistribution distribution, RelCollation collation)
Creates a SortExchange by distribution and collation.
-
sort
public RelBuilder sort(int... fields)
Creates aSort
by field ordinals.Negative fields mean descending: -1 means field(0) descending, -2 means field(1) descending, etc.
-
sort
public RelBuilder sort(RexNode... nodes)
Creates aSort
by expressions.
-
sort
public RelBuilder sort(java.lang.Iterable<? extends RexNode> nodes)
Creates aSort
by expressions.
-
sortLimit
public RelBuilder sortLimit(int offset, int fetch, RexNode... nodes)
Creates aSort
by expressions, with limit and offset.
-
sortLimit
public RelBuilder sortLimit(int offset, int fetch, java.lang.Iterable<? extends RexNode> nodes)
Creates aSort
by a list of expressions, with limit and offset.- Parameters:
offset
- Number of rows to skip; non-positive means don't skip anyfetch
- Maximum number of rows to fetch; negative means no limitnodes
- Sort expressions
-
collation
private static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, java.util.List<RexNode> extraNodes)
-
convert
public RelBuilder convert(RelDataType castRowType, boolean rename)
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
public RelBuilder permute(Mapping mapping)
-
aggregate
public RelBuilder aggregate(RelBuilder.GroupKey groupKey, java.util.List<AggregateCall> aggregateCalls)
-
match
public RelBuilder match(RexNode pattern, boolean strictStart, boolean strictEnd, java.util.Map<java.lang.String,RexNode> patternDefinitions, java.lang.Iterable<? extends RexNode> measureList, RexNode after, java.util.Map<java.lang.String,? extends java.util.SortedSet<java.lang.String>> subsets, boolean allRows, java.lang.Iterable<? extends RexNode> partitionKeys, java.lang.Iterable<? extends RexNode> orderKeys, RexNode interval)
Creates aMatch
.
-
clear
public void clear()
Clears the stack.The builder's state is now the same as when it was created.
-
-