Construct a WHERE qualifier suitable for e.g. information_schema filtering from the provided object identifiers (catalog, schema and table names).
(
sql_table_name: &ObjectName,
enable_normalization: bool,
)
| 1012 | /// Construct a WHERE qualifier suitable for e.g. information_schema filtering |
| 1013 | /// from the provided object identifiers (catalog, schema and table names). |
| 1014 | pub fn object_name_to_qualifier( |
| 1015 | sql_table_name: &ObjectName, |
| 1016 | enable_normalization: bool, |
| 1017 | ) -> Result<String> { |
| 1018 | let columns = vec!["table_name", "table_schema", "table_catalog"].into_iter(); |
| 1019 | let normalizer = IdentNormalizer::new(enable_normalization); |
| 1020 | sql_table_name |
| 1021 | .0 |
| 1022 | .iter() |
| 1023 | .rev() |
| 1024 | .zip(columns) |
| 1025 | .map(|(object_name_part, column_name)| { |
| 1026 | object_name_part |
| 1027 | .as_ident() |
| 1028 | .map(|ident| { |
| 1029 | format!( |
| 1030 | r#"{} = '{}'"#, |
| 1031 | column_name, |
| 1032 | normalizer.normalize(ident.clone()) |
| 1033 | ) |
| 1034 | }) |
| 1035 | .ok_or_else(|| { |
| 1036 | plan_datafusion_err!( |
| 1037 | "Expected identifier, but found: {:?}", |
| 1038 | object_name_part |
| 1039 | ) |
| 1040 | }) |
| 1041 | }) |
| 1042 | .collect::<Result<Vec<_>>>() |
| 1043 | .map(|parts| parts.join(" AND ")) |
| 1044 | } |