public class RexProgram extends Object
Programs are immutable. It may help to use a RexProgramBuilder,
which has the same relationship to RexProgram as StringBuffer
does has to String.
A program can contain aggregate functions. If it does, the arguments to
each aggregate function must be an RexInputRef.
RexProgramBuilder| Constructor and Description |
|---|
RexProgram(RelDataType inputRowType,
List<? extends RexNode> exprs,
List<RexLocalRef> projects,
RexLocalRef condition,
RelDataType outputRowType)
Creates a program.
|
| Modifier and Type | Method and Description |
|---|---|
RelWriter |
collectExplainTerms(String prefix,
RelWriter pw) |
RelWriter |
collectExplainTerms(String prefix,
RelWriter pw,
SqlExplainLevel level)
Collects the expressions in this program into a list of terms and values.
|
boolean |
containsAggs()
Returns whether this program contains windowed aggregate functions
|
static RexProgram |
create(RelDataType inputRowType,
List<? extends RexNode> projectExprs,
RexNode conditionExpr,
List<String> fieldNames,
RexBuilder rexBuilder)
Creates a program which calculates projections and filters rows based
upon a condition.
|
static RexProgram |
create(RelDataType inputRowType,
List<? extends RexNode> projectExprs,
RexNode conditionExpr,
RelDataType outputRowType,
RexBuilder rexBuilder)
Creates a program which calculates projections and filters rows based
upon a condition.
|
static RexProgram |
createIdentity(RelDataType rowType)
Creates the identity program.
|
static RexProgram |
createIdentity(RelDataType rowType,
RelDataType outputRowType)
Creates a program that projects its input fields but with possibly
different names for the output fields.
|
static void |
deduceCollations(List<RelCollation> outputCollations,
int sourceCount,
List<RexLocalRef> refs,
List<RelCollation> inputCollations)
Given a list of expressions and a description of which are ordered,
computes a list of collations.
|
RexNode |
expandLocalRef(RexLocalRef ref)
Fully expands a RexLocalRef back into a pure RexNode tree containing no
RexLocalRefs (reversing the effect of common subexpression elimination).
|
RelWriter |
explainCalc(RelWriter pw)
Writes an explanation of the expressions in this program to a plan
writer.
|
RexNode |
gatherExpr(RexNode expr) |
List<RelCollation> |
getCollations(List<RelCollation> inputCollations)
Given a list of collations which hold for the input to this program,
returns a list of collations which hold for its output.
|
RexLocalRef |
getCondition()
Returns the field reference of this program's filter condition, or null
if there is no condition.
|
HashSet<String> |
getCorrelVariableNames()
Returns the set of correlation variables used (read) by this program.
|
int |
getExprCount()
Returns the number of expressions in this program.
|
List<RexNode> |
getExprList()
Returns the common sub-expressions of this program.
|
RelDataType |
getInputRowType()
Returns the type of the input row to the program.
|
List<Pair<RexLocalRef,String>> |
getNamedProjects()
Returns a list of project expressions and their field names.
|
RelDataType |
getOutputRowType()
Returns the type of the output row from this program.
|
Permutation |
getPermutation()
Returns a permutation, if this program is a permutation, otherwise null.
|
List<RexLocalRef> |
getProjectList()
Returns an array of references to the expressions which this program is
to project.
|
int[] |
getReferenceCounts()
Gets reference counts for each expression in the program, where the
references are detected from later expressions in the same program, as
well as the project list and condition.
|
int |
getSourceField(int outputOrdinal)
Returns the input field that an output field is populated from, or -1 if
it is populated from an expression.
|
boolean |
isConstant(RexNode ref)
Returns whether an expression is constant.
|
boolean |
isNormalized(boolean fail,
RexBuilder rexBuilder)
Returns whether this program is in canonical form.
|
boolean |
isNull(RexNode expr)
Returns whether an expression always evaluates to null.
|
boolean |
isPermutation()
Returns whether this program is a permutation of its inputs.
|
boolean |
isTrivial()
Returns whether this program returns its input exactly.
|
boolean |
isValid(boolean fail)
Checks that this program is valid.
|
boolean |
projectsIdentity(boolean fail)
Returns whether the fields on the leading edge of the project list are
the input fields.
|
boolean |
projectsOnlyIdentity()
Returns whether this program projects precisely its input fields.
|
Pair<com.google.common.collect.ImmutableList<RexNode>,com.google.common.collect.ImmutableList<RexNode>> |
split()
Splits this program into a list of project expressions and a list of
filter expressions.
|
String |
toString() |
public RexProgram(RelDataType inputRowType, List<? extends RexNode> exprs, List<RexLocalRef> projects, RexLocalRef condition, RelDataType outputRowType)
The expressions must be valid: they must not contain common expressions, forward references, or non-trivial aggregates.
inputRowType - Input row typeexprs - Common expressionsprojects - Projection expressionscondition - Condition expression. If null, calculator does not
filter rowsoutputRowType - Description of the row produced by the programpublic List<RexNode> getExprList()
The list is never null but may be empty; each the expression in the list is not null; and no further reduction into smaller common sub-expressions is possible.
public List<RexLocalRef> getProjectList()
public List<Pair<RexLocalRef,String>> getNamedProjects()
public RexLocalRef getCondition()
public static RexProgram create(RelDataType inputRowType, List<? extends RexNode> projectExprs, RexNode conditionExpr, RelDataType outputRowType, RexBuilder rexBuilder)
projectExprs - Project expressionsconditionExpr - Condition on which to filter rows, or null if rows
are not to be filteredoutputRowType - Output row typerexBuilder - Builder of rex expressionspublic static RexProgram create(RelDataType inputRowType, List<? extends RexNode> projectExprs, RexNode conditionExpr, List<String> fieldNames, RexBuilder rexBuilder)
projectExprs - Project expressionsconditionExpr - Condition on which to filter rows, or null if rows
are not to be filteredfieldNames - Names of projected fieldsrexBuilder - Builder of rex expressionspublic RelWriter explainCalc(RelWriter pw)
pw - Plan writerpublic RelWriter collectExplainTerms(String prefix, RelWriter pw, SqlExplainLevel level)
prefix - Prefix for term names, usually the empty string, but useful
if a relational expression contains more than one programpw - Plan writerpublic int getExprCount()
public static RexProgram createIdentity(RelDataType rowType)
public static RexProgram createIdentity(RelDataType rowType, RelDataType outputRowType)
public RelDataType getInputRowType()
public boolean containsAggs()
public RelDataType getOutputRowType()
public boolean isValid(boolean fail)
If fail is true, executes assert false, so
will throw an AssertionError if assertions are enabled. If
fail is false, merely returns whether the program is valid.
fail - Whether to failAssertionError - if program is invalid and fail is
true and assertions are enabledpublic boolean isNull(RexNode expr)
Like RexUtil.isNull(RexNode), null literals are null, and
casts of null literals are null. But this method also regards references
to null expressions as null.
expr - Expressionpublic RexNode expandLocalRef(RexLocalRef ref)
program.expandLocalRef(program.getCondition())
will return the expansion of a program's condition.ref - a RexLocalRef from this programpublic Pair<com.google.common.collect.ImmutableList<RexNode>,com.google.common.collect.ImmutableList<RexNode>> split()
Neither list is null. The filters are evaluated first.
public List<RelCollation> getCollations(List<RelCollation> inputCollations)
public static void deduceCollations(List<RelCollation> outputCollations, int sourceCount, List<RexLocalRef> refs, List<RelCollation> inputCollations)
public boolean projectsIdentity(boolean fail)
fail - Whether to throw an assert failure if does not project
identitypublic boolean projectsOnlyIdentity()
public boolean isTrivial()
This is a stronger condition than projectsIdentity(boolean).
public int[] getReferenceCounts()
public boolean isConstant(RexNode ref)
public int getSourceField(int outputOrdinal)
public boolean isPermutation()
public Permutation getPermutation()
public HashSet<String> getCorrelVariableNames()
public boolean isNormalized(boolean fail,
RexBuilder rexBuilder)
fail - Whether to throw an assertion error if not in canonical
formrexBuilder - Rex builderCopyright © 2012–2015 The Apache Software Foundation. All rights reserved.