uqa_engine/capabilities/
copy.rs1use crate::{Engine, TableState};
9use std::sync::Arc;
10use uqa_execution::copy::{CopyExecutionContext, CopyPrivileges, CopyStatements};
11use uqa_sql::{
12 assignment::columns::ColumnCatalogError,
13 ast::{ColumnDef, Statement},
14 catalog::security::table::TableAclPrivilege,
15 copy::stream::{CopyCatalog, CopyRelation},
16 SQLError, SQLParam, SQLResult,
17};
18impl Engine {
19 pub(crate) fn copy_execution_context(&self) -> CopyExecutionContext<'_> {
20 CopyExecutionContext {
21 catalog: self,
22 privileges: self,
23 statements: self,
24 output: self,
25 memory: self.session.as_ref(),
26 cancellation: &self.runtime.cancellation,
27 }
28 }
29}
30struct CopyTable(Arc<TableState>);
31impl CopyRelation for CopyTable {
32 fn columns(&self) -> Vec<ColumnDef> {
33 self.0.columns.read().clone()
34 }
35 fn is_partitioned(&self) -> bool {
36 self.0.hierarchy.read().partition_spec.is_some()
37 }
38}
39impl CopyCatalog for Engine {
40 fn resolve_relation_kind(
41 &self,
42 name: &str,
43 ) -> Result<Option<(String, &'static str)>, SQLError> {
44 self.try_resolve_visible_relation_kind(name)
45 }
46 fn table(&self, name: &str) -> Result<Option<Box<dyn CopyRelation + '_>>, ColumnCatalogError> {
47 self.try_table(name)
48 .map(|table| table.map(|table| Box::new(CopyTable(table)) as Box<dyn CopyRelation>))
49 .map_err(|error| Box::new(error) as _)
50 }
51}
52impl CopyPrivileges for Engine {
53 fn ensure_any_column(&self, table: &str, privilege: TableAclPrivilege) -> Result<(), SQLError> {
54 self.ensure_any_column_privilege(table, privilege)
55 }
56 fn ensure_column(
57 &self,
58 table: &str,
59 column: &str,
60 privilege: TableAclPrivilege,
61 ) -> Result<(), SQLError> {
62 self.ensure_column_privilege(table, column, privilege)
63 }
64}
65impl CopyStatements for Engine {
66 fn execute_statement(
67 &self,
68 statement: Statement,
69 params: &[SQLParam],
70 ) -> Result<SQLResult, SQLError> {
71 uqa_execution::statement::compiled::execute(
72 &self.compiled_statement_context(),
73 statement,
74 params,
75 )
76 }
77 fn execute_text_with_output(
78 &self,
79 text: &str,
80 params: &[SQLParam],
81 consume: &mut dyn FnMut(
82 uqa_execution::statement::plan_executor::StatementOutput,
83 ) -> Result<(), SQLError>,
84 ) -> Result<(), SQLError> {
85 uqa_execution::statement::batch::execute_with_output(
86 &self.batch_execution_context(),
87 text,
88 params,
89 consume,
90 )
91 }
92}