@Value.Enclosing public class RelBuilder extends Object
FLINK modifications are at lines
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 interface |
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate.
|
static interface |
RelBuilder.OverCall
Call to a windowed aggregate function.
|
Modifier and Type | Field and Description |
---|---|
protected org.apache.calcite.plan.RelOptCluster |
cluster |
protected @Nullable org.apache.calcite.plan.RelOptSchema |
relOptSchema |
Modifier | Constructor and Description |
---|---|
protected |
RelBuilder(@Nullable org.apache.calcite.plan.Context context,
org.apache.calcite.plan.RelOptCluster cluster,
@Nullable org.apache.calcite.plan.RelOptSchema relOptSchema) |
Modifier and Type | Method and Description |
---|---|
RelBuilder |
adoptConvention(org.apache.calcite.plan.Convention convention)
Returns new RelBuilder that adopts the convention provided.
|
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
Iterable<RelBuilder.AggCall> aggCalls)
Creates an
Aggregate with multiple calls. |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
List<org.apache.calcite.rel.core.AggregateCall> aggregateCalls)
Creates an
Aggregate with an array of AggregateCall s. |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
RelBuilder.AggCall... aggCalls)
Creates an
Aggregate with an array of calls. |
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.rel.core.AggregateCall a)
Creates a call to an aggregate function as a copy of an
AggregateCall . |
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.rel.core.AggregateCall a,
org.apache.calcite.util.mapping.Mapping mapping)
Creates a call to an aggregate function as a copy of an
AggregateCall , applying a
mapping. |
protected RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
boolean ignoreNulls,
@Nullable org.apache.calcite.rex.RexNode filter,
@Nullable com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> distinctKeys,
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> orderKeys,
@Nullable String alias,
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function with all applicable operands.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
org.apache.calcite.rex.RexNode filter,
@Nullable String alias,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
org.apache.calcite.rex.RexNode filter,
@Nullable String alias,
org.apache.calcite.rex.RexNode... operands)
Deprecated.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
boolean distinct,
org.apache.calcite.rex.RexNode filter,
@Nullable String alias,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Deprecated.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
boolean distinct,
org.apache.calcite.rex.RexNode filter,
@Nullable String alias,
org.apache.calcite.rex.RexNode... operands)
Deprecated.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to an aggregate function.
|
RelBuilder.AggCall |
aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction,
org.apache.calcite.rex.RexNode... operands)
Creates a call to an aggregate function.
|
org.apache.calcite.rex.RexNode |
alias(org.apache.calcite.rex.RexNode expr,
@Nullable String alias)
Returns an expression wrapped in an alias.
|
org.apache.calcite.rex.RexNode |
all(org.apache.calcite.rex.RexNode node,
org.apache.calcite.sql.SqlOperator op,
Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ALL predicate.
|
org.apache.calcite.rex.RexNode |
and(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an AND.
|
org.apache.calcite.rex.RexNode |
and(org.apache.calcite.rex.RexNode... operands)
Creates an AND.
|
RelBuilder |
antiJoin(Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates an anti-join.
|
RelBuilder |
antiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates an anti-join.
|
org.apache.calcite.rex.RexSubQuery |
arrayQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an ARRAY sub-query.
|
RelBuilder |
as(String alias)
Assigns a table alias to the top entry on the stack.
|
RelBuilder.AggCall |
avg(boolean distinct,
@Nullable String alias,
org.apache.calcite.rex.RexNode operand)
Creates a call to the
AVG aggregate function, optionally distinct and with an alias. |
RelBuilder.AggCall |
avg(org.apache.calcite.rex.RexNode operand)
Creates a call to the
AVG aggregate function. |
org.apache.calcite.rex.RexNode |
between(org.apache.calcite.rex.RexNode arg,
org.apache.calcite.rex.RexNode lower,
org.apache.calcite.rex.RexNode upper)
Creates a
BETWEEN . |
org.apache.calcite.rel.RelNode |
build()
Returns the final relational expression.
|
org.apache.calcite.rex.RexNode |
call(org.apache.calcite.sql.SqlOperator operator,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to a scalar operator.
|
org.apache.calcite.rex.RexNode |
call(org.apache.calcite.sql.SqlOperator operator,
org.apache.calcite.rex.RexNode... operands)
Creates a call to a scalar operator.
|
org.apache.calcite.rex.RexNode |
cast(org.apache.calcite.rex.RexNode expr,
org.apache.calcite.sql.type.SqlTypeName typeName)
Creates an expression that casts an expression to a given type.
|
org.apache.calcite.rex.RexNode |
cast(org.apache.calcite.rex.RexNode expr,
org.apache.calcite.sql.type.SqlTypeName typeName,
int precision)
Creates an expression that casts an expression to a type with a given name and precision or
length.
|
org.apache.calcite.rex.RexNode |
cast(org.apache.calcite.rex.RexNode expr,
org.apache.calcite.sql.type.SqlTypeName typeName,
int precision,
int scale)
Creates an expression that casts an expression to a type with a given name, precision and
scale.
|
void |
clear()
Clears the stack.
|
RelBuilder |
convert(org.apache.calcite.rel.type.RelDataType castRowType,
boolean rename)
Creates a projection that converts the current relational expression's output to a desired
row type.
|
RelBuilder |
correlate(org.apache.calcite.rel.core.JoinRelType joinType,
org.apache.calcite.rel.core.CorrelationId correlationId,
Iterable<? extends org.apache.calcite.rex.RexNode> requiredFields)
Creates a
Correlate with a CorrelationId and a list of fields that are used
by correlation. |
RelBuilder |
correlate(org.apache.calcite.rel.core.JoinRelType joinType,
org.apache.calcite.rel.core.CorrelationId correlationId,
org.apache.calcite.rex.RexNode... requiredFields)
Creates a
Correlate with a CorrelationId and an array of fields that are used
by correlation. |
RelBuilder.AggCall |
count(boolean distinct,
@Nullable String alias,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to the
COUNT aggregate function, optionally distinct and with an
alias. |
RelBuilder.AggCall |
count(boolean distinct,
@Nullable String alias,
org.apache.calcite.rex.RexNode... operands)
Creates a call to the
COUNT aggregate function, optionally distinct and with an
alias. |
RelBuilder.AggCall |
count(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a call to the
COUNT aggregate function. |
RelBuilder.AggCall |
count(org.apache.calcite.rex.RexNode... operands)
Creates a call to the
COUNT aggregate function. |
RelBuilder.AggCall |
countStar(@Nullable String alias)
Creates a call to the
COUNT(*) aggregate function. |
static RelBuilder |
create(org.apache.calcite.tools.FrameworkConfig config)
Creates a RelBuilder.
|
org.apache.calcite.rex.RexWindowBound |
currentRow()
Creates a
CURRENT ROW window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound) and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound) . |
org.apache.calcite.rex.RexNode |
cursor(int inputCount,
int ordinal)
Creates a RexCall to the
CURSOR function by ordinal. |
org.apache.calcite.rex.RexNode |
desc(org.apache.calcite.rex.RexNode node)
Converts a sort expression to descending.
|
RelBuilder |
distinct()
Creates an
Aggregate that makes the relational expression distinct on all fields. |
org.apache.calcite.rex.RexNode |
dot(org.apache.calcite.rex.RexNode node,
int fieldOrdinal)
Creates an access to a field by ordinal.
|
org.apache.calcite.rex.RexNode |
dot(org.apache.calcite.rex.RexNode node,
String fieldName)
Creates an access to a field by name.
|
RelBuilder |
empty()
Creates a relational expression that reads from an input and throws all of the rows away.
|
org.apache.calcite.rex.RexNode |
equals(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates an
= . |
RelBuilder |
exchange(org.apache.calcite.rel.RelDistribution distribution)
Creates an Exchange by distribution.
|
org.apache.calcite.rex.RexSubQuery |
exists(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an EXISTS predicate.
|
org.apache.calcite.rex.RexInputRef |
field(int fieldOrdinal)
Creates a reference to an input field by ordinal.
|
org.apache.calcite.rex.RexInputRef |
field(int inputCount,
int inputOrdinal,
int fieldOrdinal)
Creates a reference to a field of a given input relational expression by ordinal.
|
org.apache.calcite.rex.RexInputRef |
field(int inputCount,
int inputOrdinal,
String fieldName)
Creates a reference to a field of given input relational expression by name.
|
org.apache.calcite.rex.RexNode |
field(int inputCount,
String alias,
String fieldName)
Creates a reference to a field which originated in a relation with the given alias.
|
org.apache.calcite.rex.RexNode |
field(org.apache.calcite.rex.RexNode e,
String name)
Returns a reference to a given field of a record-valued expression.
|
org.apache.calcite.rex.RexInputRef |
field(String fieldName)
Creates a reference to a field by name.
|
org.apache.calcite.rex.RexNode |
field(String alias,
String fieldName)
Creates a reference to a field of the current record which originated in a relation with a
given alias.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields()
Returns references to the fields of the top input.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(org.apache.calcite.util.ImmutableBitSet ordinals)
Returns references to fields for a given bit set of input ordinals.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(int inputCount,
int inputOrdinal)
Returns references to the fields of a given input.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(Iterable<String> fieldNames)
Returns references to fields identified by name.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(List<? extends Number> ordinals)
Returns references to fields for a given list of input ordinals.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping)
Returns references to fields identified by a mapping.
|
com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> |
fields(org.apache.calcite.rel.RelCollation collation)
Returns references to fields for a given collation.
|
RelBuilder |
filter(Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates a
Filter of a list of predicates. |
RelBuilder |
filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet,
Iterable<? extends org.apache.calcite.rex.RexNode> predicates)
Creates a
Filter of a list of correlation variables and a list of predicates. |
RelBuilder |
filter(Iterable<org.apache.calcite.rel.core.CorrelationId> variablesSet,
org.apache.calcite.rex.RexNode... predicates)
Creates a
Filter of a list of correlation variables and an array of predicates. |
RelBuilder |
filter(org.apache.calcite.rex.RexNode... predicates)
Creates a
Filter of an array of predicates. |
org.apache.calcite.rex.RexWindowBound |
following(org.apache.calcite.rex.RexNode bound)
Creates a
bound FOLLOWING window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound) and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound) . |
RelBuilder |
functionScan(org.apache.calcite.sql.SqlOperator operator,
int inputCount,
Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates a
TableFunctionScan . |
RelBuilder |
functionScan(org.apache.calcite.sql.SqlOperator operator,
int inputCount,
org.apache.calcite.rex.RexNode... operands)
Creates a
TableFunctionScan . |
org.apache.calcite.plan.RelOptCluster |
getCluster() |
@Nullable org.apache.calcite.plan.RelOptSchema |
getRelOptSchema() |
org.apache.calcite.rex.RexBuilder |
getRexBuilder()
Returns the builder for
RexNode expressions. |
org.apache.calcite.rel.core.RelFactories.TableScanFactory |
getScanFactory() |
org.apache.calcite.rel.type.RelDataTypeFactory |
getTypeFactory()
Returns the type factory.
|
org.apache.calcite.rex.RexNode |
greaterThan(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates a
> . |
org.apache.calcite.rex.RexNode |
greaterThanOrEqual(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates a
>= . |
RelBuilder.GroupKey |
groupKey()
Creates an empty group key.
|
RelBuilder.GroupKey |
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet)
Creates a group key, identified by field positions in the underlying relational expression.
|
RelBuilder.GroupKey |
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet,
boolean indicator,
@Nullable com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets)
Deprecated.
|
RelBuilder.GroupKey |
groupKey(org.apache.calcite.util.ImmutableBitSet groupSet,
Iterable<? extends org.apache.calcite.util.ImmutableBitSet> groupSets)
Creates a group key with grouping sets, both identified by field positions in the underlying
relational expression.
|
RelBuilder.GroupKey |
groupKey(int... fieldOrdinals)
Creates a group key of fields identified by ordinal.
|
RelBuilder.GroupKey |
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a group key.
|
RelBuilder.GroupKey |
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes,
boolean indicator,
Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Deprecated.
Now that indicator is deprecated, use
groupKey(Iterable, Iterable) ,
which has the same behavior as calling this method with indicator = false . |
RelBuilder.GroupKey |
groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes,
Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
Creates a group key with grouping sets.
|
RelBuilder.GroupKey |
groupKey(org.apache.calcite.rex.RexNode... nodes)
Creates a group key.
|
RelBuilder.GroupKey |
groupKey(String... fieldNames)
Creates a group key of fields identified by name.
|
RelBuilder |
hints(Iterable<org.apache.calcite.rel.hint.RelHint> hints)
Attaches multiple hints to the stack top relational expression.
|
RelBuilder |
hints(org.apache.calcite.rel.hint.RelHint... hints)
Attaches an array of hints to the stack top relational expression.
|
org.apache.calcite.rex.RexSubQuery |
in(org.apache.calcite.rel.RelNode rel,
Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates an IN predicate with a sub-query.
|
org.apache.calcite.rex.RexNode |
in(org.apache.calcite.rex.RexNode arg,
Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates an IN predicate with a sub-query.
|
org.apache.calcite.rex.RexNode |
in(org.apache.calcite.rex.RexNode arg,
Iterable<? extends org.apache.calcite.rex.RexNode> ranges)
Creates an IN predicate with a list of values.
|
org.apache.calcite.rex.RexNode |
in(org.apache.calcite.rex.RexNode arg,
org.apache.calcite.rex.RexNode... ranges)
Creates an IN predicate with a list of values.
|
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. |
org.apache.calcite.rex.RexNode |
isDistinctFrom(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent to
o0 IS DISTINCT FROM o1 . |
org.apache.calcite.rex.RexNode |
isNotDistinctFrom(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates an expression equivalent to "
o0 IS NOT DISTINCT FROM o1 ". |
org.apache.calcite.rex.RexNode |
isNotNull(org.apache.calcite.rex.RexNode operand)
Creates an
IS NOT NULL . |
org.apache.calcite.rex.RexNode |
isNull(org.apache.calcite.rex.RexNode operand)
Creates ab
IS NULL . |
RelBuilder |
join(org.apache.calcite.rel.core.JoinRelType joinType,
Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Creates a
Join with multiple conditions. |
RelBuilder |
join(org.apache.calcite.rel.core.JoinRelType joinType,
org.apache.calcite.rex.RexNode condition)
Creates a
Join with one condition. |
RelBuilder |
join(org.apache.calcite.rel.core.JoinRelType joinType,
org.apache.calcite.rex.RexNode condition0,
org.apache.calcite.rex.RexNode... conditions)
Creates a
Join with an array of conditions. |
RelBuilder |
join(org.apache.calcite.rel.core.JoinRelType joinType,
org.apache.calcite.rex.RexNode condition,
Set<org.apache.calcite.rel.core.CorrelationId> variablesSet)
Creates a
Join with correlating variables. |
RelBuilder |
join(org.apache.calcite.rel.core.JoinRelType joinType,
String... fieldNames)
Creates a
Join using USING syntax. |
org.apache.calcite.rex.RexNode |
lessThan(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates a
< . |
org.apache.calcite.rex.RexNode |
lessThanOrEqual(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates a
<= . |
<R> R |
let(Function<RelBuilder,R> consumer)
Performs an action on this RelBuilder.
|
RelBuilder |
limit(int offset,
int fetch)
Creates a limit without a sort.
|
org.apache.calcite.rex.RexLiteral |
literal(@Nullable Object value)
Creates a literal (constant expression).
|
org.apache.calcite.rex.RexSubQuery |
mapQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MAP sub-query.
|
RelBuilder |
match(org.apache.calcite.rex.RexNode pattern,
boolean strictStart,
boolean strictEnd,
Map<String,org.apache.calcite.rex.RexNode> patternDefinitions,
Iterable<? extends org.apache.calcite.rex.RexNode> measureList,
org.apache.calcite.rex.RexNode after,
Map<String,? extends SortedSet<String>> subsets,
boolean allRows,
Iterable<? extends org.apache.calcite.rex.RexNode> partitionKeys,
Iterable<? extends org.apache.calcite.rex.RexNode> orderKeys,
org.apache.calcite.rex.RexNode interval)
Creates a
Match . |
RelBuilder.AggCall |
max(org.apache.calcite.rex.RexNode operand)
Creates a call to the
MAX aggregate function, optionally with an alias. |
RelBuilder.AggCall |
max(@Nullable String alias,
org.apache.calcite.rex.RexNode operand)
Creates a call to the
MAX aggregate function. |
RelBuilder.AggCall |
min(org.apache.calcite.rex.RexNode operand)
Creates a call to the
MIN aggregate function. |
RelBuilder.AggCall |
min(@Nullable String alias,
org.apache.calcite.rex.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. |
org.apache.calcite.rex.RexSubQuery |
multisetQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a MULTISET sub-query.
|
org.apache.calcite.rex.RexNode |
not(org.apache.calcite.rex.RexNode operand)
Creates a NOT.
|
org.apache.calcite.rex.RexNode |
notEquals(org.apache.calcite.rex.RexNode operand0,
org.apache.calcite.rex.RexNode operand1)
Creates a
<> . |
org.apache.calcite.rex.RexNode |
nullsFirst(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls first.
|
org.apache.calcite.rex.RexNode |
nullsLast(org.apache.calcite.rex.RexNode node)
Converts a sort expression to nulls last.
|
org.apache.calcite.rex.RexNode |
or(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Creates an OR.
|
org.apache.calcite.rex.RexNode |
or(org.apache.calcite.rex.RexNode... operands)
Creates an OR.
|
org.apache.calcite.rex.RexNode |
patternAlter(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates alternate patterns; for use 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) . |
org.apache.calcite.rex.RexNode |
patternAlter(org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternConcat(Iterable<? extends org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternConcat(org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternExclude(org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternField(String alpha,
org.apache.calcite.rel.type.RelDataType type,
int i)
Creates a reference to a given field of the pattern.
|
org.apache.calcite.rex.RexNode |
patternPermute(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a call that creates permute patterns; for use 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) . |
org.apache.calcite.rex.RexNode |
patternPermute(org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternQuantify(Iterable<? extends org.apache.calcite.rex.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) . |
org.apache.calcite.rex.RexNode |
patternQuantify(org.apache.calcite.rex.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) . |
org.apache.calcite.rel.RelNode |
peek()
Returns the relational expression at the top of the stack, but does not remove it.
|
org.apache.calcite.rel.RelNode |
peek(int n)
Returns the relational expression
n positions from the top of the stack, but does not
remove it. |
org.apache.calcite.rel.RelNode |
peek(int inputCount,
int inputOrdinal)
Returns the relational expression
n positions from the top of the stack, but does not
remove it. |
RelBuilder |
permute(org.apache.calcite.util.mapping.Mapping mapping) |
RelBuilder |
pivot(RelBuilder.GroupKey groupKey,
Iterable<? extends RelBuilder.AggCall> aggCalls,
Iterable<? extends org.apache.calcite.rex.RexNode> axes,
Iterable<? extends Map.Entry<String,? extends Iterable<? extends org.apache.calcite.rex.RexNode>>> values)
Creates a Pivot.
|
org.apache.calcite.rex.RexWindowBound |
preceding(org.apache.calcite.rex.RexNode bound)
Creates a
bound PRECEDING window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound) and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound) . |
RelBuilder |
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a
Project of the given list of expressions. |
RelBuilder |
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes,
Iterable<? extends String> fieldNames)
Creates a
Project of the given list of expressions and field names. |
RelBuilder |
project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes,
Iterable<? extends String> fieldNames,
boolean force)
Creates a
Project of the given list of expressions, using the given names. |
RelBuilder |
project(org.apache.calcite.rex.RexNode... nodes)
Creates a
Project of the given expressions. |
RelBuilder |
projectExcept(Iterable<org.apache.calcite.rex.RexNode> expressions)
Creates a
Project of all original fields, except the given list of expressions. |
RelBuilder |
projectExcept(org.apache.calcite.rex.RexNode... expressions)
Creates a
Project of all original fields, except the given expressions. |
RelBuilder |
projectNamed(Iterable<? extends org.apache.calcite.rex.RexNode> nodes,
@Nullable Iterable<? extends String> fieldNames,
boolean force)
Creates a
Project of the given expressions and field names, and optionally
optimizing. |
RelBuilder |
projectPlus(Iterable<org.apache.calcite.rex.RexNode> nodes)
Creates a
Project of all original fields, plus the given list of expressions. |
RelBuilder |
projectPlus(org.apache.calcite.rex.RexNode... nodes)
Creates a
Project of all original fields, plus the given expressions. |
static org.apache.calcite.tools.RelBuilderFactory |
proto(org.apache.calcite.plan.Context context)
Creates a
RelBuilderFactory , a partially-created RelBuilder. |
static org.apache.calcite.tools.RelBuilderFactory |
proto(Object... factories)
Creates a
RelBuilderFactory that uses a given set of factories. |
RelBuilder |
push(org.apache.calcite.rel.RelNode node)
Adds a relational expression to be the input to the next relational expression constructed.
|
RelBuilder |
pushAll(Iterable<? extends org.apache.calcite.rel.RelNode> nodes)
Pushes a collection of relational expressions.
|
RelBuilder |
rename(List<? extends 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. |
org.apache.calcite.rex.RexSubQuery |
scalarQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a scalar sub-query.
|
RelBuilder |
scan(Iterable<String> tableNames)
Creates 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 org.apache.calcite.rex.RexNode> conditions)
Creates a
Join with JoinRelType.SEMI . |
RelBuilder |
semiJoin(org.apache.calcite.rex.RexNode... conditions)
Creates a
Join with JoinRelType.SEMI . |
int |
size()
Returns the size of the stack.
|
RelBuilder |
snapshot(org.apache.calcite.rex.RexNode period)
Creates a
Snapshot of a given snapshot period. |
org.apache.calcite.rex.RexSubQuery |
some(org.apache.calcite.rex.RexNode node,
org.apache.calcite.sql.SqlOperator op,
Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a SOME (or ANY) predicate.
|
RelBuilder |
sort(int... fields)
Creates a
Sort by field ordinals. |
RelBuilder |
sort(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a
Sort by expressions. |
RelBuilder |
sort(org.apache.calcite.rel.RelCollation collation)
Creates a
Sort by specifying collations. |
RelBuilder |
sort(org.apache.calcite.rex.RexNode... nodes)
Creates a
Sort by expressions. |
RelBuilder |
sortExchange(org.apache.calcite.rel.RelDistribution distribution,
org.apache.calcite.rel.RelCollation collation)
Creates a SortExchange by distribution and collation.
|
RelBuilder |
sortLimit(int offset,
int fetch,
Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a
Sort by a list of expressions, with limit and offset. |
RelBuilder |
sortLimit(int offset,
int fetch,
org.apache.calcite.rex.RexNode... nodes)
Creates a
Sort by expressions, with limit and offset. |
RelBuilder |
sortLimit(@Nullable org.apache.calcite.rex.RexNode offsetNode,
@Nullable org.apache.calcite.rex.RexNode fetchNode,
Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Creates a
Sort by a list of expressions, with limitNode and offsetNode. |
RelBuilder.AggCall |
sum(boolean distinct,
@Nullable String alias,
org.apache.calcite.rex.RexNode operand)
Creates a call to the
SUM aggregate function, optionally distinct and with an alias. |
RelBuilder.AggCall |
sum(org.apache.calcite.rex.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,
org.apache.calcite.rel.type.RelDataType rowType)
Creates a
TableScan on a TransientTable with the given name and type. |
org.apache.calcite.rex.RexWindowBound |
unboundedFollowing()
Creates an
UNBOUNDED FOLLOWING window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound) and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound) . |
org.apache.calcite.rex.RexWindowBound |
unboundedPreceding()
Creates an
UNBOUNDED PRECEDING window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound) and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound) . |
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. |
org.apache.calcite.rex.RexSubQuery |
unique(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
Creates a UNIQUE predicate.
|
RelBuilder |
unpivot(boolean includeNulls,
Iterable<String> measureNames,
Iterable<String> axisNames,
Iterable<? extends Map.Entry<? extends List<? extends org.apache.calcite.rex.RexLiteral>,? extends List<? extends org.apache.calcite.rex.RexNode>>> axisMap)
Creates an Unpivot.
|
RelBuilder |
values(Iterable<? extends List<org.apache.calcite.rex.RexLiteral>> tupleList,
org.apache.calcite.rel.type.RelDataType rowType)
Creates a
Values with a specified row type. |
RelBuilder |
values(org.apache.calcite.rel.type.RelDataType rowType)
Creates a
Values with a specified row type and zero rows. |
RelBuilder |
values(org.apache.calcite.rel.type.RelDataType rowType,
Object... columnValues)
Creates a
Values with a specified row type. |
RelBuilder |
values(@Nullable String[] fieldNames,
Object... values)
Creates a
Values . |
RelBuilder |
variable(org.apache.calcite.util.Holder<org.apache.calcite.rex.RexCorrelVariable> v)
Creates a correlation variable for the current input, and writes it into a Holder.
|
<E> E |
with(org.apache.calcite.rel.RelNode r,
Function<RelBuilder,E> fn)
Evaluates an expression with a relational expression temporarily on the stack.
|
<E> E |
withPredicates(org.apache.calcite.rel.metadata.RelMetadataQuery mq,
Function<RelBuilder,E> fn)
Performs an action using predicates of the
current node to simplify. |
<E> E |
withSimplifier(BiFunction<RelBuilder,org.apache.calcite.rex.RexSimplify,org.apache.calcite.rex.RexSimplify> simplifierTransform,
Function<RelBuilder,E> fn)
Performs an action with a temporary simplifier.
|
protected final org.apache.calcite.plan.RelOptCluster cluster
protected final @Nullable org.apache.calcite.plan.RelOptSchema relOptSchema
protected RelBuilder(@Nullable org.apache.calcite.plan.Context context, org.apache.calcite.plan.RelOptCluster cluster, @Nullable org.apache.calcite.plan.RelOptSchema relOptSchema)
public static RelBuilder create(org.apache.calcite.tools.FrameworkConfig config)
public RelBuilder transform(UnaryOperator<RelBuilder.Config> transform)
public <R> R let(Function<RelBuilder,R> consumer)
For example, consider the following code:
RelNode filterAndRename(RelBuilder relBuilder, RelNode rel, RexNode condition, List<String> fieldNames) { relBuilder.push(rel) .filter(condition); if (fieldNames != null) { relBuilder.rename(fieldNames); } return relBuilder .build();
The pipeline is disrupted by the 'if'. The let
method allows you to perform the
flow as a single pipeline:
RelNode filterAndRename(RelBuilder relBuilder, RelNode rel, RexNode condition, List<String> fieldNames) { return relBuilder.push(rel) .filter(condition) .let(r -> fieldNames == null ? r : r.rename(fieldNames)) .build();
In pipelined cases such as this one, the lambda must return this RelBuilder. But let
return values of other types.
public String toString()
public org.apache.calcite.rel.type.RelDataTypeFactory getTypeFactory()
public RelBuilder adoptConvention(org.apache.calcite.plan.Convention convention)
public org.apache.calcite.rex.RexBuilder getRexBuilder()
RexNode
expressions.public static org.apache.calcite.tools.RelBuilderFactory proto(org.apache.calcite.plan.Context context)
RelBuilderFactory
, a partially-created RelBuilder. Just add a RelOptCluster
and a RelOptSchema
public static org.apache.calcite.tools.RelBuilderFactory proto(Object... factories)
RelBuilderFactory
that uses a given set of factories.public org.apache.calcite.plan.RelOptCluster getCluster()
public @Nullable org.apache.calcite.plan.RelOptSchema getRelOptSchema()
public org.apache.calcite.rel.core.RelFactories.TableScanFactory getScanFactory()
public RelBuilder push(org.apache.calcite.rel.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 org.apache.calcite.rel.RelNode> nodes)
public int size()
public org.apache.calcite.rel.RelNode build()
Throws if the stack is empty.
public org.apache.calcite.rel.RelNode peek()
public org.apache.calcite.rel.RelNode peek(int n)
n
positions from the top of the stack, but does not
remove it.public org.apache.calcite.rel.RelNode peek(int inputCount, int inputOrdinal)
n
positions from the top of the stack, but does not
remove it.public <E> E with(org.apache.calcite.rel.RelNode r, Function<RelBuilder,E> fn)
public <E> E withSimplifier(BiFunction<RelBuilder,org.apache.calcite.rex.RexSimplify,org.apache.calcite.rex.RexSimplify> simplifierTransform, Function<RelBuilder,E> fn)
public <E> E withPredicates(org.apache.calcite.rel.metadata.RelMetadataQuery mq, Function<RelBuilder,E> fn)
current node
to simplify.public org.apache.calcite.rex.RexLiteral literal(@Nullable Object value)
public RelBuilder variable(org.apache.calcite.util.Holder<org.apache.calcite.rex.RexCorrelVariable> v)
public org.apache.calcite.rex.RexInputRef field(String fieldName)
Equivalent to field(1, 0, fieldName)
.
fieldName
- Field namepublic org.apache.calcite.rex.RexInputRef field(int inputCount, int inputOrdinal, String fieldName)
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldName
- Field namepublic org.apache.calcite.rex.RexInputRef field(int fieldOrdinal)
Equivalent to field(1, 0, ordinal)
.
fieldOrdinal
- Field ordinalpublic org.apache.calcite.rex.RexInputRef field(int inputCount, int inputOrdinal, int fieldOrdinal)
inputCount
- Number of inputsinputOrdinal
- Input ordinalfieldOrdinal
- Field ordinal within inputpublic org.apache.calcite.rex.RexNode field(String alias, String fieldName)
public org.apache.calcite.rex.RexNode field(int inputCount, String alias, String fieldName)
public org.apache.calcite.rex.RexNode field(org.apache.calcite.rex.RexNode e, String name)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields()
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(int inputCount, int inputOrdinal)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.rel.RelCollation collation)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(List<? extends Number> ordinals)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.util.ImmutableBitSet ordinals)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(Iterable<String> fieldNames)
public com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> fields(org.apache.calcite.util.mapping.Mappings.TargetMapping mapping)
public org.apache.calcite.rex.RexNode dot(org.apache.calcite.rex.RexNode node, String fieldName)
public org.apache.calcite.rex.RexNode dot(org.apache.calcite.rex.RexNode node, int fieldOrdinal)
public org.apache.calcite.rex.RexNode call(org.apache.calcite.sql.SqlOperator operator, org.apache.calcite.rex.RexNode... operands)
public org.apache.calcite.rex.RexNode call(org.apache.calcite.sql.SqlOperator operator, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode... ranges)
For example,
b.scan("Emp")
.filter(b.in(b.field("deptno"), b.literal(10), b.literal(20)))
is equivalent to SQL
SELECT *
FROM Emp
WHERE deptno IN (10, 20)
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, Iterable<? extends org.apache.calcite.rex.RexNode> ranges)
For example,
b.scan("Emps")
.filter(
b.in(b.field("deptno"),
Arrays.asList(b.literal(10), b.literal(20))))
is equivalent to the SQL
SELECT *
FROM Emps
WHERE deptno IN (10, 20)
public org.apache.calcite.rex.RexSubQuery in(org.apache.calcite.rel.RelNode rel, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
public org.apache.calcite.rex.RexNode in(org.apache.calcite.rex.RexNode arg, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Emps")
.filter(
b.in(b.field("deptno"),
b2 -> b2.scan("Depts")
.filter(
b2.eq(b2.field("location"), b2.literal("Boston")))
.project(b.field("deptno"))
.build()))
is equivalent to the SQL
SELECT *
FROM Emps
WHERE deptno IN (SELECT deptno FROM Dept WHERE location = 'Boston')
public org.apache.calcite.rex.RexSubQuery some(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Emps")
.filter(
b.some(b.field("commission"),
SqlStdOperatorTable.GREATER_THAN,
b2 -> b2.scan("Emps")
.filter(
b2.eq(b2.field("job"), b2.literal("Manager")))
.project(b2.field("sal"))
.build()))
is equivalent to the SQL
SELECT *
FROM Emps
WHERE commission > SOME (SELECT sal FROM Emps WHERE job = 'Manager')
or (since SOME
and ANY
are synonyms) the SQL
SELECT *
FROM Emps
WHERE commission > ANY (SELECT sal FROM Emps WHERE job = 'Manager')
public org.apache.calcite.rex.RexNode all(org.apache.calcite.rex.RexNode node, org.apache.calcite.sql.SqlOperator op, Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Emps")
.filter(
b.all(b.field("commission"),
SqlStdOperatorTable.GREATER_THAN,
b2 -> b2.scan("Emps")
.filter(
b2.eq(b2.field("job"), b2.literal("Manager")))
.project(b2.field("sal"))
.build()))
is equivalent to the SQL
SELECT *
FROM Emps
WHERE commission > ALL (SELECT sal FROM Emps WHERE job = 'Manager')
Calcite translates ALL
predicates to NOT SOME
. The following SQL is
equivalent to the previous:
SELECT *
FROM Emps
WHERE NOT (commission <= SOME (SELECT sal FROM Emps WHERE job = 'Manager'))
public org.apache.calcite.rex.RexSubQuery exists(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.filter(
b.exists(b2 ->
b2.scan("Emps")
.filter(
b2.eq(b2.field("job"), b2.literal("Manager")))
.build()))
is equivalent to the SQL
SELECT *
FROM Depts
WHERE EXISTS (SELECT 1 FROM Emps WHERE job = 'Manager')
public org.apache.calcite.rex.RexSubQuery unique(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.filter(
b.exists(b2 ->
b2.scan("Emps")
.filter(
b2.eq(b2.field("job"), b2.literal("Manager")))
.project(b2.field("deptno")
.build()))
is equivalent to the SQL
SELECT *
FROM Depts
WHERE UNIQUE (SELECT deptno FROM Emps WHERE job = 'Manager')
public org.apache.calcite.rex.RexSubQuery scalarQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.project(
b.field("deptno")
b.scalarQuery(b2 ->
b2.scan("Emps")
.aggregate(
b2.eq(b2.field("job"), b2.literal("Manager")))
.build()))
is equivalent to the SQL
SELECT deptno, (SELECT MAX(sal) FROM Emps)
FROM Depts
public org.apache.calcite.rex.RexSubQuery arrayQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.project(
b.field("deptno")
b.arrayQuery(b2 ->
b2.scan("Emps")
.build()))
is equivalent to the SQL
SELECT deptno, ARRAY (SELECT * FROM Emps)
FROM Depts
public org.apache.calcite.rex.RexSubQuery multisetQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.project(
b.field("deptno")
b.multisetQuery(b2 ->
b2.scan("Emps")
.build()))
is equivalent to the SQL
SELECT deptno, MULTISET (SELECT * FROM Emps)
FROM Depts
public org.apache.calcite.rex.RexSubQuery mapQuery(Function<RelBuilder,org.apache.calcite.rel.RelNode> f)
For example,
b.scan("Depts")
.project(
b.field("deptno")
b.multisetQuery(b2 ->
b2.scan("Emps")
.project(b2.field("empno"), b2.field("job"))
.build()))
is equivalent to the SQL
SELECT deptno, MAP (SELECT empno, job FROM Emps)
FROM Depts
public org.apache.calcite.rex.RexNode and(org.apache.calcite.rex.RexNode... operands)
public org.apache.calcite.rex.RexNode and(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
Simplifies the expression a little: e AND TRUE
becomes e
; e AND e2
AND NOT e
becomes e2
.
public org.apache.calcite.rex.RexNode or(org.apache.calcite.rex.RexNode... operands)
public org.apache.calcite.rex.RexNode or(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
public org.apache.calcite.rex.RexNode not(org.apache.calcite.rex.RexNode operand)
public org.apache.calcite.rex.RexNode equals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
=
.public org.apache.calcite.rex.RexNode greaterThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
>
.public org.apache.calcite.rex.RexNode greaterThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
>=
.public org.apache.calcite.rex.RexNode lessThan(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
<
.public org.apache.calcite.rex.RexNode lessThanOrEqual(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
<=
.public org.apache.calcite.rex.RexNode notEquals(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
<>
.public org.apache.calcite.rex.RexNode isNotDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
o0 IS NOT DISTINCT FROM o1
". It is also
equivalent to "o0 = o1 OR (o0 IS NULL AND o1 IS NULL)
".public org.apache.calcite.rex.RexNode isDistinctFrom(org.apache.calcite.rex.RexNode operand0, org.apache.calcite.rex.RexNode operand1)
o0 IS DISTINCT FROM o1
. It is also equivalent to
"NOT (o0 = o1 OR (o0 IS NULL AND o1 IS NULL))
.public org.apache.calcite.rex.RexNode between(org.apache.calcite.rex.RexNode arg, org.apache.calcite.rex.RexNode lower, org.apache.calcite.rex.RexNode upper)
BETWEEN
.public org.apache.calcite.rex.RexNode isNull(org.apache.calcite.rex.RexNode operand)
IS NULL
.public org.apache.calcite.rex.RexNode isNotNull(org.apache.calcite.rex.RexNode operand)
IS NOT NULL
.public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName)
public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision)
public org.apache.calcite.rex.RexNode cast(org.apache.calcite.rex.RexNode expr, org.apache.calcite.sql.type.SqlTypeName typeName, int precision, int scale)
public org.apache.calcite.rex.RexNode alias(org.apache.calcite.rex.RexNode expr, @Nullable 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 org.apache.calcite.rex.RexNode desc(org.apache.calcite.rex.RexNode node)
public org.apache.calcite.rex.RexNode nullsLast(org.apache.calcite.rex.RexNode node)
public org.apache.calcite.rex.RexNode nullsFirst(org.apache.calcite.rex.RexNode node)
public org.apache.calcite.rex.RexWindowBound unboundedPreceding()
UNBOUNDED PRECEDING
window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound)
and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound)
.public org.apache.calcite.rex.RexWindowBound preceding(org.apache.calcite.rex.RexNode bound)
bound PRECEDING
window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound)
and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound)
.public org.apache.calcite.rex.RexWindowBound currentRow()
CURRENT ROW
window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound)
and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound)
.public org.apache.calcite.rex.RexWindowBound following(org.apache.calcite.rex.RexNode bound)
bound FOLLOWING
window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound)
and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound)
.public org.apache.calcite.rex.RexWindowBound unboundedFollowing()
UNBOUNDED FOLLOWING
window bound, for use in methods such as RelBuilder.OverCall.rowsFrom(RexWindowBound)
and RelBuilder.OverCall.rangeBetween(RexWindowBound,
RexWindowBound)
.public RelBuilder.GroupKey groupKey()
public RelBuilder.GroupKey groupKey(org.apache.calcite.rex.RexNode... nodes)
public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
@Deprecated public RelBuilder.GroupKey groupKey(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, boolean indicator, Iterable<? extends Iterable<? extends org.apache.calcite.rex.RexNode>> nodeLists)
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(org.apache.calcite.util.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(org.apache.calcite.util.ImmutableBitSet groupSet, Iterable<? extends org.apache.calcite.util.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
.
It is possible for groupSet
to be strict superset of all groupSets
. For
example, in the pseudo SQL
GROUP BY 0, 1, 2
GROUPING SETS ((0, 1), 0)
column 2 does not appear in either grouping set. This is not valid SQL. We can approximate
in actual SQL by adding an extra grouping set and filtering out using HAVING
, as
follows:
GROUP BY GROUPING SETS ((0, 1, 2), (0, 1), 0)
HAVING GROUPING_ID(0, 1, 2) <> 0
@Deprecated public RelBuilder.GroupKey groupKey(org.apache.calcite.util.ImmutableBitSet groupSet, boolean indicator, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.util.ImmutableBitSet> groupSets)
groupKey(ImmutableBitSet, Iterable)
.@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
@Deprecated public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, org.apache.calcite.rex.RexNode filter, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
public RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, Iterable<? extends org.apache.calcite.rex.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(org.apache.calcite.sql.SqlAggFunction aggFunction, org.apache.calcite.rex.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(org.apache.calcite.rel.core.AggregateCall a)
AggregateCall
.public RelBuilder.AggCall aggregateCall(org.apache.calcite.rel.core.AggregateCall a, org.apache.calcite.util.mapping.Mapping mapping)
AggregateCall
, applying a
mapping.protected RelBuilder.AggCall aggregateCall(org.apache.calcite.sql.SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, @Nullable org.apache.calcite.rex.RexNode filter, @Nullable com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> distinctKeys, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> orderKeys, @Nullable String alias, com.google.common.collect.ImmutableList<org.apache.calcite.rex.RexNode> operands)
public RelBuilder.AggCall count(org.apache.calcite.rex.RexNode... operands)
COUNT
aggregate function.public RelBuilder.AggCall count(Iterable<? extends org.apache.calcite.rex.RexNode> operands)
COUNT
aggregate function.public RelBuilder.AggCall count(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode... operands)
COUNT
aggregate function, optionally distinct and with an
alias.public RelBuilder.AggCall count(boolean distinct, @Nullable String alias, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
COUNT
aggregate function, optionally distinct and with an
alias.public RelBuilder.AggCall countStar(@Nullable String alias)
COUNT(*)
aggregate function.public RelBuilder.AggCall sum(org.apache.calcite.rex.RexNode operand)
SUM
aggregate function.public RelBuilder.AggCall sum(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
SUM
aggregate function, optionally distinct and with an alias.public RelBuilder.AggCall avg(org.apache.calcite.rex.RexNode operand)
AVG
aggregate function.public RelBuilder.AggCall avg(boolean distinct, @Nullable String alias, org.apache.calcite.rex.RexNode operand)
AVG
aggregate function, optionally distinct and with an alias.public RelBuilder.AggCall min(org.apache.calcite.rex.RexNode operand)
MIN
aggregate function.public RelBuilder.AggCall min(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
MIN
aggregate function, optionally with an alias.public RelBuilder.AggCall max(org.apache.calcite.rex.RexNode operand)
MAX
aggregate function, optionally with an alias.public RelBuilder.AggCall max(@Nullable String alias, org.apache.calcite.rex.RexNode operand)
MAX
aggregate function.public org.apache.calcite.rex.RexNode patternField(String alpha, org.apache.calcite.rel.type.RelDataType type, int i)
alpha
- the pattern nametype
- Type of fieldi
- Ordinal of fieldpublic org.apache.calcite.rex.RexNode patternConcat(Iterable<? extends org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternConcat(org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternAlter(Iterable<? extends org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternAlter(org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternQuantify(Iterable<? extends org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternQuantify(org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternPermute(Iterable<? extends org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternPermute(org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode patternExclude(org.apache.calcite.rex.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(org.apache.calcite.rex.RexNode period)
Snapshot
of a given snapshot period.
Returns this builder.
period
- Name of table (can optionally be qualified)public org.apache.calcite.rex.RexNode cursor(int inputCount, int ordinal)
CURSOR
function by ordinal.inputCount
- Number of inputsordinal
- The reference to the relational inputpublic RelBuilder functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, org.apache.calcite.rex.RexNode... operands)
TableFunctionScan
.public RelBuilder functionScan(org.apache.calcite.sql.SqlOperator operator, int inputCount, Iterable<? extends org.apache.calcite.rex.RexNode> operands)
TableFunctionScan
.public RelBuilder filter(org.apache.calcite.rex.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 org.apache.calcite.rex.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<org.apache.calcite.rel.core.CorrelationId> variablesSet, org.apache.calcite.rex.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<org.apache.calcite.rel.core.CorrelationId> variablesSet, Iterable<? extends org.apache.calcite.rex.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 simplification is on and the result is TRUE, no filter is created.
public RelBuilder project(org.apache.calcite.rex.RexNode... nodes)
Project
of the given expressions.public RelBuilder project(Iterable<? extends org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode> nodes, Iterable<? extends String> fieldNames)
Project
of the given list of expressions and field names.nodes
- ExpressionsfieldNames
- field names for expressionspublic RelBuilder project(Iterable<? extends org.apache.calcite.rex.RexNode> nodes, Iterable<? extends 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(org.apache.calcite.rex.RexNode... nodes)
Project
of all original fields, plus the given expressions.public RelBuilder projectPlus(Iterable<org.apache.calcite.rex.RexNode> nodes)
Project
of all original fields, plus the given list of expressions.public RelBuilder projectExcept(org.apache.calcite.rex.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<org.apache.calcite.rex.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 org.apache.calcite.rex.RexNode> nodes, @Nullable Iterable<? extends 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<? extends 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<org.apache.calcite.rel.core.AggregateCall> aggregateCalls)
Aggregate
with an array of AggregateCall
s.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, org.apache.calcite.rel.type.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 RepeatUnion
all
- 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 RepeatUnion
all
- Whether duplicates are considerediterationLimit
- Maximum number of iterations; negative value means no limitpublic RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition0, org.apache.calcite.rex.RexNode... conditions)
Join
with an array of conditions.public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, Iterable<? extends org.apache.calcite.rex.RexNode> conditions)
Join
with multiple conditions.public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition)
Join
with one condition.public RelBuilder join(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rex.RexNode condition, Set<org.apache.calcite.rel.core.CorrelationId> variablesSet)
Join
with correlating variables.public RelBuilder correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, org.apache.calcite.rex.RexNode... requiredFields)
Correlate
with a CorrelationId
and an array of fields that are used
by correlation.public RelBuilder correlate(org.apache.calcite.rel.core.JoinRelType joinType, org.apache.calcite.rel.core.CorrelationId correlationId, Iterable<? extends org.apache.calcite.rex.RexNode> requiredFields)
Correlate
with a CorrelationId
and a list of fields that are used
by correlation.public RelBuilder join(org.apache.calcite.rel.core.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 org.apache.calcite.rex.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(org.apache.calcite.rex.RexNode... conditions)
Join
with JoinRelType.SEMI
.semiJoin(Iterable)
public RelBuilder antiJoin(Iterable<? extends org.apache.calcite.rex.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(org.apache.calcite.rex.RexNode... conditions)
antiJoin(Iterable)
public RelBuilder as(String alias)
public RelBuilder values(@Nullable 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(org.apache.calcite.rel.type.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<org.apache.calcite.rex.RexLiteral>> tupleList, org.apache.calcite.rel.type.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(org.apache.calcite.rel.type.RelDataType rowType)
Values
with a specified row type and zero rows.rowType
- Row typepublic RelBuilder limit(int offset, int fetch)
public RelBuilder exchange(org.apache.calcite.rel.RelDistribution distribution)
public RelBuilder sortExchange(org.apache.calcite.rel.RelDistribution distribution, org.apache.calcite.rel.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(org.apache.calcite.rex.RexNode... nodes)
Sort
by expressions.public RelBuilder sort(Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Sort
by expressions.public RelBuilder sortLimit(int offset, int fetch, org.apache.calcite.rex.RexNode... nodes)
Sort
by expressions, with limit and offset.public RelBuilder sort(org.apache.calcite.rel.RelCollation collation)
Sort
by specifying collations.public RelBuilder sortLimit(int offset, int fetch, Iterable<? extends org.apache.calcite.rex.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 sortLimit(@Nullable org.apache.calcite.rex.RexNode offsetNode, @Nullable org.apache.calcite.rex.RexNode fetchNode, Iterable<? extends org.apache.calcite.rex.RexNode> nodes)
Sort
by a list of expressions, with limitNode and offsetNode.offsetNode
- RexLiteral means number of rows to skip is deterministic, RexDynamicParam
means number of rows to skip is dynamic.fetchNode
- RexLiteral means maximum number of rows to fetch is deterministic,
RexDynamicParam mean maximum number is dynamic.nodes
- Sort expressionspublic RelBuilder convert(org.apache.calcite.rel.type.RelDataType castRowType, boolean rename)
The desired row type and the row type to be converted must have the same number of fields.
castRowType
- row type after castrename
- if true, use field names from castRowType; if false, preserve field names from
relpublic RelBuilder permute(org.apache.calcite.util.mapping.Mapping mapping)
public RelBuilder match(org.apache.calcite.rex.RexNode pattern, boolean strictStart, boolean strictEnd, Map<String,org.apache.calcite.rex.RexNode> patternDefinitions, Iterable<? extends org.apache.calcite.rex.RexNode> measureList, org.apache.calcite.rex.RexNode after, Map<String,? extends SortedSet<String>> subsets, boolean allRows, Iterable<? extends org.apache.calcite.rex.RexNode> partitionKeys, Iterable<? extends org.apache.calcite.rex.RexNode> orderKeys, org.apache.calcite.rex.RexNode interval)
Match
.public RelBuilder pivot(RelBuilder.GroupKey groupKey, Iterable<? extends RelBuilder.AggCall> aggCalls, Iterable<? extends org.apache.calcite.rex.RexNode> axes, Iterable<? extends Map.Entry<String,? extends Iterable<? extends org.apache.calcite.rex.RexNode>>> values)
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 unpivot(boolean includeNulls, Iterable<String> measureNames, Iterable<String> axisNames, Iterable<? extends Map.Entry<? extends List<? extends org.apache.calcite.rex.RexLiteral>,? extends List<? extends org.apache.calcite.rex.RexNode>>> axisMap)
To achieve the same effect as the SQL
SELECT * FROM (SELECT deptno, job, sal, comm FROM emp) UNPIVOT INCLUDE NULLS (remuneration FOR remuneration_type IN (comm AS 'commission', sal AS 'salary'))
use the builder as follows:
RelBuilder b; b.scan("EMP"); final List<String> measureNames = Arrays.asList("REMUNERATION"); final List<String> axisNames = Arrays.asList("REMUNERATION_TYPE"); final Map<List<RexLiteral>, List<RexNode>> axisMap = ImmutableMap.<List<RexLiteral>, List<RexNode>>builder() .put(Arrays.asList(b.literal("commission")), Arrays.asList(b.field("COMM"))) .put(Arrays.asList(b.literal("salary")), Arrays.asList(b.field("SAL"))) .build(); b.unpivot(false, measureNames, axisNames, axisMap);
The query generates two columns: remuneration_type
(an axis column) and remuneration
(a measure column). Axis columns contain values to indicate the source of the
row (in this case, 'salary'
if the row came from the sal
column, and 'commission'
if the row came from the comm
column).
includeNulls
- Whether to include NULL values in the outputmeasureNames
- Names of columns to be generated to hold pivoted measuresaxisNames
- Names of columns to be generated to hold qualifying valuesaxisMap
- Mapping from the columns that hold measures to the values that the axis
columns will hold in the generated rowspublic RelBuilder hints(org.apache.calcite.rel.hint.RelHint... hints)
The redundant hints would be eliminated.
hints
- HintsAssertionError
- if the top relational expression does not implement Hintable
public RelBuilder hints(Iterable<org.apache.calcite.rel.hint.RelHint> hints)
The redundant hints would be eliminated.
hints
- HintsAssertionError
- if the top relational expression does not implement Hintable
public void clear()
The builder's state is now the same as when it was created.
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.