Package org.apache.calcite.schema
Class Schemas
java.lang.Object
org.apache.calcite.schema.Schemas
Utility functions for schemas.
-
Method Summary
Modifier and TypeMethodDescriptionanalyzeView
(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String viewSql, @Nullable List<String> viewPath, boolean fail) Analyzes a view.static CalcitePrepare.ConvertResult
convert
(CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, String sql) Parses and validates a SQL query and converts to relational algebra.static DataContext
createDataContext
(Connection connection, @Nullable SchemaPlus rootSchema) static Enumerable<@Nullable Object[]>
enumerable
(FilterableTable table, DataContext root) Returns anEnumerable
over the rows of a given table, not applying any filters, representing each row as an object array.static Enumerable<@Nullable Object[]>
enumerable
(ProjectableFilterableTable table, DataContext root) Returns anEnumerable
over the rows of a given table, not applying any filters and projecting all columns, representing each row as an object array.static Enumerable<@Nullable Object[]>
enumerable
(ScannableTable table, DataContext root) Returns anEnumerable
over the rows of a given table, representing each row as an object array.static Expression
expression
(SchemaPlus schema) Returns the expression for a schema.static List<CalciteSchema.LatticeEntry>
getLatticeEntries
(CalciteSchema schema) Returns the lattices defined in a schema.getLattices
(CalciteSchema schema) Returns the lattices defined in a schema.static List<CalciteSchema.TableEntry>
getStarTables
(CalciteSchema schema) Returns the star tables defined in a schema.static Expression
getTableExpression
(SchemaPlus schema, String tableName, Table table, Class<?> clazz) Generates an expression with which table can be referenced in generated code.static CalcitePrepare.ParseResult
parse
(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String sql) Parses and validates a SQL query.static Path
static Path
path
(CalciteSchema rootSchema, Iterable<String> names) Creates a path with a given list of names starting from a given root schema.static Path
path
(SchemaPlus schema) Returns the path to get to a schema from its root.prepare
(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String sql, com.google.common.collect.ImmutableMap<CalciteConnectionProperty, String> map) Prepares a SQL query for execution.static RelProtoDataType
proto
(ScalarFunction function) Returns an implementation ofRelProtoDataType
that asks a given scalar function for its return type with a given type factory.static RelProtoDataType
Returns an implementation ofRelProtoDataType
that asks a given table for its row type with a given type factory.static <E> Queryable<E>
queryable
(DataContext root, Class<E> clazz, Iterable<? extends String> names) Returns aQueryable
, given a fully-qualified table name as an iterable.static <E> Queryable<E>
queryable
(DataContext root, Class<E> clazz, String... names) Returns aQueryable
, given a fully-qualified table name.static <E> Queryable<E>
queryable
(DataContext root, SchemaPlus schema, Class<E> clazz, String tableName) Returns aQueryable
, given a schema and table name.static @Nullable CalciteSchema.FunctionEntry
resolve
(RelDataTypeFactory typeFactory, String name, Collection<CalciteSchema.FunctionEntry> functionEntries, List<RelDataType> argumentTypes) static @Nullable CalciteSchema
subSchema
(CalciteSchema schema, Iterable<String> names) Returns a sub-schema of a given schema obtained by following a sequence of names.static Expression
subSchemaExpression
(SchemaPlus schema, String name, Class type) Returns the expression for a sub-schema.static @Nullable Table
table
(DataContext root, String... names) Returns anEnumerable
over object arrays, given a fully-qualified table name which leads to aScannableTable
.static Expression
tableExpression
(SchemaPlus schema, Type elementType, String tableName, Class clazz) Returns the expression to access a table within a schema.static String
uniqueTableName
(CalciteSchema schema, String base) Generates a table name that is unique within the given schema.static Expression
unwrap
(Expression call, Class type) Converts a schema expression to a given type by calling theSchemaPlus.unwrap(Class)
method.
-
Method Details
-
resolve
public static @Nullable CalciteSchema.FunctionEntry resolve(RelDataTypeFactory typeFactory, String name, Collection<CalciteSchema.FunctionEntry> functionEntries, List<RelDataType> argumentTypes) -
expression
Returns the expression for a schema. -
subSchemaExpression
Returns the expression for a sub-schema. -
unwrap
Converts a schema expression to a given type by calling theSchemaPlus.unwrap(Class)
method. -
tableExpression
public static Expression tableExpression(SchemaPlus schema, Type elementType, String tableName, Class clazz) Returns the expression to access a table within a schema. -
getTableExpression
public static Expression getTableExpression(SchemaPlus schema, String tableName, Table table, Class<?> clazz) Generates an expression with which table can be referenced in generated code.- Parameters:
schema
- SchematableName
- Table name (unique within schema)table
- Table to be referencedclazz
- Class that provides specific methods for accessing table data. It may differ from thetable
class; for exampleclazz
may beMongoTable.MongoQueryable
, thoughtable
isMongoTable
-
createDataContext
-
queryable
Returns aQueryable
, given a fully-qualified table name. -
queryable
public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, Iterable<? extends String> names) Returns aQueryable
, given a fully-qualified table name as an iterable. -
queryable
public static <E> Queryable<E> queryable(DataContext root, SchemaPlus schema, Class<E> clazz, String tableName) Returns aQueryable
, given a schema and table name. -
enumerable
Returns anEnumerable
over the rows of a given table, representing each row as an object array. -
enumerable
Returns anEnumerable
over the rows of a given table, not applying any filters, representing each row as an object array. -
enumerable
public static Enumerable<@Nullable Object[]> enumerable(ProjectableFilterableTable table, DataContext root) Returns anEnumerable
over the rows of a given table, not applying any filters and projecting all columns, representing each row as an object array. -
table
Returns anEnumerable
over object arrays, given a fully-qualified table name which leads to aScannableTable
. -
parse
public static CalcitePrepare.ParseResult parse(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String sql) Parses and validates a SQL query. For use within Calcite only. -
convert
public static CalcitePrepare.ConvertResult convert(CalciteConnection connection, CalciteSchema schema, List<String> schemaPath, String sql) Parses and validates a SQL query and converts to relational algebra. For use within Calcite only. -
analyzeView
public static CalcitePrepare.AnalyzeViewResult analyzeView(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String viewSql, @Nullable List<String> viewPath, boolean fail) Analyzes a view. For use within Calcite only. -
prepare
public static CalcitePrepare.CalciteSignature<Object> prepare(CalciteConnection connection, CalciteSchema schema, @Nullable List<String> schemaPath, String sql, com.google.common.collect.ImmutableMap<CalciteConnectionProperty, String> map) Prepares a SQL query for execution. For use within Calcite only. -
proto
Returns an implementation ofRelProtoDataType
that asks a given table for its row type with a given type factory. -
proto
Returns an implementation ofRelProtoDataType
that asks a given scalar function for its return type with a given type factory. -
getStarTables
Returns the star tables defined in a schema.- Parameters:
schema
- Schema
-
getLattices
Returns the lattices defined in a schema.- Parameters:
schema
- Schema
-
getLatticeEntries
Returns the lattices defined in a schema.- Parameters:
schema
- Schema
-
subSchema
Returns a sub-schema of a given schema obtained by following a sequence of names.The result is null if the initial schema is null or any sub-schema does not exist.
-
uniqueTableName
Generates a table name that is unique within the given schema. -
path
Creates a path with a given list of names starting from a given root schema. -
path
-
path
Returns the path to get to a schema from its root.
-