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.
|
private static class |
RelBuilder.AggCallImpl
Implementation of
RelBuilder.AggCall. |
private static class |
RelBuilder.AggCallImpl2
Implementation of
RelBuilder.AggCall that wraps an
AggregateCall. |
private static class |
RelBuilder.Field
A field that belongs to a stack
RelBuilder.Frame. |
private static class |
RelBuilder.Frame
Builder stack frame.
|
static interface |
RelBuilder.GroupKey
Information necessary to create the GROUP BY clause of an Aggregate.
|
protected static class |
RelBuilder.GroupKeyImpl
Implementation of
RelBuilder.GroupKey. |
private static class |
RelBuilder.Registrar
Collects the extra expressions needed for
aggregate(org.apache.calcite.tools.RelBuilder.GroupKey, org.apache.calcite.tools.RelBuilder.AggCall...). |
private class |
RelBuilder.Shifter
Shuttle that shifts a predicate's inputs to the left, replacing early
ones with references to a
RexCorrelVariable. |
| Modifier and Type | Field and Description |
|---|---|
private RelFactories.AggregateFactory |
aggregateFactory |
protected RelOptCluster |
cluster |
private RelFactories.CorrelateFactory |
correlateFactory |
private RelFactories.FilterFactory |
filterFactory |
private static com.google.common.base.Function<RexNode,String> |
FN_TYPE |
private RelFactories.JoinFactory |
joinFactory |
private RelFactories.MatchFactory |
matchFactory |
private RelFactories.ProjectFactory |
projectFactory |
protected RelOptSchema |
relOptSchema |
private RelFactories.TableScanFactory |
scanFactory |
private RelFactories.SemiJoinFactory |
semiJoinFactory |
private RelFactories.SetOpFactory |
setOpFactory |
private RexSimplify |
simplifier |
private RexSimplify |
simplifierUnknownAsFalse |
private boolean |
simplify |
private RelFactories.SortFactory |
sortFactory |
private Deque<RelBuilder.Frame> |
stack |
private RelFactories.ValuesFactory |
valuesFactory |
| Modifier | Constructor and Description |
|---|---|
protected |
RelBuilder(Context context,
RelOptCluster cluster,
RelOptSchema relOptSchema) |
| Modifier and Type | Method and Description |
|---|---|
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
Iterable<RelBuilder.AggCall> aggCalls)
Creates an
Aggregate with a list of
calls. |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
List<AggregateCall> aggregateCalls) |
RelBuilder |
aggregate(RelBuilder.GroupKey groupKey,
RelBuilder.AggCall... aggCalls)
Creates an
Aggregate with an array of
calls. |
RelBuilder.AggCall |
aggregateCall(SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
RexNode filter,
String alias,
Iterable<? extends RexNode> operands)
Creates a call to an aggregate function.
|
RelBuilder.AggCall |
aggregateCall(SqlAggFunction aggFunction,
boolean distinct,
boolean approximate,
RexNode filter,
String alias,
RexNode... operands)
Creates a call to an aggregate function.
|
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.
|
RexNode |
alias(RexNode expr,
String alias)
Returns an expression wrapped in an alias.
|
private boolean |
allNull(Object[] values,
int column,
int columnCount)
Returns whether all values for a given column are null.
|
RexNode |
and(Iterable<? extends RexNode> operands)
Creates an AND.
|
RexNode |
and(RexNode... operands)
Creates an AND.
|
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.
|
RelNode |
build()
Returns the final relational expression.
|
RexNode |
call(SqlOperator operator,
Iterable<? extends RexNode> operands)
Creates a call to a scalar operator.
|
private RexNode |
call(SqlOperator operator,
List<RexNode> operandList)
Creates a call to a scalar operator.
|
RexNode |
call(SqlOperator operator,
RexNode... operands)
Creates a call to a scalar operator.
|
RexNode |
cast(RexNode expr,
SqlTypeName typeName)
Creates an expression that casts an expression to a given type.
|
RexNode |
cast(RexNode expr,
SqlTypeName typeName,
int precision)
Creates an expression that casts an expression to a type with a given name
and precision or length.
|
RexNode |
cast(RexNode expr,
SqlTypeName typeName,
int precision,
int scale)
Creates an expression that casts an expression to a type with a given
name, precision and scale.
|
void |
clear()
Clears the stack.
|
private static RelFieldCollation |
collation(RexNode node,
RelFieldCollation.Direction direction,
RelFieldCollation.NullDirection nullDirection,
List<RexNode> extraNodes) |
RelBuilder |
convert(RelDataType castRowType,
boolean rename)
Creates a projection that converts the current relational expression's
output to a desired row type.
|
private static <E> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<E>> |
copy(Iterable<? extends List<E>> tupleList)
Converts an iterable of lists into an immutable list of immutable lists
with the same contents.
|
RelBuilder.AggCall |
count(boolean distinct,
String alias,
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 |
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
=. |
RexInputRef |
field(int fieldOrdinal)
Creates a reference to an input field by ordinal.
|
RexInputRef |
field(int inputCount,
int inputOrdinal,
int fieldOrdinal)
Creates a reference to a field of a given input relational expression
by ordinal.
|
private RexNode |
field(int inputCount,
int inputOrdinal,
int fieldOrdinal,
boolean alias)
As
field(int, int, int), but if alias is true, the method
may apply an alias to make sure that the field has the same name as in the
input frame. |
RexInputRef |
field(int inputCount,
int inputOrdinal,
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(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(RexNode... predicates)
Creates a
Filter of an array of
predicates. |
RexBuilder |
getRexBuilder()
Returns the builder for
RexNode expressions. |
RelDataTypeFactory |
getTypeFactory()
Returns the type factory.
|
private RelBuilder.GroupKey |
groupKey_(ImmutableBitSet groupSet,
boolean indicator,
com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets) |
RelBuilder.GroupKey |
groupKey()
Creates an empty group key.
|
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)
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)
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.
|
private String |
inferAlias(List<RexNode> exprList,
RexNode expr)
Infers the alias of an expression.
|
private int |
inputOffset(int inputCount,
int inputOrdinal)
Returns the number of fields in all inputs before (to the left of)
the given input.
|
RelBuilder |
intersect(boolean all)
Creates 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) |
RelBuilder |
join(JoinRelType joinType,
RexNode condition0,
RexNode... conditions)
Creates a
Join. |
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(String alias,
RexNode operand)
Creates a call to the MAX aggregate function.
|
RelBuilder.AggCall |
min(String alias,
RexNode operand)
Creates a call to the MIN aggregate function.
|
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). |
private RelBuilder.Frame |
peek_() |
private RelBuilder.Frame |
peek_(int n) |
private RelBuilder.Frame |
peek_(int inputCount,
int inputOrdinal) |
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 |
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. |
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.
|
private void |
replaceTop(RelNode node)
Adds a rel node to the top of the stack while preserving the field names
and aliases.
|
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
SemiJoin. |
RelBuilder |
semiJoin(RexNode... conditions)
Creates a
SemiJoin. |
private RelBuilder |
setOp(boolean all,
SqlKind kind,
int n) |
RelBuilder |
sort(int... fields)
Creates a
Sort by field ordinals. |
RelBuilder |
sort(Iterable<? extends RexNode> nodes)
Creates a
Sort by expressions. |
RelBuilder |
sort(RexNode... nodes)
Creates a
Sort by expressions. |
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.
|
private com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>> |
tupleList(int columnCount,
Object[] values) |
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
private final RelFactories.FilterFactory filterFactory
private final RelFactories.ProjectFactory projectFactory
private final RelFactories.AggregateFactory aggregateFactory
private final RelFactories.SortFactory sortFactory
private final RelFactories.SetOpFactory setOpFactory
private final RelFactories.JoinFactory joinFactory
private final RelFactories.SemiJoinFactory semiJoinFactory
private final RelFactories.CorrelateFactory correlateFactory
private final RelFactories.ValuesFactory valuesFactory
private final RelFactories.TableScanFactory scanFactory
private final RelFactories.MatchFactory matchFactory
private final Deque<RelBuilder.Frame> stack
private final boolean simplify
private final RexSimplify simplifier
private final RexSimplify simplifierUnknownAsFalse
protected RelBuilder(Context context, RelOptCluster cluster, RelOptSchema relOptSchema)
public static RelBuilder create(FrameworkConfig config)
public RelDataTypeFactory getTypeFactory()
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 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.
private void replaceTop(RelNode node)
public RelBuilder pushAll(Iterable<? extends RelNode> nodes)
public RelNode build()
Throws if the stack is empty.
public RelNode peek()
private RelBuilder.Frame peek_()
public RelNode peek(int n)
n positions from the top of the
stack, but does not remove it.private RelBuilder.Frame peek_(int n)
public RelNode peek(int inputCount, int inputOrdinal)
n positions from the top of the
stack, but does not remove it.private RelBuilder.Frame peek_(int inputCount, int inputOrdinal)
private int inputOffset(int inputCount,
int inputOrdinal)
inputCount - Number of inputsinputOrdinal - Input ordinalpublic 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 inputprivate RexNode field(int inputCount, int inputOrdinal, int fieldOrdinal, boolean alias)
field(int, int, int), but if alias is true, the method
may apply an alias to make sure that the field has the same name as in the
input frame. If no alias is applied the expression is definitely a
RexInputRef.public 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(Iterable<String> fieldNames)
public com.google.common.collect.ImmutableList<RexNode> fields(Mappings.TargetMapping mapping)
public RexNode call(SqlOperator operator, RexNode... operands)
private RexNode call(SqlOperator operator, List<RexNode> operandList)
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 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, boolean indicator, Iterable<? extends Iterable<? extends RexNode>> nodeLists)
public RelBuilder.GroupKey groupKey(int... fieldOrdinals)
public RelBuilder.GroupKey groupKey(String... fieldNames)
public RelBuilder.GroupKey groupKey(ImmutableBitSet groupSet, com.google.common.collect.ImmutableList<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, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
groupKey(ImmutableBitSet, ImmutableList).private RelBuilder.GroupKey groupKey_(ImmutableBitSet groupSet, boolean indicator, com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets)
@Deprecated public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, RexNode filter, String alias, RexNode... operands)
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)
public RelBuilder.AggCall aggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, RexNode filter, String alias, Iterable<? extends RexNode> operands)
public RelBuilder.AggCall count(boolean distinct, String alias, RexNode... operands)
public RelBuilder.AggCall countStar(String alias)
public RelBuilder.AggCall sum(boolean distinct, String alias, RexNode operand)
public RelBuilder.AggCall avg(boolean distinct, String alias, RexNode operand)
public RelBuilder.AggCall min(String alias, RexNode operand)
public RelBuilder.AggCall max(String alias, RexNode operand)
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 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 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 project(RexNode... nodes)
Project of the given
expressions.public 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 typeprivate String inferAlias(List<RexNode> exprList, RexNode expr)
If the expression was created by alias(org.apache.calcite.rex.RexNode, java.lang.String), replaces the expression
in the project list.
public 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, Iterable<RelBuilder.AggCall> aggCalls)
Aggregate with a list of
calls.private RelBuilder setOp(boolean all, SqlKind kind, int n)
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 join(JoinRelType joinType, RexNode condition0, RexNode... conditions)
Join.public RelBuilder join(JoinRelType joinType, Iterable<? extends RexNode> conditions)
Join with multiple
conditions.public RelBuilder join(JoinRelType joinType, RexNode condition)
public RelBuilder join(JoinRelType joinType, RexNode condition, Set<CorrelationId> variablesSet)
Join with correlating
variables.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)
SemiJoin.public RelBuilder semiJoin(RexNode... conditions)
SemiJoin.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 - Valuesprivate com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<RexLiteral>> tupleList(int columnCount, Object[] values)
private boolean allNull(Object[] values, int column, int columnCount)
public 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 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 typeprivate static <E> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableList<E>> copy(Iterable<? extends List<E>> tupleList)
public RelBuilder limit(int offset, int fetch)
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 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 expressionsprivate static RelFieldCollation collation(RexNode node, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection, List<RexNode> extraNodes)
public 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 aggregate(RelBuilder.GroupKey groupKey, List<AggregateCall> aggregateCalls)
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 void clear()
The builder's state is now the same as when it was created.
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.