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.
| Modifier and Type | Class and 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 the
withXxx methods in
RelBuilder.Config. |
static interface |
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate.
|
| Modifier and Type | Field and Description |
|---|---|
protected RelOptCluster |
cluster |
protected RelOptSchema |
relOptSchema |
| Modifier | Constructor and Description |
|---|---|
protected |
RelBuilder(Context context,
RelOptCluster cluster,
RelOptSchema relOptSchema) |
| Modifier and Type | Method and Description |
|---|---|
RelBuilder |
adoptConvention(Convention convention)
Returns new RelBuilder that adopts the convention provided.
|
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
Iterable<RelBuilder.AggCall> aggCalls)
Creates an
Aggregate with multiple calls. |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
List<AggregateCall> aggregateCalls)
Creates an
Aggregate with an array of
AggregateCalls. |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
RelBuilder.AggCall... aggCalls)
Creates an
Aggregate with an array of
calls. |
RelBuilder.AggCall |
aggregateCall(AggregateCall a)
Creates a call to an aggregate function as a copy of an
AggregateCall. |
RelBuilder.AggCall |
aggregateCall(AggregateCall a,
Mapping mapping)
Creates a call to an aggregate function as a copy of an
AggregateCall, 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 the
AVG aggregate function,
optionally distinct and with an alias. |
RelBuilder.AggCall |
avg(RexNode operand)
Creates a call to the
AVG aggregate function. |
RexNode |
between(RexNode arg,
RexNode lower,
RexNode upper)
Creates a
BETWEEN. |
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 a
Correlate
with a CorrelationId and a list of fields that are used by correlation. |
RelBuilder |
correlate(JoinRelType joinType,
CorrelationId correlationId,
RexNode... requiredFields)
Creates a
Correlate
with a CorrelationId 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 the
COUNT aggregate function,
optionally distinct and with an alias. |
RelBuilder.AggCall |
count(boolean distinct,
String alias,
RexNode... operands)
Creates a call to the
COUNT aggregate function,
optionally distinct and with an alias. |
RelBuilder.AggCall |
count(Iterable<? extends RexNode> operands)
Creates a call to the
COUNT aggregate function. |
RelBuilder.AggCall |
count(RexNode... operands)
Creates a call to the
COUNT aggregate function. |
RelBuilder.AggCall |
countStar(String alias)
Creates a call to the
COUNT(*) aggregate function. |
static RelBuilder |
create(FrameworkConfig config)
Creates a RelBuilder.
|
RexNode |
cursor(int inputCount,
int ordinal)
Creates a RexCall to the
CURSOR function by ordinal. |
RexNode |
desc(RexNode node)
Converts a sort expression to descending.
|
RelBuilder |
distinct()
Creates an
Aggregate 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.
|
RexNode |
field(RexNode e,
String name)
Returns a reference to a given field of a record-valued expression.
|
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.
|
com.google.common.collect.ImmutableList<RexNode> |
fields()
Returns references to the fields of the top input.
|
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(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(Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.
|
com.google.common.collect.ImmutableList<RexNode> |
fields(RelCollation collation)
Returns references to fields for a given collation.
|
RelBuilder |
filter(Iterable<? extends RexNode> predicates)
Creates a
Filter of a list of
predicates. |
RelBuilder |
filter(Iterable<CorrelationId> variablesSet,
Iterable<? extends RexNode> predicates)
Creates a
Filter of a list of correlation variables
and a list of predicates. |
RelBuilder |
filter(Iterable<CorrelationId> variablesSet,
RexNode... predicates)
Creates a
Filter of a list of correlation variables
and an array of predicates. |
RelBuilder |
filter(RexNode... predicates)
Creates a
Filter of an array of
predicates. |
RelBuilder |
functionScan(SqlOperator operator,
int inputCount,
Iterable<? extends RexNode> operands)
Creates a
TableFunctionScan. |
RelBuilder |
functionScan(SqlOperator operator,
int inputCount,
RexNode... operands)
Creates a
TableFunctionScan. |
RelOptCluster |
getCluster() |
RelOptSchema |
getRelOptSchema() |
RexBuilder |
getRexBuilder()
Returns the builder for
RexNode expressions. |
RelFactories.TableScanFactory |
getScanFactory() |
RelDataTypeFactory |
getTypeFactory()
Returns the type factory.
|
RelBuilder.GroupKey |
groupKey()
Creates an empty 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.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, use
groupKey(Iterable, Iterable), which has the same behavior as
calling this method with indicator = false. |
RelBuilder.GroupKey |
groupKey(Iterable<? extends RexNode> nodes,
Iterable<? extends Iterable<? extends RexNode>> nodeLists)
Creates a group key with grouping sets.
|
RelBuilder.GroupKey |
groupKey(RexNode... nodes)
Creates a group key.
|
RelBuilder.GroupKey |
groupKey(String... fieldNames)
Creates a group key of fields identified by name.
|
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 an
Intersect of the two most
recent relational expressions on the stack. |
RelBuilder |
intersect(boolean all,
int n)
Creates an
Intersect of the n
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 a
Join with multiple
conditions. |
RelBuilder |
join(JoinRelType joinType,
RexNode condition)
Creates a
Join with one condition. |
RelBuilder |
join(JoinRelType joinType,
RexNode condition0,
RexNode... conditions)
Creates a
Join with an array of conditions. |
RelBuilder |
join(JoinRelType joinType,
RexNode condition,
Set<CorrelationId> variablesSet)
Creates a
Join with correlating variables. |
RelBuilder |
join(JoinRelType joinType,
String... fieldNames)
Creates a
Join using USING syntax. |
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 a
Match. |
RelBuilder.AggCall |
max(RexNode operand)
Creates a call to the
MAX aggregate function,
optionally with an alias. |
RelBuilder.AggCall |
max(String alias,
RexNode operand)
Creates a call to the
MAX aggregate function. |
RelBuilder.AggCall |
min(RexNode operand)
Creates a call to the
MIN aggregate function. |
RelBuilder.AggCall |
min(String alias,
RexNode operand)
Creates a call to the
MIN aggregate function,
optionally with an alias. |
RelBuilder |
minus(boolean all)
Creates a
Minus of the two most recent
relational expressions on the stack. |
RelBuilder |
minus(boolean all,
int n)
Creates a
Minus of the n
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 in
match(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 in
match(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 in
match(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 in
match(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 in
match(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 in
match(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 in
match(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 in
match(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 in
match(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 expression
n positions from the top of the
stack, but does not remove it. |
RelNode |
peek(int inputCount,
int inputOrdinal)
Returns the relational expression
n 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 a
Project of the given list
of expressions. |
RelBuilder |
project(Iterable<? extends RexNode> nodes,
Iterable<String> fieldNames)
Creates a
Project of the given list
of expressions and field names. |
RelBuilder |
project(Iterable<? extends RexNode> nodes,
Iterable<String> fieldNames,
boolean force)
Creates a
Project of the given list
of expressions, using the given names. |
RelBuilder |
project(RexNode... nodes)
Creates a
Project of the given
expressions. |
RelBuilder |
projectExcept(Iterable<RexNode> expressions)
Creates a
Project of all original fields, except the given list of
expressions. |
RelBuilder |
projectExcept(RexNode... expressions)
Creates a
Project of all original fields, except the given
expressions. |
RelBuilder |
projectNamed(Iterable<? extends RexNode> nodes,
Iterable<String> fieldNames,
boolean force)
Creates a
Project of the given
expressions and field names, and optionally optimizing. |
RelBuilder |
projectPlus(Iterable<RexNode> nodes)
Creates a
Project of all original fields, plus the given list of
expressions. |
RelBuilder |
projectPlus(RexNode... nodes)
Creates a
Project of all original fields, plus the given
expressions. |
static RelBuilderFactory |
proto(Context context)
Creates a
RelBuilderFactory, a partially-created RelBuilder. |
static RelBuilderFactory |
proto(Object... factories)
Creates a
RelBuilderFactory that uses a given set of factories. |
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 a
RepeatUnion associated to a TransientTable without a maximum number
of iterations, i.e. repeatUnion(tableName, all, -1). |
RelBuilder |
repeatUnion(String tableName,
boolean all,
int iterationLimit)
Creates a
RepeatUnion associated to a TransientTable of the
two most recent relational expressions on the stack. |
RelBuilder |
scan(Iterable<String> tableNames)
Creates a
TableScan of the table
with a given name. |
RelBuilder |
scan(String... tableNames)
Creates a
TableScan of the table
with a given name. |
RelBuilder |
semiJoin(Iterable<? extends RexNode> conditions)
Creates a
Join with JoinRelType.SEMI. |
RelBuilder |
semiJoin(RexNode... conditions)
Creates a
Join with JoinRelType.SEMI. |
RelBuilder |
snapshot(RexNode period)
Creates a
Snapshot of a given snapshot period. |
RelBuilder |
sort(int... fields)
Creates a
Sort by field ordinals. |
RelBuilder |
sort(Iterable<? extends RexNode> nodes)
Creates a
Sort by expressions. |
RelBuilder |
sort(RelCollation collation)
Creates a
Sort by specifying collations. |
RelBuilder |
sort(RexNode... nodes)
Creates a
Sort 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 a
Sort by a list of expressions, with limit and offset. |
RelBuilder |
sortLimit(int offset,
int fetch,
RexNode... nodes)
Creates a
Sort by expressions, with limit and offset. |
RelBuilder.AggCall |
sum(boolean distinct,
String alias,
RexNode operand)
Creates a call to the
SUM aggregate function,
optionally distinct and with an alias. |
RelBuilder.AggCall |
sum(RexNode operand)
Creates a call to the
SUM 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 a
TableScan on a TransientTable with the given name, using as type
the top of the stack's type. |
RelBuilder |
transientScan(String tableName,
RelDataType rowType)
Creates a
TableScan on a TransientTable with the given name and type. |
RelBuilder |
uncollect(List<String> itemAliases,
boolean withOrdinality)
Creates an
Uncollect with given item aliases. |
RelBuilder |
union(boolean all)
Creates a
Union of the two most recent
relational expressions on the stack. |
RelBuilder |
union(boolean all,
int n)
Creates a
Union of the n
most recent relational expressions on the stack. |
RelBuilder |
values(Iterable<? extends List<RexLiteral>> tupleList,
RelDataType rowType)
Creates a
Values with a specified row type. |
RelBuilder |
values(RelDataType rowType)
Creates a
Values with a specified row type and
zero rows. |
RelBuilder |
values(RelDataType rowType,
Object... columnValues)
Creates a
Values with a specified row type. |
RelBuilder |
values(String[] fieldNames,
Object... values)
Creates a
Values. |
RelBuilder |
variable(Holder<RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into
a Holder.
|
protected final RelOptCluster cluster
protected final RelOptSchema relOptSchema
protected RelBuilder(Context context, RelOptCluster cluster, RelOptSchema relOptSchema)
public static RelBuilder create(FrameworkConfig config)
public RelBuilder transform(UnaryOperator<RelBuilder.Config> transform)
public String toString()
public RelDataTypeFactory getTypeFactory()
public RelBuilder adoptConvention(Convention convention)
public RexBuilder getRexBuilder()
RexNode expressions.public static RelBuilderFactory proto(Context context)
RelBuilderFactory, a partially-created RelBuilder.
Just add a RelOptCluster and a RelOptSchemapublic static RelBuilderFactory proto(Object... factories)
RelBuilderFactory that uses a given set of factories.public RelOptCluster getCluster()
public RelOptSchema getRelOptSchema()
public RelFactories.TableScanFactory getScanFactory()
public RelBuilder push(RelNode node)
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.
public RelBuilder pushAll(Iterable<? extends RelNode> nodes)
public RelNode build()
Throws if the stack is empty.
public RelNode peek()
public RelNode peek(int n)
n positions from the top of the
stack, but does not remove it.public RelNode peek(int inputCount, int inputOrdinal)
n positions from the top of the
stack, but does not remove it.public RelBuilder variable(Holder<RexCorrelVariable> v)
public RexInputRef field(String fieldName)
Equivalent to field(1, 0, fieldName).
fieldName - Field namepublic RexInputRef field(int inputCount, int inputOrdinal, String fieldName)
inputCount - Number of inputsinputOrdinal - Input ordinalfieldName - Field namepublic RexInputRef field(int fieldOrdinal)
Equivalent to field(1, 0, ordinal).
fieldOrdinal - Field ordinalpublic RexInputRef field(int inputCount, int inputOrdinal, int fieldOrdinal)
inputCount - Number of inputsinputOrdinal - Input ordinalfieldOrdinal - Field ordinal within inputpublic RexNode field(String alias, String fieldName)
public RexNode field(int inputCount, String alias, String fieldName)
public RexNode field(RexNode e, String name)
public com.google.common.collect.ImmutableList<RexNode> fields()
public com.google.common.collect.ImmutableList<RexNode> fields(int inputCount, int inputOrdinal)
public com.google.common.collect.ImmutableList<RexNode> fields(RelCollation collation)
public com.google.common.collect.ImmutableList<RexNode> fields(List<? extends Number> ordinals)
public com.google.common.collect.ImmutableList<RexNode> fields(ImmutableBitSet ordinals)
public com.google.common.collect.ImmutableList<RexNode> fields(Iterable<String> fieldNames)
public com.google.common.collect.ImmutableList<RexNode> fields(Mappings.TargetMapping mapping)
@Nonnull public RexNode call(SqlOperator operator, RexNode... operands)
@Nonnull public RexNode call(SqlOperator operator, Iterable<? extends RexNode> operands)
public RexNode and(Iterable<? extends RexNode> operands)
Simplifies the expression a little:
e AND TRUE becomes e;
e AND e2 AND NOT e becomes e2.
public RexNode cast(RexNode expr, SqlTypeName typeName)
public RexNode cast(RexNode expr, SqlTypeName typeName, int precision)
public RexNode cast(RexNode expr, SqlTypeName typeName, int precision, int scale)
public RexNode alias(RexNode expr, String 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.
public RelBuilder.GroupKey groupKey()
public RelBuilder.GroupKey groupKey(RexNode... nodes)
public RelBuilder.GroupKey groupKey(Iterable<? extends RexNode> nodes)
public RelBuilder.GroupKey groupKey(Iterable<? extends RexNode> nodes, Iterable<? extends Iterable<? extends RexNode>> nodeLists)
@Deprecated public RelBuilder.GroupKey groupKey(Iterable<? extends RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends RexNode>> nodeLists)
groupKey(Iterable, Iterable), which has the same behavior as
calling this method with indicator = false.public RelBuilder.GroupKey groupKey(int... fieldOrdinals)
public RelBuilder.GroupKey groupKey(String... fieldNames)
public RelBuilder.GroupKey groupKey(@Nonnull ImmutableBitSet groupSet)
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.
public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, @Nonnull Iterable<? extends ImmutableBitSet> groupSets)
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.
@Deprecated public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
groupKey(ImmutableBitSet)
or groupKey(ImmutableBitSet, Iterable).@Deprecated public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
groupKey(ImmutableBitSet, Iterable).@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, RexNode... operands)
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, RexNode... operands)
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, Iterable<? extends RexNode> operands)
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, Iterable<? extends RexNode> operands)
public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, Iterable<? extends RexNode> operands)
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.
public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, RexNode... operands)
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.
public RelBuilder.AggCall aggregateCall(AggregateCall a)
AggregateCall.public RelBuilder.AggCall aggregateCall(AggregateCall a, Mapping mapping)
AggregateCall, 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)
public RelBuilder.AggCall count(RexNode... operands)
COUNT aggregate function.public RelBuilder.AggCall count(Iterable<? extends RexNode> operands)
COUNT aggregate function.public RelBuilder.AggCall count(boolean distinct, String alias, RexNode... operands)
COUNT aggregate function,
optionally distinct and with an alias.public RelBuilder.AggCall count(boolean distinct, String alias, Iterable<? extends RexNode> operands)
COUNT aggregate function,
optionally distinct and with an alias.public RelBuilder.AggCall countStar(String alias)
COUNT(*) aggregate function.public RelBuilder.AggCall sum(RexNode operand)
SUM aggregate function.public RelBuilder.AggCall sum(boolean distinct, String alias, RexNode operand)
SUM aggregate function,
optionally distinct and with an alias.public RelBuilder.AggCall avg(RexNode operand)
AVG aggregate function.public RelBuilder.AggCall avg(boolean distinct, String alias, RexNode operand)
AVG aggregate function,
optionally distinct and with an alias.public RelBuilder.AggCall min(RexNode operand)
MIN aggregate function.public RelBuilder.AggCall min(String alias, RexNode operand)
MIN aggregate function,
optionally with an alias.public RelBuilder.AggCall max(RexNode operand)
MAX aggregate function,
optionally with an alias.public RelBuilder.AggCall max(String alias, RexNode operand)
MAX aggregate function.public RexNode patternField(String alpha, RelDataType type, int i)
alpha - the pattern nametype - Type of fieldi - Ordinal of fieldpublic RexNode patternConcat(Iterable<? extends RexNode> nodes)
match(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).public RexNode patternConcat(RexNode... nodes)
match(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).public RexNode patternAlter(Iterable<? extends RexNode> nodes)
match(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).public RexNode patternAlter(RexNode... nodes)
match(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).public RexNode patternQuantify(Iterable<? extends RexNode> nodes)
match(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).public RexNode patternQuantify(RexNode... nodes)
match(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).public RexNode patternPermute(Iterable<? extends RexNode> nodes)
match(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).public RexNode patternPermute(RexNode... nodes)
match(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).public RexNode patternExclude(RexNode node)
match(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).public RelBuilder scan(Iterable<String> tableNames)
TableScan of the table
with a given name.
Throws if the table does not exist.
Returns this builder.
tableNames - Name of table (can optionally be qualified)public RelBuilder scan(String... tableNames)
TableScan of the table
with a given name.
Throws if the table does not exist.
Returns this builder.
tableNames - Name of table (can optionally be qualified)public RelBuilder snapshot(RexNode period)
Snapshot of a given snapshot period.
Returns this builder.
period - Name of table (can optionally be qualified)public RexNode cursor(int inputCount, int ordinal)
CURSOR function by ordinal.inputCount - Number of inputsordinal - The reference to the relational inputpublic RelBuilder functionScan(SqlOperator operator, int inputCount, RexNode... operands)
TableFunctionScan.public RelBuilder functionScan(SqlOperator operator, int inputCount, Iterable<? extends RexNode> operands)
TableFunctionScan.public RelBuilder filter(RexNode... predicates)
Filter 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.
public RelBuilder filter(Iterable<? extends RexNode> predicates)
Filter 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.
public RelBuilder filter(Iterable<CorrelationId> variablesSet, RexNode... predicates)
Filter 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.
public RelBuilder filter(Iterable<CorrelationId> variablesSet, Iterable<? extends RexNode> predicates)
Filter 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.
public RelBuilder project(RexNode... nodes)
Project of the given
expressions.public RelBuilder project(Iterable<? extends RexNode> nodes)
Project of the given list
of expressions.
Infers names as would project(Iterable, Iterable) if all
suggested names were null.
nodes - Expressionspublic RelBuilder project(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames)
Project of the given list
of expressions and field names.nodes - ExpressionsfieldNames - field names for expressionspublic RelBuilder project(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames, boolean force)
Project of the given list
of expressions, using the given names.
Names are deduced as follows:
fieldNames is greater than the index of
the current entry in nodes, and the entry in
fieldNames is not null, uses it; otherwise
SqlStdOperatorTable.AS
(see alias(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.
nodes - ExpressionsfieldNames - Suggested field namesforce - create project even if it is identitypublic RelBuilder projectPlus(RexNode... nodes)
Project of all original fields, plus the given
expressions.public RelBuilder projectPlus(Iterable<RexNode> nodes)
Project of all original fields, plus the given list of
expressions.public RelBuilder projectExcept(RexNode... expressions)
Project of all original fields, except the given
expressions.IllegalArgumentException - if the given expressions contain duplicates
or there is an expression that does not match an existing fieldpublic RelBuilder projectExcept(Iterable<RexNode> expressions)
Project of all original fields, except the given list of
expressions.IllegalArgumentException - if the given expressions contain duplicates
or there is an expression that does not match an existing fieldpublic RelBuilder projectNamed(Iterable<? extends RexNode> nodes, Iterable<String> fieldNames, boolean force)
Project of the given
expressions and field names, and optionally optimizing.
If fieldNames is null, or if a particular entry in
fieldNames is null, derives field names from the input
expressions.
If force is false,
and the input is a Project,
and the expressions make the trivial projection ($0, $1, ...),
modifies the input.
nodes - ExpressionsfieldNames - Suggested field names, or null to generateforce - Whether to create a renaming Project if the
projections are trivialpublic RelBuilder uncollect(List<String> itemAliases, boolean withOrdinality)
Uncollect with given item aliases.itemAliases - Operand item aliases, never nullwithOrdinality - If withOrdinality, the output contains an extra
ORDINALITY columnpublic RelBuilder rename(List<String> fieldNames)
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.
fieldNames - List of desired field names; may contain null values or
have fewer fields than the current row typepublic RelBuilder distinct()
Aggregate that makes the
relational expression distinct on all fields.public RelBuilder aggregate(RelBuilder.GroupKey groupKey, RelBuilder.AggCall... aggCalls)
Aggregate with an array of
calls.public RelBuilder aggregate(RelBuilder.GroupKey groupKey, List<AggregateCall> aggregateCalls)
Aggregate with an array of
AggregateCalls.public RelBuilder aggregate(RelBuilder.GroupKey groupKey, Iterable<RelBuilder.AggCall> aggCalls)
Aggregate with multiple calls.public RelBuilder union(boolean all)
Union of the two most recent
relational expressions on the stack.all - Whether to create UNION ALLpublic RelBuilder union(boolean all, int n)
Union of the n
most recent relational expressions on the stack.all - Whether to create UNION ALLn - Number of inputs to the UNION operatorpublic RelBuilder intersect(boolean all)
Intersect of the two most
recent relational expressions on the stack.all - Whether to create INTERSECT ALLpublic RelBuilder intersect(boolean all, int n)
Intersect of the n
most recent relational expressions on the stack.all - Whether to create INTERSECT ALLn - Number of inputs to the INTERSECT operatorpublic RelBuilder minus(boolean all)
Minus of the two most recent
relational expressions on the stack.all - Whether to create EXCEPT ALLpublic RelBuilder minus(boolean all, int n)
Minus of the n
most recent relational expressions on the stack.all - Whether to create EXCEPT ALLpublic RelBuilder transientScan(String tableName)
TableScan on a TransientTable with the given name, using as type
the top of the stack's type.tableName - table namepublic RelBuilder transientScan(String tableName, RelDataType rowType)
TableScan on a TransientTable with the given name and type.tableName - table namerowType - row type of the tablepublic RelBuilder repeatUnion(String tableName, boolean all)
RepeatUnion associated to a TransientTable without a maximum number
of iterations, i.e. repeatUnion(tableName, all, -1).tableName - name of the TransientTable associated to the RepeatUnionall - whether duplicates will be considered or notpublic RelBuilder repeatUnion(String tableName, boolean all, int iterationLimit)
RepeatUnion associated to a TransientTable 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:
TransientTable;
TableScan on the
TransientTable) 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 the TransientTable,
overwriting the results from the previous one.
tableName - Name of the TransientTable associated to the
RepeatUnionall - Whether duplicates are considerediterationLimit - Maximum number of iterations; negative value means no limitpublic RelBuilder join(JoinRelType joinType, RexNode condition0, RexNode... conditions)
Join with an array of conditions.public RelBuilder join(JoinRelType joinType, Iterable<? extends RexNode> conditions)
Join with multiple
conditions.public RelBuilder join(JoinRelType joinType, RexNode condition)
Join with one condition.public RelBuilder join(JoinRelType joinType, RexNode condition, Set<CorrelationId> variablesSet)
Join with correlating variables.public RelBuilder correlate(JoinRelType joinType, CorrelationId correlationId, RexNode... requiredFields)
Correlate
with a CorrelationId and an array of fields that are used by correlation.public RelBuilder correlate(JoinRelType joinType, CorrelationId correlationId, Iterable<? extends RexNode> requiredFields)
Correlate
with a CorrelationId and a list of fields that are used by correlation.public RelBuilder join(JoinRelType joinType, String... fieldNames)
Join 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.
joinType - Join typefieldNames - Field namespublic RelBuilder semiJoin(Iterable<? extends RexNode> conditions)
Join with JoinRelType.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 all EMP records
that do not have a corresponding DEPT record, similar to the
following SQL:
SELECT * FROM EMP
WHERE EXISTS (SELECT 1 FROM DEPT
WHERE DEPT.DEPTNO = EMP.DEPTNO)
public RelBuilder semiJoin(RexNode... conditions)
Join with JoinRelType.SEMI.semiJoin(Iterable)public RelBuilder antiJoin(Iterable<? extends RexNode> conditions)
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 all EMP records
that do not have a corresponding DEPT record, similar to the
following SQL:
SELECT * FROM EMP
WHERE NOT EXISTS (SELECT 1 FROM DEPT
WHERE DEPT.DEPTNO = EMP.DEPTNO)
public RelBuilder antiJoin(RexNode... conditions)
antiJoin(Iterable)public RelBuilder as(String alias)
public RelBuilder values(String[] fieldNames, Object... values)
Values.
The values array must have the same number of entries as
fieldNames, 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).
fieldNames - Field namesvalues - Valuespublic RelBuilder empty()
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.
public RelBuilder values(RelDataType rowType, Object... columnValues)
Values 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.
rowType - Row typecolumnValues - Valuespublic RelBuilder values(Iterable<? extends List<RexLiteral>> tupleList, RelDataType rowType)
Values 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.
tupleList - Tuple listrowType - Row typepublic RelBuilder values(RelDataType rowType)
Values with a specified row type and
zero rows.rowType - Row typepublic RelBuilder limit(int offset, int fetch)
public RelBuilder exchange(RelDistribution distribution)
public RelBuilder sortExchange(RelDistribution distribution, RelCollation collation)
public RelBuilder sort(int... fields)
Sort by field ordinals.
Negative fields mean descending: -1 means field(0) descending, -2 means field(1) descending, etc.
public RelBuilder sort(RexNode... nodes)
Sort by expressions.public RelBuilder sort(Iterable<? extends RexNode> nodes)
Sort by expressions.public RelBuilder sortLimit(int offset, int fetch, RexNode... nodes)
Sort by expressions, with limit and offset.public RelBuilder sort(RelCollation collation)
Sort by specifying collations.public RelBuilder sortLimit(int offset, int fetch, Iterable<? extends RexNode> nodes)
Sort by a list of expressions, with limit and offset.offset - Number of rows to skip; non-positive means don't skip anyfetch - Maximum number of rows to fetch; negative means no limitnodes - Sort expressionspublic RelBuilder convert(RelDataType castRowType, boolean rename)
castRowType - row type after castrename - if true, use field names from castRowType; if false,
preserve field names from relpublic RelBuilder permute(Mapping mapping)
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)
Match.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)
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
the GROUP BY. You do not need to do that in this API, because the
groupKey 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
groupKey - Key columnsaggCalls - Aggregate expressions to compute for each valueaxes - Columns to pivotvalues - Values to pivot, and the alias for each column grouppublic RelBuilder hints(RelHint... hints)
The redundant hints would be eliminated.
hints - HintsAssertionError - if the top relational expression does not implement
Hintablepublic RelBuilder hints(Iterable<RelHint> hints)
The redundant hints would be eliminated.
hints - HintsAssertionError - if the top relational expression does not implement
Hintablepublic void clear()
The builder's state is now the same as when it was created.
Copyright © 2012-2020 Apache Software Foundation. All Rights Reserved.