Package org.apache.calcite.materialize
Class LatticeSuggester
- java.lang.Object
-
- org.apache.calcite.materialize.LatticeSuggester
-
public class LatticeSuggester extends java.lang.Object
Algorithm that suggests a set of lattices.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LatticeSuggester.BaseColRef
Reference to a base column.private static class
LatticeSuggester.ColRef
Column reference.private static class
LatticeSuggester.DerivedColRef
Reference to a derived column (that is, an expression).(package private) static class
LatticeSuggester.Frame
Information about the parent of fields from a relational expression.private static class
LatticeSuggester.Hop
A hop is a join condition.private static class
LatticeSuggester.MutableMeasure
An aggregate call.private static class
LatticeSuggester.Query
Holds state for a particular query graph.private static class
LatticeSuggester.StepRef
Use of a step within a query.private static class
LatticeSuggester.TableRef
Use of a table within a query.
-
Field Summary
Fields Modifier and Type Field Description private boolean
evolve
Whether to try to extend an existing lattice when adding a lattice.(package private) java.util.Map<java.lang.String,Lattice>
latticeMap
Lattices, indexed by digest.private java.util.Map<Lattice,Lattice>
obsoleteLatticeMap
Lattices that have been made obsolete.private static HepProgram
PROGRAM
(package private) LatticeSpace
space
-
Constructor Summary
Constructors Constructor Description LatticeSuggester(FrameworkConfig config)
Creates a LatticeSuggester.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Lattice>
addQuery(RelNode r)
Adds a query.private static java.lang.String
deriveAlias(LatticeSuggester.MutableMeasure measure, LatticeSuggester.DerivedColRef derivedColRef)
Derives the alias of an expression that is the argument to a measure.private Lattice
findMatch(Lattice lattice, MutableNode mutableNode)
Returns the best match for a lattice.private LatticeSuggester.Frame
frame(LatticeSuggester.Query q, RelNode r)
java.util.Set<Lattice>
getLatticeSet()
Returns the minimal set of lattices necessary to cover all of the queries seen.private java.util.function.Function<Lattice.Column,Lattice.Column>
mapper(Lattice lattice, Lattice.Builder builder)
private int
matchQuality(Lattice lattice, Lattice target)
private static <E> java.util.Set<E>
minus(java.util.Collection<E> c, java.util.Collection<E> c2)
-
-
-
Field Detail
-
space
final LatticeSpace space
-
PROGRAM
private static final HepProgram PROGRAM
-
latticeMap
final java.util.Map<java.lang.String,Lattice> latticeMap
Lattices, indexed by digest. Uses LinkedHashMap for determinacy.
-
obsoleteLatticeMap
private final java.util.Map<Lattice,Lattice> obsoleteLatticeMap
Lattices that have been made obsolete. Key is the obsolete lattice, value is the lattice that superseded it.
-
evolve
private final boolean evolve
Whether to try to extend an existing lattice when adding a lattice.
-
-
Constructor Detail
-
LatticeSuggester
public LatticeSuggester(FrameworkConfig config)
Creates a LatticeSuggester.
-
-
Method Detail
-
getLatticeSet
public java.util.Set<Lattice> getLatticeSet()
Returns the minimal set of lattices necessary to cover all of the queries seen. Any lattices that are subsumed by other lattices are not included.
-
addQuery
public java.util.List<Lattice> addQuery(RelNode r)
Adds a query.It may fit within an existing lattice (or lattices). Or it may need a new lattice, or an extension to an existing lattice.
- Parameters:
r
- Relational expression for a query- Returns:
- A list of join graphs: usually 1; more if the query contains a cartesian product; zero if the query graph is cyclic
-
deriveAlias
private static java.lang.String deriveAlias(LatticeSuggester.MutableMeasure measure, LatticeSuggester.DerivedColRef derivedColRef)
Derives the alias of an expression that is the argument to a measure.For example, if the measure is called "sum_profit" and the aggregate function is "sum", returns "profit".
-
findMatch
private Lattice findMatch(Lattice lattice, MutableNode mutableNode)
Returns the best match for a lattice. If no match, registers the lattice and returns it. Never returns null.
-
mapper
private java.util.function.Function<Lattice.Column,Lattice.Column> mapper(Lattice lattice, Lattice.Builder builder)
-
minus
private static <E> java.util.Set<E> minus(java.util.Collection<E> c, java.util.Collection<E> c2)
-
frame
private LatticeSuggester.Frame frame(LatticeSuggester.Query q, RelNode r)
-
-