Class CalciteCatalogReader
- java.lang.Object
-
- org.apache.calcite.prepare.CalciteCatalogReader
-
- All Implemented Interfaces:
RelOptSchema
,Prepare.CatalogReader
,Wrapper
,SqlOperatorTable
,SqlValidatorCatalogReader
public class CalciteCatalogReader extends java.lang.Object implements Prepare.CatalogReader
Implementation ofPrepare.CatalogReader
and alsoSqlOperatorTable
based on tables and functions defined schemas.
-
-
Field Summary
Fields Modifier and Type Field Description protected CalciteConnectionConfig
config
protected SqlNameMatcher
nameMatcher
protected CalciteSchema
rootSchema
private java.util.List<java.util.List<java.lang.String>>
schemaPaths
protected RelDataTypeFactory
typeFactory
-
Fields inherited from interface org.apache.calcite.prepare.Prepare.CatalogReader
THREAD_LOCAL
-
-
Constructor Summary
Constructors Modifier Constructor Description CalciteCatalogReader(CalciteSchema rootSchema, java.util.List<java.lang.String> defaultSchema, RelDataTypeFactory typeFactory, CalciteConnectionConfig config)
protected
CalciteCatalogReader(CalciteSchema rootSchema, SqlNameMatcher nameMatcher, java.util.List<java.util.List<java.lang.String>> schemaPaths, RelDataTypeFactory typeFactory, CalciteConnectionConfig config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RelDataType
createTypeFromProjection(RelDataType type, java.util.List<java.lang.String> columnNameList)
RelDataTypeField
field(RelDataType rowType, java.lang.String alias)
java.util.List<SqlMoniker>
getAllSchemaObjectNames(java.util.List<java.lang.String> names)
Given fully qualified schema name, returns schema object names as specified.CalciteConnectionConfig
getConfig()
Returns Config settingsprivate java.util.Collection<Function>
getFunctionsFrom(java.util.List<java.lang.String> names)
RelDataType
getNamedType(SqlIdentifier typeName)
Finds a user-defined type with the given name, possibly qualified.java.util.List<SqlOperator>
getOperatorList()
Retrieves a list of all functions and operators in this table.CalciteSchema
getRootSchema()
Returns the root namespace for name resolution.java.util.List<java.util.List<java.lang.String>>
getSchemaPaths()
Returns the paths of all schemas to look in for tables.Prepare.PreparingTable
getTable(java.util.List<java.lang.String> names)
Finds a table or schema with the given name, possibly qualified.Prepare.PreparingTable
getTableForMember(java.util.List<java.lang.String> names)
Retrieves aRelOptTable
based upon a member access.RelDataTypeFactory
getTypeFactory()
Returns thetype factory
used to generate types for this schema.private static SqlReturnTypeInference
infer(AggregateFunction function)
private static SqlReturnTypeInference
infer(ScalarFunction function)
boolean
isCaseSensitive()
void
lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, java.util.List<SqlOperator> operatorList)
Retrieves a list of operators with a given name and syntax.boolean
matches(java.lang.String string, java.lang.String name)
private SqlMonikerImpl
moniker(CalciteSchema schema, java.lang.String name, SqlMonikerType type)
SqlNameMatcher
nameMatcher()
Returns an implementation ofSqlNameMatcher
that matches the case-sensitivity policy.static SqlOperatorTable
operatorTable(java.lang.String className)
Creates an operator table that contains functions in the given class.void
registerRules(RelOptPlanner planner)
Registers all of the rules supported by this schema.private static SqlOperator
toOp(RelDataTypeFactory typeFactory, SqlIdentifier name, Function function)
Converts a function to aSqlOperator
.private SqlOperator
toOp(SqlIdentifier name, Function function)
private static java.util.List<RelDataType>
toSql(RelDataTypeFactory typeFactory, java.util.List<RelDataType> types)
private static RelDataType
toSql(RelDataTypeFactory typeFactory, RelDataType type)
<C> C
unwrap(java.lang.Class<C> aClass)
Finds an instance of an interface implemented by this object, or returns null if this object does not support that interface.CalciteCatalogReader
withSchemaPath(java.util.List<java.lang.String> schemaPath)
Returns a catalog reader the same as this one but with a possibly different schema path.
-
-
-
Field Detail
-
rootSchema
protected final CalciteSchema rootSchema
-
typeFactory
protected final RelDataTypeFactory typeFactory
-
schemaPaths
private final java.util.List<java.util.List<java.lang.String>> schemaPaths
-
nameMatcher
protected final SqlNameMatcher nameMatcher
-
config
protected final CalciteConnectionConfig config
-
-
Constructor Detail
-
CalciteCatalogReader
public CalciteCatalogReader(CalciteSchema rootSchema, java.util.List<java.lang.String> defaultSchema, RelDataTypeFactory typeFactory, CalciteConnectionConfig config)
-
CalciteCatalogReader
protected CalciteCatalogReader(CalciteSchema rootSchema, SqlNameMatcher nameMatcher, java.util.List<java.util.List<java.lang.String>> schemaPaths, RelDataTypeFactory typeFactory, CalciteConnectionConfig config)
-
-
Method Detail
-
withSchemaPath
public CalciteCatalogReader withSchemaPath(java.util.List<java.lang.String> schemaPath)
Description copied from interface:Prepare.CatalogReader
Returns a catalog reader the same as this one but with a possibly different schema path.- Specified by:
withSchemaPath
in interfacePrepare.CatalogReader
-
getTable
public Prepare.PreparingTable getTable(java.util.List<java.lang.String> names)
Description copied from interface:SqlValidatorCatalogReader
Finds a table or schema with the given name, possibly qualified.Uses the case-sensitivity policy of the catalog reader.
If not found, returns null. If you want a more descriptive error message or to override the case-sensitivity of the match, use
SqlValidatorScope.resolveTable(java.util.List<java.lang.String>, org.apache.calcite.sql.validate.SqlNameMatcher, org.apache.calcite.sql.validate.SqlValidatorScope.Path, org.apache.calcite.sql.validate.SqlValidatorScope.Resolved)
.- Specified by:
getTable
in interfacePrepare.CatalogReader
- Specified by:
getTable
in interfaceSqlValidatorCatalogReader
- Parameters:
names
- Name of table, may be qualified or fully-qualified- Returns:
- Table with the given name, or null
-
getConfig
public CalciteConnectionConfig getConfig()
Description copied from interface:SqlValidatorCatalogReader
Returns Config settings- Specified by:
getConfig
in interfaceSqlValidatorCatalogReader
-
getFunctionsFrom
private java.util.Collection<Function> getFunctionsFrom(java.util.List<java.lang.String> names)
-
getNamedType
public RelDataType getNamedType(SqlIdentifier typeName)
Description copied from interface:SqlValidatorCatalogReader
Finds a user-defined type with the given name, possibly qualified.NOTE jvs 12-Feb-2005: the reason this method is defined here instead of on RelDataTypeFactory is that it has to take into account context-dependent information such as SQL schema path, whereas a type factory is context-independent.
- Specified by:
getNamedType
in interfaceSqlValidatorCatalogReader
- Parameters:
typeName
- Name of type- Returns:
- named type, or null if not found
-
getAllSchemaObjectNames
public java.util.List<SqlMoniker> getAllSchemaObjectNames(java.util.List<java.lang.String> names)
Description copied from interface:SqlValidatorCatalogReader
Given fully qualified schema name, returns schema object names as specified. They can be schema, table, function, view. When names array is empty, the contents of root schema should be returned.- Specified by:
getAllSchemaObjectNames
in interfaceSqlValidatorCatalogReader
- Parameters:
names
- the array contains fully qualified schema name or empty list for root schema- Returns:
- the list of all object (schema, table, function, view) names under the above criteria
-
moniker
private SqlMonikerImpl moniker(CalciteSchema schema, java.lang.String name, SqlMonikerType type)
-
getSchemaPaths
public java.util.List<java.util.List<java.lang.String>> getSchemaPaths()
Description copied from interface:SqlValidatorCatalogReader
Returns the paths of all schemas to look in for tables.- Specified by:
getSchemaPaths
in interfaceSqlValidatorCatalogReader
- Returns:
- paths of current schema and root schema
-
getTableForMember
public Prepare.PreparingTable getTableForMember(java.util.List<java.lang.String> names)
Description copied from interface:RelOptSchema
Retrieves aRelOptTable
based upon a member access.For example, the Saffron expression
salesSchema.emps
would be resolved using a call tosalesSchema.getTableForMember(new String[]{"emps" })
.Note that name.length is only greater than 1 for queries originating from JDBC.
- Specified by:
getTableForMember
in interfacePrepare.CatalogReader
- Specified by:
getTableForMember
in interfaceRelOptSchema
- Parameters:
names
- Qualified name
-
field
public RelDataTypeField field(RelDataType rowType, java.lang.String alias)
- Specified by:
field
in interfaceSqlValidatorCatalogReader
-
matches
public boolean matches(java.lang.String string, java.lang.String name)
- Specified by:
matches
in interfaceSqlValidatorCatalogReader
-
createTypeFromProjection
public RelDataType createTypeFromProjection(RelDataType type, java.util.List<java.lang.String> columnNameList)
- Specified by:
createTypeFromProjection
in interfaceSqlValidatorCatalogReader
-
lookupOperatorOverloads
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, java.util.List<SqlOperator> operatorList)
Description copied from interface:SqlOperatorTable
Retrieves a list of operators with a given name and syntax. For example, by passing SqlSyntax.Function, the returned list is narrowed to only matching SqlFunction objects.- Specified by:
lookupOperatorOverloads
in interfaceSqlOperatorTable
- Parameters:
opName
- name of operatorcategory
- function category to look up, or null for any matching operatorsyntax
- syntax type of operatoroperatorList
- mutable list to which to append matches
-
operatorTable
public static SqlOperatorTable operatorTable(java.lang.String className)
Creates an operator table that contains functions in the given class.
-
toOp
private SqlOperator toOp(SqlIdentifier name, Function function)
-
toOp
private static SqlOperator toOp(RelDataTypeFactory typeFactory, SqlIdentifier name, Function function)
Converts a function to aSqlOperator
.The
typeFactory
argument is technical debt; see [CALCITE-2082] Remove RelDataTypeFactory argument from SqlUserDefinedAggFunction constructor.
-
infer
private static SqlReturnTypeInference infer(ScalarFunction function)
-
infer
private static SqlReturnTypeInference infer(AggregateFunction function)
-
toSql
private static java.util.List<RelDataType> toSql(RelDataTypeFactory typeFactory, java.util.List<RelDataType> types)
-
toSql
private static RelDataType toSql(RelDataTypeFactory typeFactory, RelDataType type)
-
getOperatorList
public java.util.List<SqlOperator> getOperatorList()
Description copied from interface:SqlOperatorTable
Retrieves a list of all functions and operators in this table. Used for automated testing.- Specified by:
getOperatorList
in interfaceSqlOperatorTable
- Returns:
- list of SqlOperator objects
-
getRootSchema
public CalciteSchema getRootSchema()
Description copied from interface:SqlValidatorCatalogReader
Returns the root namespace for name resolution.- Specified by:
getRootSchema
in interfaceSqlValidatorCatalogReader
-
getTypeFactory
public RelDataTypeFactory getTypeFactory()
Description copied from interface:RelOptSchema
Returns thetype factory
used to generate types for this schema.- Specified by:
getTypeFactory
in interfaceRelOptSchema
-
registerRules
public void registerRules(RelOptPlanner planner) throws java.lang.Exception
Description copied from interface:RelOptSchema
Registers all of the rules supported by this schema. Only called byRelOptPlanner.registerSchema(org.apache.calcite.plan.RelOptSchema)
.- Specified by:
registerRules
in interfaceRelOptSchema
- Throws:
java.lang.Exception
-
isCaseSensitive
public boolean isCaseSensitive()
- Specified by:
isCaseSensitive
in interfaceSqlValidatorCatalogReader
-
nameMatcher
public SqlNameMatcher nameMatcher()
Description copied from interface:SqlValidatorCatalogReader
Returns an implementation ofSqlNameMatcher
that matches the case-sensitivity policy.- Specified by:
nameMatcher
in interfaceSqlValidatorCatalogReader
-
-