pub struct TableReference {
pub catalog: Option<Ident>,
pub schema: Option<Ident>,
pub name: Ident,
}Expand description
Physical table identity — the catalog.schema.name triplet.
TableReference deliberately carries no alias: aliasing is a
use-site decoration, not part of a table’s identity. Use-site alias
information, when needed, is carried by the structures that wrap a
TableReference (e.g. resolver bindings).
Equality has two levels. The derived Eq / Hash are
structural — case- and quote-sensitive, exact segments. That is the
right dedup when references come from catalog-backed analysis (matched
tables are canonicalized, so equal tables produce equal references) and
for direct cross-statement comparison. For catalog-free dedup, where
the same table may appear under fold-equivalent spellings (users vs
USERS), use identity_key /
same_table, which fold by a dialect’s
IdentifierCasing.
Fields§
§catalog: Option<Ident>§schema: Option<Ident>§name: IdentImplementations§
Source§impl TableReference
impl TableReference
Sourcepub fn identity_key(&self, casing: &IdentifierCasing) -> TableIdentityKey
pub fn identity_key(&self, casing: &IdentifierCasing) -> TableIdentityKey
The dialect-aware TableIdentityKey for this reference: each
segment folded by casing’s table rule. Equal keys denote the same
table under that dialect’s casing.
This is the catalog-free dedup key. The structural Eq on
TableReference is exact (case- and quote-sensitive), so without a
catalog to canonicalize spellings it over-counts users and USERS
as two tables; folding by the dialect’s casing collapses them.
use std::collections::HashSet;
use sql_insight::{CaseRule, IdentifierCasing, TableReference};
let users = TableReference { catalog: None, schema: None, name: "users".into() };
let upper = TableReference { catalog: None, schema: None, name: "USERS".into() };
// Structural equality is exact — these read as two different tables.
assert_ne!(users, upper);
// Under a case-folding dialect (here lower-folding, e.g. PostgreSQL)
// they share one identity.
let casing = IdentifierCasing::uniform(CaseRule::Lower);
assert!(users.same_table(&upper, &casing));
// So a fold-keyed set counts the table once, where a structural
// `HashSet<TableReference>` would count two.
let distinct: HashSet<_> = [&users, &upper]
.iter()
.map(|t| t.identity_key(&casing))
.collect();
assert_eq!(distinct.len(), 1);
// Identity, not wildcard: a bare name and a schema-qualified one stay
// distinct (different identities, not a prefix match).
let qualified = TableReference {
catalog: None,
schema: Some("public".into()),
name: "users".into(),
};
assert!(!users.same_table(&qualified, &casing));Sourcepub fn same_table(&self, other: &Self, casing: &IdentifierCasing) -> bool
pub fn same_table(&self, other: &Self, casing: &IdentifierCasing) -> bool
Whether self and other denote the same table under casing —
equivalent to comparing their identity_keys.
Trait Implementations§
Source§impl Clone for TableReference
impl Clone for TableReference
Source§fn clone(&self) -> TableReference
fn clone(&self) -> TableReference
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TableReference
impl Debug for TableReference
Source§impl Display for TableReference
impl Display for TableReference
impl Eq for TableReference
Source§impl Hash for TableReference
impl Hash for TableReference
Source§impl PartialEq for TableReference
impl PartialEq for TableReference
Source§fn eq(&self, other: &TableReference) -> bool
fn eq(&self, other: &TableReference) -> bool
self and other values to be equal, and is used by ==.