Package org.apache.calcite.schema
Class Schemas
- java.lang.Object
-
- org.apache.calcite.schema.Schemas
-
public final class Schemas extends java.lang.Object
Utility functions for schemas.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Schemas.DummyDataContext
Dummy data context that has no variables.private static class
Schemas.PathImpl
Implementation ofPath
.
-
Constructor Summary
Constructors Modifier Constructor Description private
Schemas()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CalcitePrepare.AnalyzeViewResult
analyzeView(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.String viewSql, java.util.List<java.lang.String> viewPath, boolean fail)
Analyzes a view.private static boolean
canConvert(RelDataType fromType, RelDataType toType)
static CalcitePrepare.ConvertResult
convert(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.String sql)
Parses and validates a SQL query and converts to relational algebra.static DataContext
createDataContext(java.sql.Connection connection, SchemaPlus rootSchema)
static Enumerable<java.lang.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<java.lang.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<java.lang.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.private static void
gatherLattices(CalciteSchema schema, java.util.List<CalciteSchema.LatticeEntry> list)
static java.util.List<CalciteSchema.LatticeEntry>
getLatticeEntries(CalciteSchema schema)
Returns the lattices defined in a schema.static java.util.List<Lattice>
getLattices(CalciteSchema schema)
Returns the lattices defined in a schema.static java.util.List<CalciteSchema.TableEntry>
getStarTables(CalciteSchema schema)
Returns the star tables defined in a schema.private static int[]
identity(int count)
private static CalcitePrepare.Context
makeContext(CalciteConnectionConfig connectionConfig, JavaTypeFactory typeFactory, DataContext dataContext, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> objectPath_)
private static CalcitePrepare.Context
makeContext(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> objectPath, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.String> propValues)
Creates a context for the purposes of preparing a statement.private static boolean
matches(RelDataTypeFactory typeFactory, Function member, java.util.List<RelDataType> argumentTypes)
private static CalciteConnectionConfig
mutate(CalciteConnectionConfig config, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.String> propValues)
static CalcitePrepare.ParseResult
parse(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.String sql)
Parses and validates a SQL query.static Schemas.PathImpl
path(com.google.common.collect.ImmutableList<Pair<java.lang.String,Schema>> build)
static Path
path(CalciteSchema rootSchema, java.lang.Iterable<java.lang.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.static CalcitePrepare.CalciteSignature<java.lang.Object>
prepare(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.String sql, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.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
proto(Table table)
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, java.lang.Class<E> clazz, java.lang.Iterable<? extends java.lang.String> names)
Returns aQueryable
, given a fully-qualified table name as an iterable.static <E> Queryable<E>
queryable(DataContext root, java.lang.Class<E> clazz, java.lang.String... names)
Returns aQueryable
, given a fully-qualified table name.static <E> Queryable<E>
queryable(DataContext root, SchemaPlus schema, java.lang.Class<E> clazz, java.lang.String tableName)
Returns aQueryable
, given a schema and table name.static CalciteSchema.FunctionEntry
resolve(RelDataTypeFactory typeFactory, java.lang.String name, java.util.Collection<CalciteSchema.FunctionEntry> functionEntries, java.util.List<RelDataType> argumentTypes)
static CalciteSchema
subSchema(CalciteSchema schema, java.lang.Iterable<java.lang.String> names)
Returns a sub-schema of a given schema obtained by following a sequence of names.static Expression
subSchemaExpression(SchemaPlus schema, java.lang.String name, java.lang.Class type)
Returns the expression for a sub-schema.static Table
table(DataContext root, java.lang.String... names)
Returns anEnumerable
over object arrays, given a fully-qualified table name which leads to aScannableTable
.static Expression
tableExpression(SchemaPlus schema, java.lang.reflect.Type elementType, java.lang.String tableName, java.lang.Class clazz)
Returns the expression to access a table within a schema.static java.lang.String
uniqueTableName(CalciteSchema schema, java.lang.String base)
Generates a table name that is unique within the given schema.static Expression
unwrap(Expression call, java.lang.Class type)
Converts a schema expression to a given type by calling theSchemaPlus.unwrap(Class)
method.
-
-
-
Method Detail
-
resolve
public static CalciteSchema.FunctionEntry resolve(RelDataTypeFactory typeFactory, java.lang.String name, java.util.Collection<CalciteSchema.FunctionEntry> functionEntries, java.util.List<RelDataType> argumentTypes)
-
matches
private static boolean matches(RelDataTypeFactory typeFactory, Function member, java.util.List<RelDataType> argumentTypes)
-
canConvert
private static boolean canConvert(RelDataType fromType, RelDataType toType)
-
expression
public static Expression expression(SchemaPlus schema)
Returns the expression for a schema.
-
subSchemaExpression
public static Expression subSchemaExpression(SchemaPlus schema, java.lang.String name, java.lang.Class type)
Returns the expression for a sub-schema.
-
unwrap
public static Expression unwrap(Expression call, java.lang.Class type)
Converts a schema expression to a given type by calling theSchemaPlus.unwrap(Class)
method.
-
tableExpression
public static Expression tableExpression(SchemaPlus schema, java.lang.reflect.Type elementType, java.lang.String tableName, java.lang.Class clazz)
Returns the expression to access a table within a schema.
-
createDataContext
public static DataContext createDataContext(java.sql.Connection connection, SchemaPlus rootSchema)
-
queryable
public static <E> Queryable<E> queryable(DataContext root, java.lang.Class<E> clazz, java.lang.String... names)
Returns aQueryable
, given a fully-qualified table name.
-
queryable
public static <E> Queryable<E> queryable(DataContext root, java.lang.Class<E> clazz, java.lang.Iterable<? extends java.lang.String> names)
Returns aQueryable
, given a fully-qualified table name as an iterable.
-
queryable
public static <E> Queryable<E> queryable(DataContext root, SchemaPlus schema, java.lang.Class<E> clazz, java.lang.String tableName)
Returns aQueryable
, given a schema and table name.
-
enumerable
public static Enumerable<java.lang.Object[]> enumerable(ScannableTable table, DataContext root)
Returns anEnumerable
over the rows of a given table, representing each row as an object array.
-
enumerable
public static Enumerable<java.lang.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.
-
enumerable
public static Enumerable<java.lang.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.
-
identity
private static int[] identity(int count)
-
table
public static Table table(DataContext root, java.lang.String... names)
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, java.util.List<java.lang.String> schemaPath, java.lang.String sql)
Parses and validates a SQL query. For use within Calcite only.
-
convert
public static CalcitePrepare.ConvertResult convert(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.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, java.util.List<java.lang.String> schemaPath, java.lang.String viewSql, java.util.List<java.lang.String> viewPath, boolean fail)
Analyzes a view. For use within Calcite only.
-
prepare
public static CalcitePrepare.CalciteSignature<java.lang.Object> prepare(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.lang.String sql, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.String> map)
Prepares a SQL query for execution. For use within Calcite only.
-
makeContext
private static CalcitePrepare.Context makeContext(CalciteConnection connection, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> objectPath, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.String> propValues)
Creates a context for the purposes of preparing a statement.- Parameters:
connection
- Connectionschema
- SchemaschemaPath
- Path wherein to look for functionsobjectPath
- Path of the object being analyzed (usually a view), or nullpropValues
- Connection properties- Returns:
- Context
-
mutate
private static CalciteConnectionConfig mutate(CalciteConnectionConfig config, com.google.common.collect.ImmutableMap<CalciteConnectionProperty,java.lang.String> propValues)
-
makeContext
private static CalcitePrepare.Context makeContext(CalciteConnectionConfig connectionConfig, JavaTypeFactory typeFactory, DataContext dataContext, CalciteSchema schema, java.util.List<java.lang.String> schemaPath, java.util.List<java.lang.String> objectPath_)
-
proto
public static RelProtoDataType proto(Table table)
Returns an implementation ofRelProtoDataType
that asks a given table for its row type with a given type factory.
-
proto
public static RelProtoDataType proto(ScalarFunction function)
Returns an implementation ofRelProtoDataType
that asks a given scalar function for its return type with a given type factory.
-
getStarTables
public static java.util.List<CalciteSchema.TableEntry> getStarTables(CalciteSchema schema)
Returns the star tables defined in a schema.- Parameters:
schema
- Schema
-
getLattices
public static java.util.List<Lattice> getLattices(CalciteSchema schema)
Returns the lattices defined in a schema.- Parameters:
schema
- Schema
-
getLatticeEntries
public static java.util.List<CalciteSchema.LatticeEntry> getLatticeEntries(CalciteSchema schema)
Returns the lattices defined in a schema.- Parameters:
schema
- Schema
-
gatherLattices
private static void gatherLattices(CalciteSchema schema, java.util.List<CalciteSchema.LatticeEntry> list)
-
subSchema
public static CalciteSchema subSchema(CalciteSchema schema, java.lang.Iterable<java.lang.String> names)
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
public static java.lang.String uniqueTableName(CalciteSchema schema, java.lang.String base)
Generates a table name that is unique within the given schema.
-
path
public static Path path(CalciteSchema rootSchema, java.lang.Iterable<java.lang.String> names)
Creates a path with a given list of names starting from a given root schema.
-
path
public static Schemas.PathImpl path(com.google.common.collect.ImmutableList<Pair<java.lang.String,Schema>> build)
-
path
public static Path path(SchemaPlus schema)
Returns the path to get to a schema from its root.
-
-