Skip to main content

uqa_execution/query/block/
context.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Statement-bound row access and retrieval execution for query blocks.
8
9use std::collections::BTreeMap;
10use uqa_core::{DocId, ScoredEntry, Value};
11use uqa_sql::{ast::ColumnDef, SQLError, SQLParam, ScalarExpr};
12use uqa_storage::document_store::Document;
13
14pub trait QueryDocumentRead: Sync {
15    fn document_ids(&self, table: &str) -> Result<Vec<DocId>, SQLError>;
16    fn document(&self, table: &str, doc_id: DocId) -> Result<Option<Document>, SQLError>;
17    fn document_fields(
18        &self,
19        table: &str,
20        ids: &[DocId],
21        fields: &[&str],
22    ) -> Result<BTreeMap<DocId, Vec<Value>>, SQLError>;
23    fn column_definitions(&self, table: &str) -> Result<Option<Vec<ColumnDef>>, String>;
24    /// Whether a read of `table` merges changes from the command overlay that the table's storage view does not show. A read of a table for which this is false sees exactly its storage view.
25    fn command_overlay_holds(&self, table: &str) -> Result<bool, SQLError>;
26}
27
28/// Retrieval planning and execution against the caller's selected relation generation.
29pub trait RelationRetrieval: Sync {
30    fn prepare_accelerated<'a>(
31        &'a self,
32        table: &'a str,
33        signal_table: &'a str,
34        predicate: Option<&ScalarExpr>,
35        params: &'a [SQLParam],
36        capture_complete_scores: bool,
37    ) -> Result<Option<crate::query::scored_input::ScoredEntriesProducer<'a>>, SQLError>;
38    fn optimized(
39        &self,
40        table: &str,
41        predicate: Option<&ScalarExpr>,
42        params: &[SQLParam],
43    ) -> Result<Option<Vec<ScoredEntry>>, SQLError>;
44    fn captured(
45        &self,
46        table: &str,
47        predicate: Option<&ScalarExpr>,
48        params: &[SQLParam],
49    ) -> Result<Option<crate::query::scored_input::ProducedScoredEntries>, SQLError> {
50        self.optimized(table, predicate, params)
51            .map(|entries| entries.map(Into::into))
52    }
53    fn function(
54        &self,
55        table: &str,
56        signal_table: &str,
57        name: &str,
58        args: &[ScalarExpr],
59        params: &[SQLParam],
60        top_k: Option<usize>,
61    ) -> Result<Vec<ScoredEntry>, SQLError>;
62}