Package org.apache.calcite.materialize
Class Lattice
- java.lang.Object
-
- org.apache.calcite.materialize.Lattice
-
@ParametersAreNonnullByDefault public class Lattice extends java.lang.Object
Structure that allows materialized views based upon a star schema to be recognized and recommended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Lattice.BaseColumn
Column in a lattice.static class
Lattice.Builder
Lattice builder.static class
Lattice.Column
Column in a lattice.static class
Lattice.DerivedColumn
Column in a lattice that is based upon a SQL expression.private static class
Lattice.Edge
Edge in the temporary graph.static class
Lattice.Measure
A measure within aLattice
.static class
Lattice.SqlWriter
The information necessary to convert a column to SQL.static class
Lattice.Tile
Materialized aggregate within a lattice.static class
Lattice.TileBuilder
Tile builder.private static class
Lattice.Vertex
Vertex in the temporary graph.
-
Field Summary
Fields Modifier and Type Field Description boolean
algorithm
long
algorithmMaxMillis
boolean
auto
com.google.common.collect.ImmutableList<Lattice.Column>
columns
com.google.common.collect.ImmutableList<Lattice.Measure>
defaultMeasures
LatticeRootNode
rootNode
CalciteSchema
rootSchema
double
rowCountEstimate
LatticeStatisticProvider
statisticProvider
com.google.common.collect.ImmutableList<Lattice.Tile>
tiles
-
Constructor Summary
Constructors Modifier Constructor Description private
Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode, boolean auto, boolean algorithm, long algorithmMaxMillis, LatticeStatisticProvider.Factory statisticProviderFactory, java.lang.Double rowCountEstimate, com.google.common.collect.ImmutableList<Lattice.Column> columns, com.google.common.collect.ImmutableSortedSet<Lattice.Measure> defaultMeasures, com.google.common.collect.ImmutableList<Lattice.Tile> tiles)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Lattice.Builder
builder(CalciteSchema calciteSchema, java.lang.String sql)
(package private) static Lattice.Builder
builder(LatticeSpace space, CalciteSchema calciteSchema, java.lang.String sql)
(package private) Pair<Path,java.lang.Integer>
columnToPathOffset(Lattice.BaseColumn c)
java.lang.Iterable<? extends Lattice.Tile>
computeTiles()
java.lang.String
countSql(ImmutableBitSet groupSet)
Returns a SQL query that counts the number of distinct values of the attributes given ingroupSet
.static Lattice
create(CalciteSchema schema, java.lang.String sql, boolean auto)
Creates a Lattice.Lattice.SqlWriter
createSqlWriter(SqlDialect dialect, java.lang.StringBuilder buf, java.util.function.IntFunction<SqlNode> field)
Creates a context to which SQL can be generated.StarTable
createStarTable()
int
firstColumn(java.lang.String tableAlias)
Returns the ordinal, within all of the columns in this Lattice, of the first column in the table with a given alias.double
getFactRowCount()
Returns an estimate of the number of rows in the un-aggregated star.static double
getRowCount(double factCount, double... columnCounts)
Returns an estimate of the number of rows in the tile with the given dimensions.static double
getRowCount(double factCount, java.util.List<java.lang.Double> columnCounts)
Returns an estimate of the number of rows in the tile with the given dimensions.double
getRowCount(java.util.List<Lattice.Column> columns)
Returns an estimate of the number of rows in the tile with the given dimensions.private static int[][]
grab(java.util.List<RelNode> leaves, RexNode rex)
Converts an "t1.c1 = t2.c2" expression into two (input, field) pairs.private static int[]
inputField(java.util.List<RelNode> leaves, RexNode rex)
Converts an expression into an (input, field) pair.private boolean
isValid(Litmus litmus)
private static boolean
populate(java.util.List<RelNode> nodes, java.util.List<int[][]> tempLinks, RelNode rel)
private static void
populateAliases(SqlNode from, java.util.List<java.lang.String> aliases, java.lang.String current)
java.lang.String
sql(ImmutableBitSet groupSet, boolean group, java.util.List<Lattice.Measure> aggCallList)
Generates a SQL query to populate a tile of the lattice specified by a given set of columns and measures, optionally grouping.java.lang.String
sql(ImmutableBitSet groupSet, java.util.List<Lattice.Measure> aggCallList)
Generates a SQL query to populate a tile of the lattice specified by a given set of columns and measures.java.util.Set<LatticeTable>
tables()
Returns the set of tables in this lattice.private Lattice.Measure
toMeasure(AggregateCall aggCall)
java.util.List<Lattice.Measure>
toMeasures(java.util.List<AggregateCall> aggCallList)
java.lang.String
toString()
java.util.List<java.lang.String>
uniqueColumnNames()
-
-
-
Field Detail
-
rootSchema
public final CalciteSchema rootSchema
-
rootNode
public final LatticeRootNode rootNode
-
columns
public final com.google.common.collect.ImmutableList<Lattice.Column> columns
-
auto
public final boolean auto
-
algorithm
public final boolean algorithm
-
algorithmMaxMillis
public final long algorithmMaxMillis
-
rowCountEstimate
public final double rowCountEstimate
-
defaultMeasures
public final com.google.common.collect.ImmutableList<Lattice.Measure> defaultMeasures
-
tiles
public final com.google.common.collect.ImmutableList<Lattice.Tile> tiles
-
statisticProvider
public final LatticeStatisticProvider statisticProvider
-
-
Constructor Detail
-
Lattice
private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode, boolean auto, boolean algorithm, long algorithmMaxMillis, LatticeStatisticProvider.Factory statisticProviderFactory, @Nullable java.lang.Double rowCountEstimate, com.google.common.collect.ImmutableList<Lattice.Column> columns, com.google.common.collect.ImmutableSortedSet<Lattice.Measure> defaultMeasures, com.google.common.collect.ImmutableList<Lattice.Tile> tiles)
-
-
Method Detail
-
create
public static Lattice create(CalciteSchema schema, java.lang.String sql, boolean auto)
Creates a Lattice.
-
isValid
private boolean isValid(Litmus litmus)
-
populateAliases
private static void populateAliases(SqlNode from, java.util.List<java.lang.String> aliases, @Nullable java.lang.String current)
-
populate
private static boolean populate(java.util.List<RelNode> nodes, java.util.List<int[][]> tempLinks, RelNode rel)
-
grab
private static int[][] grab(java.util.List<RelNode> leaves, RexNode rex)
Converts an "t1.c1 = t2.c2" expression into two (input, field) pairs.
-
inputField
private static int[] inputField(java.util.List<RelNode> leaves, RexNode rex)
Converts an expression into an (input, field) pair.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
sql
public java.lang.String sql(ImmutableBitSet groupSet, java.util.List<Lattice.Measure> aggCallList)
Generates a SQL query to populate a tile of the lattice specified by a given set of columns and measures.
-
sql
public java.lang.String sql(ImmutableBitSet groupSet, boolean group, java.util.List<Lattice.Measure> aggCallList)
Generates a SQL query to populate a tile of the lattice specified by a given set of columns and measures, optionally grouping.
-
createSqlWriter
public Lattice.SqlWriter createSqlWriter(SqlDialect dialect, java.lang.StringBuilder buf, java.util.function.IntFunction<SqlNode> field)
Creates a context to which SQL can be generated.
-
countSql
public java.lang.String countSql(ImmutableBitSet groupSet)
Returns a SQL query that counts the number of distinct values of the attributes given ingroupSet
.
-
createStarTable
public StarTable createStarTable()
-
builder
public static Lattice.Builder builder(CalciteSchema calciteSchema, java.lang.String sql)
-
builder
static Lattice.Builder builder(LatticeSpace space, CalciteSchema calciteSchema, java.lang.String sql)
-
toMeasures
public java.util.List<Lattice.Measure> toMeasures(java.util.List<AggregateCall> aggCallList)
-
toMeasure
private Lattice.Measure toMeasure(AggregateCall aggCall)
-
computeTiles
public java.lang.Iterable<? extends Lattice.Tile> computeTiles()
-
getFactRowCount
public double getFactRowCount()
Returns an estimate of the number of rows in the un-aggregated star.
-
getRowCount
public double getRowCount(java.util.List<Lattice.Column> columns)
Returns an estimate of the number of rows in the tile with the given dimensions.
-
getRowCount
public static double getRowCount(double factCount, double... columnCounts)
Returns an estimate of the number of rows in the tile with the given dimensions.
-
getRowCount
public static double getRowCount(double factCount, java.util.List<java.lang.Double> columnCounts)
Returns an estimate of the number of rows in the tile with the given dimensions.
-
uniqueColumnNames
public java.util.List<java.lang.String> uniqueColumnNames()
-
columnToPathOffset
Pair<Path,java.lang.Integer> columnToPathOffset(Lattice.BaseColumn c)
-
tables
public java.util.Set<LatticeTable> tables()
Returns the set of tables in this lattice.
-
firstColumn
public int firstColumn(java.lang.String tableAlias)
Returns the ordinal, within all of the columns in this Lattice, of the first column in the table with a given alias. Returns -1 if the table is not found.
-
-