Class CalciteSchema
- java.lang.Object
-
- org.apache.calcite.jdbc.CalciteSchema
-
- Direct Known Subclasses:
CachingCalciteSchema
,SimpleCalciteSchema
public abstract class CalciteSchema extends java.lang.Object
Schema.Wrapper around user-defined schema used internally.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CalciteSchema.Entry
Entry in a schema, such as a table or sub-schema.static class
CalciteSchema.FunctionEntry
Membership of a function in a schema.static class
CalciteSchema.FunctionEntryImpl
Implementation ofCalciteSchema.FunctionEntry
where all properties are held in fields.static class
CalciteSchema.LatticeEntry
Membership of a lattice in a schema.static class
CalciteSchema.LatticeEntryImpl
Implementation ofCalciteSchema.LatticeEntry
where all properties are held in fields.private class
CalciteSchema.SchemaPlusImpl
Implementation ofSchemaPlus
based on aCalciteSchema
.static class
CalciteSchema.TableEntry
Membership of a table in a schema.static class
CalciteSchema.TableEntryImpl
Implementation ofCalciteSchema.TableEntry
where all properties are held in fields.static class
CalciteSchema.TypeEntry
Membership of a type in a schema.static class
CalciteSchema.TypeEntryImpl
Implementation ofCalciteSchema.TypeEntry
where all properties are held in fields.
-
Field Summary
Fields Modifier and Type Field Description protected NameMultimap<CalciteSchema.FunctionEntry>
functionMap
protected NameSet
functionNames
protected NameMap<CalciteSchema.LatticeEntry>
latticeMap
java.lang.String
name
protected NameMap<CalciteSchema.FunctionEntry>
nullaryFunctionMap
private CalciteSchema
parent
private java.util.List<? extends java.util.List<java.lang.String>>
path
Schema
schema
protected NameMap<CalciteSchema>
subSchemaMap
protected NameMap<CalciteSchema.TableEntry>
tableMap
Tables explicitly defined in this schema.protected NameMap<CalciteSchema.TypeEntry>
typeMap
-
Constructor Summary
Constructors Modifier Constructor Description protected
CalciteSchema(CalciteSchema parent, Schema schema, java.lang.String name, NameMap<CalciteSchema> subSchemaMap, NameMap<CalciteSchema.TableEntry> tableMap, NameMap<CalciteSchema.LatticeEntry> latticeMap, NameMap<CalciteSchema.TypeEntry> typeMap, NameMultimap<CalciteSchema.FunctionEntry> functionMap, NameSet functionNames, NameMap<CalciteSchema.FunctionEntry> nullaryFunctionMap, java.util.List<? extends java.util.List<java.lang.String>> path)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private CalciteSchema.LatticeEntry
add(java.lang.String name, Lattice lattice)
CalciteSchema.TypeEntry
add(java.lang.String name, RelProtoDataType type)
Defines a type within this schema.private CalciteSchema.FunctionEntry
add(java.lang.String name, Function function)
abstract CalciteSchema
add(java.lang.String name, Schema schema)
Adds a child schema of this schema.CalciteSchema.TableEntry
add(java.lang.String tableName, Table table)
Defines a table within this schema.CalciteSchema.TableEntry
add(java.lang.String tableName, Table table, com.google.common.collect.ImmutableList<java.lang.String> sqls)
Defines a table within this schema.protected abstract void
addImplicitFuncNamesToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit function names to a builder.protected abstract void
addImplicitFunctionsToBuilder(com.google.common.collect.ImmutableList.Builder<Function> builder, java.lang.String name, boolean caseSensitive)
Adds implicit functions to a builder.protected abstract void
addImplicitSubSchemaToBuilder(com.google.common.collect.ImmutableSortedMap.Builder<java.lang.String,CalciteSchema> builder)
Adds implicit sub-schemas to a builder.protected abstract void
addImplicitTablesBasedOnNullaryFunctionsToBuilder(com.google.common.collect.ImmutableSortedMap.Builder<java.lang.String,Table> builder)
Adds implicit table functions to a builder.protected abstract void
addImplicitTableToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit tables to a builder.protected abstract void
addImplicitTypeNamesToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit type names to a builder.static CalciteSchema
createRootSchema(boolean addMetadataSchema)
Creates a root schema.static CalciteSchema
createRootSchema(boolean addMetadataSchema, boolean cache)
Creates a root schema.static CalciteSchema
createRootSchema(boolean addMetadataSchema, boolean cache, java.lang.String name)
Creates a root schema.CalciteSchema
createSnapshot(SchemaVersion version)
Creates a snapshot of this CalciteSchema as of the specified time.protected static <V> java.util.NavigableMap<java.lang.String,V>
find(java.util.NavigableMap<java.lang.String,V> map, java.lang.String s)
Deprecated.use NameMapprotected static java.lang.Iterable<java.lang.String>
find(java.util.NavigableSet<java.lang.String> set, java.lang.String name)
Deprecated.use NameSetstatic CalciteSchema
from(SchemaPlus plus)
java.util.NavigableSet<java.lang.String>
getFunctionNames()
Returns the list of function names in this schema, both implicit and explicit, never null.java.util.Collection<Function>
getFunctions(java.lang.String name, boolean caseSensitive)
Returns a collection of all functions, explicit and implicit, with a given name.protected abstract CalciteSchema
getImplicitSubSchema(java.lang.String schemaName, boolean caseSensitive)
Returns a sub-schema with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Schema)
), or null.protected abstract CalciteSchema.TableEntry
getImplicitTable(java.lang.String tableName, boolean caseSensitive)
Returns a table with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Table)
), or null.protected abstract CalciteSchema.TableEntry
getImplicitTableBasedOnNullaryFunction(java.lang.String tableName, boolean caseSensitive)
Returns table function with a given name and zero arguments that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Function)
), or null.protected abstract CalciteSchema.TypeEntry
getImplicitType(java.lang.String name, boolean caseSensitive)
Returns a type with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, RelProtoDataType)
), or null.java.util.NavigableMap<java.lang.String,CalciteSchema.LatticeEntry>
getLatticeMap()
Returns a collection of lattices.java.lang.String
getName()
java.util.List<? extends java.util.List<java.lang.String>>
getPath()
Returns the default path resolving functions from this schema.CalciteSchema
getSubSchema(java.lang.String schemaName, boolean caseSensitive)
java.util.NavigableMap<java.lang.String,CalciteSchema>
getSubSchemaMap()
Returns a collection of sub-schemas, both explicit (defined usingadd(String, org.apache.calcite.schema.Schema)
) and implicit (defined usingSchema.getSubSchemaNames()
andSchema.getSubSchema(String)
).CalciteSchema.TableEntry
getTable(java.lang.String tableName, boolean caseSensitive)
Returns a table with the given name.CalciteSchema.TableEntry
getTableBasedOnNullaryFunction(java.lang.String tableName, boolean caseSensitive)
Returns a tables derived from explicit and implicit functions that take zero parameters.CalciteSchema.TableEntry
getTableBySql(java.lang.String sql)
Returns a table that materializes the given SQL statement.java.util.NavigableSet<java.lang.String>
getTableNames()
Returns the set of all table names.java.util.NavigableMap<java.lang.String,Table>
getTablesBasedOnNullaryFunctions()
Returns tables derived from explicit and implicit functions that take zero parameters.CalciteSchema.TypeEntry
getType(java.lang.String name, boolean caseSensitive)
Returns a type, explicit and implicit, with a given name.java.util.NavigableSet<java.lang.String>
getTypeNames()
Returns the set of all types names.protected abstract boolean
isCacheEnabled()
boolean
isRoot()
Returns whether this is a root schema.java.util.List<java.lang.String>
path(java.lang.String name)
Returns the path of an object in this schema.SchemaPlus
plus()
boolean
removeFunction(java.lang.String name)
boolean
removeSubSchema(java.lang.String name)
boolean
removeTable(java.lang.String name)
boolean
removeType(java.lang.String name)
CalciteSchema
root()
abstract void
setCache(boolean cache)
protected abstract CalciteSchema
snapshot(CalciteSchema parent, SchemaVersion version)
Returns a snapshot representation of this CalciteSchema.protected CalciteSchema.TableEntryImpl
tableEntry(java.lang.String name, Table table)
Creates a TableEntryImpl with no SQLs.protected CalciteSchema.TypeEntryImpl
typeEntry(java.lang.String name, RelProtoDataType relProtoDataType)
Creates a TableEntryImpl with no SQLs.
-
-
-
Field Detail
-
parent
private final CalciteSchema parent
-
schema
public final Schema schema
-
name
public final java.lang.String name
-
tableMap
protected final NameMap<CalciteSchema.TableEntry> tableMap
Tables explicitly defined in this schema. Does not include tables inschema
.
-
functionMap
protected final NameMultimap<CalciteSchema.FunctionEntry> functionMap
-
typeMap
protected final NameMap<CalciteSchema.TypeEntry> typeMap
-
latticeMap
protected final NameMap<CalciteSchema.LatticeEntry> latticeMap
-
functionNames
protected final NameSet functionNames
-
nullaryFunctionMap
protected final NameMap<CalciteSchema.FunctionEntry> nullaryFunctionMap
-
subSchemaMap
protected final NameMap<CalciteSchema> subSchemaMap
-
path
private java.util.List<? extends java.util.List<java.lang.String>> path
-
-
Constructor Detail
-
CalciteSchema
protected CalciteSchema(CalciteSchema parent, Schema schema, java.lang.String name, NameMap<CalciteSchema> subSchemaMap, NameMap<CalciteSchema.TableEntry> tableMap, NameMap<CalciteSchema.LatticeEntry> latticeMap, NameMap<CalciteSchema.TypeEntry> typeMap, NameMultimap<CalciteSchema.FunctionEntry> functionMap, NameSet functionNames, NameMap<CalciteSchema.FunctionEntry> nullaryFunctionMap, java.util.List<? extends java.util.List<java.lang.String>> path)
-
-
Method Detail
-
getImplicitSubSchema
protected abstract CalciteSchema getImplicitSubSchema(java.lang.String schemaName, boolean caseSensitive)
Returns a sub-schema with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Schema)
), or null.
-
getImplicitTable
protected abstract CalciteSchema.TableEntry getImplicitTable(java.lang.String tableName, boolean caseSensitive)
Returns a table with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Table)
), or null.
-
getImplicitType
protected abstract CalciteSchema.TypeEntry getImplicitType(java.lang.String name, boolean caseSensitive)
Returns a type with a given name that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, RelProtoDataType)
), or null.
-
getImplicitTableBasedOnNullaryFunction
protected abstract CalciteSchema.TableEntry getImplicitTableBasedOnNullaryFunction(java.lang.String tableName, boolean caseSensitive)
Returns table function with a given name and zero arguments that is defined implicitly (that is, by the underlyingSchema
object, not explicitly by a call toadd(String, Function)
), or null.
-
addImplicitSubSchemaToBuilder
protected abstract void addImplicitSubSchemaToBuilder(com.google.common.collect.ImmutableSortedMap.Builder<java.lang.String,CalciteSchema> builder)
Adds implicit sub-schemas to a builder.
-
addImplicitTableToBuilder
protected abstract void addImplicitTableToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit tables to a builder.
-
addImplicitFunctionsToBuilder
protected abstract void addImplicitFunctionsToBuilder(com.google.common.collect.ImmutableList.Builder<Function> builder, java.lang.String name, boolean caseSensitive)
Adds implicit functions to a builder.
-
addImplicitFuncNamesToBuilder
protected abstract void addImplicitFuncNamesToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit function names to a builder.
-
addImplicitTypeNamesToBuilder
protected abstract void addImplicitTypeNamesToBuilder(com.google.common.collect.ImmutableSortedSet.Builder<java.lang.String> builder)
Adds implicit type names to a builder.
-
addImplicitTablesBasedOnNullaryFunctionsToBuilder
protected abstract void addImplicitTablesBasedOnNullaryFunctionsToBuilder(com.google.common.collect.ImmutableSortedMap.Builder<java.lang.String,Table> builder)
Adds implicit table functions to a builder.
-
snapshot
protected abstract CalciteSchema snapshot(CalciteSchema parent, SchemaVersion version)
Returns a snapshot representation of this CalciteSchema.
-
isCacheEnabled
protected abstract boolean isCacheEnabled()
-
setCache
public abstract void setCache(boolean cache)
-
tableEntry
protected CalciteSchema.TableEntryImpl tableEntry(java.lang.String name, Table table)
Creates a TableEntryImpl with no SQLs.
-
typeEntry
protected CalciteSchema.TypeEntryImpl typeEntry(java.lang.String name, RelProtoDataType relProtoDataType)
Creates a TableEntryImpl with no SQLs.
-
add
public CalciteSchema.TableEntry add(java.lang.String tableName, Table table)
Defines a table within this schema.
-
add
public CalciteSchema.TableEntry add(java.lang.String tableName, Table table, com.google.common.collect.ImmutableList<java.lang.String> sqls)
Defines a table within this schema.
-
add
public CalciteSchema.TypeEntry add(java.lang.String name, RelProtoDataType type)
Defines a type within this schema.
-
add
private CalciteSchema.FunctionEntry add(java.lang.String name, Function function)
-
add
private CalciteSchema.LatticeEntry add(java.lang.String name, Lattice lattice)
-
root
public CalciteSchema root()
-
isRoot
public boolean isRoot()
Returns whether this is a root schema.
-
path
public java.util.List<java.lang.String> path(java.lang.String name)
Returns the path of an object in this schema.
-
getSubSchema
public final CalciteSchema getSubSchema(java.lang.String schemaName, boolean caseSensitive)
-
add
public abstract CalciteSchema add(java.lang.String name, Schema schema)
Adds a child schema of this schema.
-
getTableBySql
public final CalciteSchema.TableEntry getTableBySql(java.lang.String sql)
Returns a table that materializes the given SQL statement.
-
getTable
public final CalciteSchema.TableEntry getTable(java.lang.String tableName, boolean caseSensitive)
Returns a table with the given name. Does not look for views.
-
getName
public java.lang.String getName()
-
plus
public SchemaPlus plus()
-
from
public static CalciteSchema from(SchemaPlus plus)
-
getPath
public java.util.List<? extends java.util.List<java.lang.String>> getPath()
Returns the default path resolving functions from this schema.The path consists is a list of lists of strings. Each list of strings represents the path of a schema from the root schema. For example, [[], [foo], [foo, bar, baz]] represents three schemas: the root schema "/" (level 0), "/foo" (level 1) and "/foo/bar/baz" (level 3).
- Returns:
- Path of this schema; never null, may be empty
-
getSubSchemaMap
public final java.util.NavigableMap<java.lang.String,CalciteSchema> getSubSchemaMap()
Returns a collection of sub-schemas, both explicit (defined usingadd(String, org.apache.calcite.schema.Schema)
) and implicit (defined usingSchema.getSubSchemaNames()
andSchema.getSubSchema(String)
).
-
getLatticeMap
public java.util.NavigableMap<java.lang.String,CalciteSchema.LatticeEntry> getLatticeMap()
Returns a collection of lattices.All are explicit (defined using
add(String, Lattice)
).
-
getTableNames
public final java.util.NavigableSet<java.lang.String> getTableNames()
Returns the set of all table names. Includes implicit and explicit tables and functions with zero parameters.
-
getTypeNames
public final java.util.NavigableSet<java.lang.String> getTypeNames()
Returns the set of all types names.
-
getType
public final CalciteSchema.TypeEntry getType(java.lang.String name, boolean caseSensitive)
Returns a type, explicit and implicit, with a given name. Never null.
-
getFunctions
public final java.util.Collection<Function> getFunctions(java.lang.String name, boolean caseSensitive)
Returns a collection of all functions, explicit and implicit, with a given name. Never null.
-
getFunctionNames
public final java.util.NavigableSet<java.lang.String> getFunctionNames()
Returns the list of function names in this schema, both implicit and explicit, never null.
-
getTablesBasedOnNullaryFunctions
public final java.util.NavigableMap<java.lang.String,Table> getTablesBasedOnNullaryFunctions()
Returns tables derived from explicit and implicit functions that take zero parameters.
-
getTableBasedOnNullaryFunction
public final CalciteSchema.TableEntry getTableBasedOnNullaryFunction(java.lang.String tableName, boolean caseSensitive)
Returns a tables derived from explicit and implicit functions that take zero parameters.
-
createSnapshot
public CalciteSchema createSnapshot(SchemaVersion version)
Creates a snapshot of this CalciteSchema as of the specified time. All explicit objects in this CalciteSchema will be copied into the snapshot CalciteSchema, while the contents of the snapshot of the underlying schema should not change as specified inSchema.snapshot(SchemaVersion)
. Snapshots of explicit sub schemas will be created and copied recursively.Currently, to accommodate the requirement of creating tables on the fly for materializations, the snapshot will still use the same table map and lattice map as in the original CalciteSchema instead of making copies.
- Parameters:
version
- The current schema version- Returns:
- the schema snapshot.
-
find
@Deprecated protected static <V> java.util.NavigableMap<java.lang.String,V> find(java.util.NavigableMap<java.lang.String,V> map, java.lang.String s)
Deprecated.use NameMapReturns a subset of a map whose keys match the given string case-insensitively.
-
find
@Deprecated protected static java.lang.Iterable<java.lang.String> find(java.util.NavigableSet<java.lang.String> set, java.lang.String name)
Deprecated.use NameSetReturns a subset of a set whose values match the given string case-insensitively.
-
createRootSchema
public static CalciteSchema createRootSchema(boolean addMetadataSchema)
Creates a root schema.When
addMetadataSchema
argument is true adds a "metadata" schema containing definitions of tables, columns etc. to root schema. By default, creates aCachingCalciteSchema
.
-
createRootSchema
public static CalciteSchema createRootSchema(boolean addMetadataSchema, boolean cache)
Creates a root schema.- Parameters:
addMetadataSchema
- Whether to add a "metadata" schema containing definitions of tables, columns etc.cache
- If true createCachingCalciteSchema
; if false createSimpleCalciteSchema
-
createRootSchema
public static CalciteSchema createRootSchema(boolean addMetadataSchema, boolean cache, java.lang.String name)
Creates a root schema.- Parameters:
addMetadataSchema
- Whether to add a "metadata" schema containing definitions of tables, columns etc.cache
- If true createCachingCalciteSchema
; if false createSimpleCalciteSchema
name
- Schema name
-
removeSubSchema
public boolean removeSubSchema(java.lang.String name)
-
removeTable
public boolean removeTable(java.lang.String name)
-
removeFunction
public boolean removeFunction(java.lang.String name)
-
removeType
public boolean removeType(java.lang.String name)
-
-