Package net.hydromatic.morel.ast
Class FromBuilder
java.lang.Object
net.hydromatic.morel.ast.FromBuilder
Builds a
Core.From.
Simplifies the following patterns:
- Converts "from v in list" to "list"
(only works in
buildSimplify(), notbuild()); - Removes "where true" steps;
- Removes empty "order" steps;
- Removes trivial
yield, e.g. "from v in list where condition yield v" becomes "from v in list where condition"; - Inlines
fromexpressions, e.g. "from v in (from w in list)" becomes "from w in list yield {v = w}".
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classCalls the method to re-register a step.private static enumCategory of expression passed to "yield". -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @Nullable Environmentprivate intIf non-negative, flags that particular step should be removed if it is the last step.private intIf non-negative, flags that particular step should be removed if it is not the last step.private final List<Core.FromStep> private final TypeSystem -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAll(Iterable<? extends Core.FromStep> steps) private FromBuilderaddStep(Core.FromStep step) bindings()Returns the bindings available after the most recent step.build()private Core.Expbuild(boolean simplify) Asbuild(boolean), but also simplifies "from x in list" to "list".group(SortedMap<Core.IdPat, Core.Exp> groupExps, SortedMap<Core.IdPat, Core.Aggregate> aggregates) private booleanisRename(Core.Tuple tuple) Returns whether tuple is something like "{i = j, j = x}".private static booleanReturns whether tuple is something like "{i = i, j = j}".order(Iterable<Core.OrderItem> orderItems) toString()private static FromBuilder.TupleTypeReturns whether tuple is something like "{i = i, j = j}".Creates a "yield" step.
-
Field Details
-
typeSystem
-
env
-
steps
-
bindings
-
removeIfNotLastIndex
private int removeIfNotLastIndexIf non-negative, flags that particular step should be removed if it is not the last step. (For example, "yield {i = i}", which changes the result shape if the last step but is otherwise a no-op.) -
removeIfLastIndex
private int removeIfLastIndexIf non-negative, flags that particular step should be removed if it is the last step. (For example, we flatten "from p in (from q in list)", to "from q in list yield {p = q}" but we want to remove "yield {p = q}" if it turns out to be the last step.)
-
-
Constructor Details
-
FromBuilder
FromBuilder(TypeSystem typeSystem, @Nullable Environment env)
-
-
Method Details
-
toString
-
bindings
Returns the bindings available after the most recent step. -
addStep
-
suchThat
-
scan
-
scan
-
addAll
-
where
-
skip
-
take
-
group
public FromBuilder group(SortedMap<Core.IdPat, Core.Exp> groupExps, SortedMap<Core.IdPat, Core.Aggregate> aggregates) -
order
-
yield_
-
yield_
-
yield_
Creates a "yield" step.When copying, the
bindings2parameter is theCore.FromStep.bindingsvalue of the current Yield, so that we don't generate new variables (with different ordinals). Later steps are relying on the variables remaining the same. For example, infrom ... yield {a = b} where a > 5the
aina > 5referencesIdPat('a', 0)and we don't want yield to generate anIdPat('a', 1).- Parameters:
uselessIfLast- Whether this Yield will be useless if it is the last step. The expression{x = y}is an example of thisbindings2- Desired bindings, or nullexp- Expression to yield- Returns:
- This FromBuilder, with a Yield added to the list of steps
-
isTrivial
private static boolean isTrivial(Core.Tuple tuple, List<Binding> bindings, @Nullable List<Binding> bindings2) Returns whether tuple is something like "{i = i, j = j}". -
tupleType
private static FromBuilder.TupleType tupleType(Core.Tuple tuple, List<Binding> bindings, @Nullable List<Binding> bindings2) Returns whether tuple is something like "{i = i, j = j}". -
isRename
Returns whether tuple is something like "{i = j, j = x}". -
build
-
build
-
buildSimplify
Asbuild(boolean), but also simplifies "from x in list" to "list".
-