Possibilities we search with, in order from top to bottom for each len: len = 2: 1. (table.column) 2. (column).nested len = 3: 1. (schema.table.column) 2. (table.column).nested 3. (column).nested1.nested2 len = 4: 1. (catalog.schema.table.column) 2. (schema.table.column).nested1 3. (table.column).nested1.nested2 4. (column).nested1.nested2.nested3 len = 5: 1. (catalog.schema.table.column).nest
(
ids: &[String],
)
| 352 | // 3. (table.column).nested1.nested2.nested3[.nestedN]+ |
| 353 | // 4. (column).nested1.nested2.nested3.nested4[.nestedN]+ |
| 354 | fn generate_schema_search_terms( |
| 355 | ids: &[String], |
| 356 | ) -> impl Iterator<Item = (Option<TableReference>, &String, &[String])> { |
| 357 | // Take at most 4 identifiers to form a Column to search with |
| 358 | // - 1 for the column name |
| 359 | // - 0 to 3 for the TableReference |
| 360 | let bound = ids.len().min(4); |
| 361 | // Search terms from most specific to least specific |
| 362 | (0..bound).rev().map(|i| { |
| 363 | let nested_names_index = i + 1; |
| 364 | let qualifier_and_column = &ids[0..nested_names_index]; |
| 365 | // Safe unwrap as qualifier_and_column can never be empty or exceed the bounds |
| 366 | let (relation, column_name) = form_identifier(qualifier_and_column).unwrap(); |
| 367 | (relation, column_name, &ids[nested_names_index..]) |
| 368 | }) |
| 369 | } |
| 370 | |
| 371 | #[cfg(test)] |
| 372 | mod test { |
searching dependent graphs…