Class Lattice

java.lang.Object
org.apache.calcite.materialize.Lattice

public class Lattice extends Object
Structure that allows materialized views based upon a star schema to be recognized and recommended.
  • Field Details

    • 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
    • columnUses

      public final com.google.common.collect.ImmutableListMultimap<Integer,Boolean> columnUses
    • statisticProvider

      public final LatticeStatisticProvider statisticProvider
  • Method Details

    • create

      public static Lattice create(CalciteSchema schema, String sql, boolean auto)
      Creates a Lattice.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • sql

      public String sql(ImmutableBitSet groupSet, 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 String sql(ImmutableBitSet groupSet, boolean group, 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, StringBuilder buf, IntFunction<SqlNode> field)
      Creates a context to which SQL can be generated.
    • countSql

      public String countSql(ImmutableBitSet groupSet)
      Returns a SQL query that counts the number of distinct values of the attributes given in groupSet.
    • createStarTable

      public StarTable createStarTable()
    • builder

      public static Lattice.Builder builder(CalciteSchema calciteSchema, String sql)
    • toMeasures

      public List<Lattice.Measure> toMeasures(List<AggregateCall> aggCallList)
    • computeTiles

      public 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(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, List<Double> columnCounts)
      Returns an estimate of the number of rows in the tile with the given dimensions.
    • uniqueColumnNames

      public List<String> uniqueColumnNames()
    • tables

      public Set<LatticeTable> tables()
      Returns the set of tables in this lattice.
    • firstColumn

      public int firstColumn(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.
    • isAlwaysMeasure

      public boolean isAlwaysMeasure(Lattice.Column column)
      Returns whether every use of a column is as an argument to a measure.

      For example, in the query select sum(x + y), sum(a + b) from t group by x + y the expression "x + y" is used once as an argument to a measure, and once as a dimension.

      Therefore, in a lattice created from that one query, isAlwaysMeasure for the derived column corresponding to "x + y" returns false, and for "a + b" returns true.

      Parameters:
      column - Column or derived column
      Returns:
      Whether all uses are as arguments to aggregate functions