Normalize a compound object name, rejecting schema-qualified forms. Accepts a single-part name (plain identifier) and returns it normalized. Rejects any name with more than one part (e.g. `public.users`, `db.public.users`) with `SqlError::Unsupported`.
(name: &sqlparser::ast::ObjectName)
| 24 | /// Rejects any name with more than one part (e.g. `public.users`, |
| 25 | /// `db.public.users`) with `SqlError::Unsupported`. |
| 26 | pub fn normalize_object_name_checked(name: &sqlparser::ast::ObjectName) -> Result<String> { |
| 27 | if name.0.len() > 1 { |
| 28 | // Build a human-readable representation of what was actually written. |
| 29 | let qualified: String = name |
| 30 | .0 |
| 31 | .iter() |
| 32 | .map(|part| match part { |
| 33 | sqlparser::ast::ObjectNamePart::Identifier(ident) => ident.value.clone(), |
| 34 | _ => String::new(), |
| 35 | }) |
| 36 | .collect::<Vec<_>>() |
| 37 | .join("."); |
| 38 | return Err(SqlError::Unsupported { |
| 39 | detail: format!("'{qualified}': {SCHEMA_QUALIFIED_MSG}"), |
| 40 | }); |
| 41 | } |
| 42 | Ok(name |
| 43 | .0 |
| 44 | .first() |
| 45 | .map(|part| match part { |
| 46 | sqlparser::ast::ObjectNamePart::Identifier(ident) => normalize_ident(ident), |
| 47 | _ => String::new(), |
| 48 | }) |
| 49 | .unwrap_or_default()) |
| 50 | } |
| 51 | |
| 52 | /// Extract table name and optional alias from a table factor. |
| 53 | /// |