Trait sql::catalog::SessionCatalog [−][src]
pub trait SessionCatalog: Debug + ExprHumanizer {
Show 17 methods
fn search_path(&self, include_system_schemas: bool) -> Vec<&str>ⓘ;
fn user(&self) -> &str;
fn get_prepared_statement_desc(&self, name: &str) -> Option<&StatementDesc>;
fn default_database(&self) -> &str;
fn resolve_database(
&self,
database_name: &str
) -> Result<&dyn CatalogDatabase, CatalogError>;
fn resolve_schema(
&self,
database_name: Option<String>,
schema_name: &str
) -> Result<&dyn CatalogSchema, CatalogError>;
fn resolve_role(
&self,
role_name: &str
) -> Result<&dyn CatalogRole, CatalogError>;
fn resolve_item(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>;
fn resolve_function(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>;
fn try_get_item_by_id(&self, id: &GlobalId) -> Option<&dyn CatalogItem>;
fn get_item_by_id(&self, id: &GlobalId) -> &dyn CatalogItem;
fn get_item_by_oid(&self, oid: &u32) -> &dyn CatalogItem;
fn item_exists(&self, name: &FullName) -> bool;
fn try_get_lossy_scalar_type_by_id(
&self,
id: &GlobalId
) -> Option<ScalarType>;
fn config(&self) -> &CatalogConfig;
fn now(&self) -> EpochMillis;
fn find_available_name(&self, name: FullName) -> FullName { ... }
}
Expand description
A catalog keeps track of SQL objects and session state available to the planner.
The sql
crate is agnostic to any particular catalog implementation. This
trait describes the required interface.
The SQL standard mandates a catalog hierarchy of exactly three layers. A catalog contains databases, databases contain schemas, and schemas contain catalog items, like sources, sinks, view, and indexes.
There are two classes of operations provided by a catalog:
-
Resolution operations, like
resolve_item
. These fill in missing name components based upon connection defaults, e.g., resolving the partial nameview42
to the fully-specified namematerialize.public.view42
. -
Lookup operations, like
SessionCatalog::get_item_by_id
. These retrieve metadata about a catalog entity based on a fully-specified name that is known to be valid (i.e., because the name was successfully resolved, or was constructed based on the output of a prior lookup operation). These functions panic if called with invalid input.
Required methods
Returns the search path used by the catalog.
fn get_prepared_statement_desc(&self, name: &str) -> Option<&StatementDesc>
fn get_prepared_statement_desc(&self, name: &str) -> Option<&StatementDesc>
Returns the descriptor of the named prepared statement on the session, or None if the prepared statement does not exist.
fn default_database(&self) -> &str
fn default_database(&self) -> &str
Returns the database to use if one is not explicitly specified.
fn resolve_database(
&self,
database_name: &str
) -> Result<&dyn CatalogDatabase, CatalogError>
fn resolve_database(
&self,
database_name: &str
) -> Result<&dyn CatalogDatabase, CatalogError>
Resolves the named database.
If database_name
exists in the catalog, it returns the ID of the
resolved database; otherwise it returns an error.
fn resolve_schema(
&self,
database_name: Option<String>,
schema_name: &str
) -> Result<&dyn CatalogSchema, CatalogError>
fn resolve_schema(
&self,
database_name: Option<String>,
schema_name: &str
) -> Result<&dyn CatalogSchema, CatalogError>
Resolves a partially-specified schema name.
If database_name
is provided, it searches the named database for a
schema named schema_name
. If database_name
is not provided, it
searches the default database instead. It returns the ID of the schema
if found; otherwise it returns an error if the database does not exist,
or if the database exists but the schema does not.
fn resolve_role(
&self,
role_name: &str
) -> Result<&dyn CatalogRole, CatalogError>
fn resolve_role(
&self,
role_name: &str
) -> Result<&dyn CatalogRole, CatalogError>
Resolves the named role.
fn resolve_item(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>
fn resolve_item(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>
Resolves a partially-specified item name.
If the partial name has a database component, it searches only the specified database; otherwise, it searches the default database. If the partial name has a schema component, it searches only the specified schema; otherwise, it searches a default set of schemas within the selected database. It returns an error if none of the searched schemas contain an item whose name matches the item component of the partial name.
Note that it is not an error if the named item appears in more than one of the search schemas. The catalog implementation must choose one.
fn resolve_function(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>
fn resolve_function(
&self,
item_name: &PartialName
) -> Result<&dyn CatalogItem, CatalogError>
Performs the same operation as SessionCatalog::resolve_item
but for
functions within the catalog.
fn try_get_item_by_id(&self, id: &GlobalId) -> Option<&dyn CatalogItem>
fn try_get_item_by_id(&self, id: &GlobalId) -> Option<&dyn CatalogItem>
Gets an item by its ID.
fn get_item_by_id(&self, id: &GlobalId) -> &dyn CatalogItem
fn get_item_by_id(&self, id: &GlobalId) -> &dyn CatalogItem
Gets an item by its ID.
Panics if id
does not specify a valid item.
fn get_item_by_oid(&self, oid: &u32) -> &dyn CatalogItem
fn get_item_by_oid(&self, oid: &u32) -> &dyn CatalogItem
Gets an item by its OID.
Panics if oid
does not specify a valid item.
fn item_exists(&self, name: &FullName) -> bool
fn item_exists(&self, name: &FullName) -> bool
Reports whether the specified type exists in the catalog.
fn try_get_lossy_scalar_type_by_id(&self, id: &GlobalId) -> Option<ScalarType>
fn try_get_lossy_scalar_type_by_id(&self, id: &GlobalId) -> Option<ScalarType>
Returns a lossy ScalarType
associated with id
if one exists.
For example pg_catalog.numeric
returns ScalarType::Numeric { scale: None}
,
meaning that its precision and scale need to be associated with values
from elsewhere.
fn config(&self) -> &CatalogConfig
fn config(&self) -> &CatalogConfig
Returns the configuration of the catalog.
fn now(&self) -> EpochMillis
fn now(&self) -> EpochMillis
Returns the number of milliseconds since the system epoch. For normal use this means the Unix epoch. This can safely be mocked in tests and start at 0.
Provided methods
fn find_available_name(&self, name: FullName) -> FullName
fn find_available_name(&self, name: FullName) -> FullName
Finds a name like name
that is not already in use.
If name
itself is available, it is returned unchanged.