Class Lattice


  • @ParametersAreNonnullByDefault
    public class Lattice
    extends java.lang.Object
    Structure that allows materialized views based upon a star schema to be recognized and recommended.
    • Field Detail

      • 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<java.lang.Integer,​java.lang.Boolean> columnUses
    • 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,
                        com.google.common.collect.ImmutableListMultimap<java.lang.Integer,​java.lang.Boolean> columnUses)
    • 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 class java.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 in groupSet.
      • createStarTable

        public StarTable createStarTable()
      • 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()
      • 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.
      • 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