Skip to main content

uqa_sql/catalog/resolution/
candidates.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Legacy relation candidates with lazy session input reads and exact search-path ordering.
8#[cfg(test)]
9mod tests;
10use std::ops::Deref;
11use uqa_core::RelationIdentity;
12pub type SearchPathRead<'a> = Box<dyn Deref<Target = Vec<String>> + 'a>;
13pub trait RelationCandidateState {
14    fn temporary_schema_name(&self) -> String;
15    fn search_path(&self) -> SearchPathRead<'_>;
16}
17pub fn relation_lookup_candidates(
18    state: &dyn RelationCandidateState,
19    name: &str,
20) -> Result<Vec<RelationIdentity>, String> {
21    let (schema, relation) = RelationIdentity::parse_reference(name)?;
22    if let Some(schema) = schema {
23        if schema == "pg_temp" {
24            return Ok(vec![RelationIdentity::new(
25                state.temporary_schema_name(),
26                relation,
27            )]);
28        }
29        return Ok(vec![RelationIdentity::new(schema, relation)]);
30    }
31    let mut candidates = Vec::new();
32    candidates.push(RelationIdentity::new(
33        state.temporary_schema_name(),
34        &relation,
35    ));
36    for schema in state.search_path().iter() {
37        if schema == "pg_catalog" || schema == "information_schema" {
38            continue;
39        }
40        candidates.push(RelationIdentity::new(schema, &relation));
41    }
42    Ok(candidates)
43}