Package org.apache.calcite.materialize
Class MaterializationService
- java.lang.Object
-
- org.apache.calcite.materialize.MaterializationService
-
public class MaterializationService extends java.lang.Object
Manages the collection of materialized tables known to the system, and the process by which they become valid and invalid.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MaterializationService.DefaultTableFactory
Default implementation ofMaterializationService.TableFactory
.static interface
MaterializationService.TableFactory
Creates tables that represent a materialized view.
-
Field Summary
Fields Modifier and Type Field Description private MaterializationActor
actor
private static java.util.Comparator<Pair<CalciteSchema.TableEntry,TileKey>>
C
private static MaterializationService
INSTANCE
private MaterializationService.DefaultTableFactory
tableFactory
private static java.lang.ThreadLocal<MaterializationService>
THREAD_INSTANCE
For testing.
-
Constructor Summary
Constructors Modifier Constructor Description private
MaterializationService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
allSatisfiable(java.util.List<Lattice.Measure> measureList, TileKey tileKey)
CalciteSchema.TableEntry
checkValid(MaterializationKey key)
Checks whether a materialization is valid, and if so, returns the table where the data are stored.void
clear()
De-registers all materialized tables in the system.MaterializationKey
defineMaterialization(CalciteSchema schema, TileKey tileKey, java.lang.String viewSql, java.util.List<java.lang.String> viewSchemaPath, java.lang.String suggestedTableName, boolean create, boolean existing)
Defines a new materialization.MaterializationKey
defineMaterialization(CalciteSchema schema, TileKey tileKey, java.lang.String viewSql, java.util.List<java.lang.String> viewSchemaPath, java.lang.String suggestedTableName, MaterializationService.TableFactory tableFactory, boolean create, boolean existing)
Defines a new materialization.Pair<CalciteSchema.TableEntry,TileKey>
defineTile(Lattice lattice, ImmutableBitSet groupSet, java.util.List<Lattice.Measure> measureList, CalciteSchema schema, boolean create, boolean exact)
Defines a tile.Pair<CalciteSchema.TableEntry,TileKey>
defineTile(Lattice lattice, ImmutableBitSet groupSet, java.util.List<Lattice.Measure> measureList, CalciteSchema schema, boolean create, boolean exact, java.lang.String suggestedTableName, MaterializationService.TableFactory tableFactory)
static MaterializationService
instance()
Returns the instance of the materialization service.java.util.List<Prepare.Materialization>
query(CalciteSchema rootSchema)
Gathers a list of all materialized tables known within a given root schema.void
removeMaterialization(MaterializationKey key)
static void
setThreadLocal()
Used by tests, to ensure that they see their own service.
-
-
-
Field Detail
-
INSTANCE
private static final MaterializationService INSTANCE
-
THREAD_INSTANCE
private static final java.lang.ThreadLocal<MaterializationService> THREAD_INSTANCE
For testing.
-
C
private static final java.util.Comparator<Pair<CalciteSchema.TableEntry,TileKey>> C
-
actor
private final MaterializationActor actor
-
tableFactory
private final MaterializationService.DefaultTableFactory tableFactory
-
-
Method Detail
-
defineMaterialization
public MaterializationKey defineMaterialization(CalciteSchema schema, TileKey tileKey, java.lang.String viewSql, java.util.List<java.lang.String> viewSchemaPath, java.lang.String suggestedTableName, boolean create, boolean existing)
Defines a new materialization. Returns its key.
-
defineMaterialization
public MaterializationKey defineMaterialization(CalciteSchema schema, TileKey tileKey, java.lang.String viewSql, java.util.List<java.lang.String> viewSchemaPath, java.lang.String suggestedTableName, MaterializationService.TableFactory tableFactory, boolean create, boolean existing)
Defines a new materialization. Returns its key.
-
checkValid
public CalciteSchema.TableEntry checkValid(MaterializationKey key)
Checks whether a materialization is valid, and if so, returns the table where the data are stored.
-
defineTile
public Pair<CalciteSchema.TableEntry,TileKey> defineTile(Lattice lattice, ImmutableBitSet groupSet, java.util.List<Lattice.Measure> measureList, CalciteSchema schema, boolean create, boolean exact)
Defines a tile.Setting the
create
flag to false prevents a materialization from being created if one does not exist. Critically, it is set to false during the recursive SQL that populates a materialization. Otherwise a materialization would try to create itself to populate itself!
-
defineTile
public Pair<CalciteSchema.TableEntry,TileKey> defineTile(Lattice lattice, ImmutableBitSet groupSet, java.util.List<Lattice.Measure> measureList, CalciteSchema schema, boolean create, boolean exact, java.lang.String suggestedTableName, MaterializationService.TableFactory tableFactory)
-
allSatisfiable
private boolean allSatisfiable(java.util.List<Lattice.Measure> measureList, TileKey tileKey)
-
query
public java.util.List<Prepare.Materialization> query(CalciteSchema rootSchema)
Gathers a list of all materialized tables known within a given root schema. (Each root schema defines a disconnected namespace, with no overlap with the current schema. Especially in a test run, the contents of two root schemas may look similar.)
-
clear
public void clear()
De-registers all materialized tables in the system.
-
setThreadLocal
public static void setThreadLocal()
Used by tests, to ensure that they see their own service.
-
instance
public static MaterializationService instance()
Returns the instance of the materialization service. Usually the global one, but returns a thread-local one during testing (whensetThreadLocal()
has been called by the current thread).
-
removeMaterialization
public void removeMaterialization(MaterializationKey key)
-
-