rustfs_s3select_api/query/
mod.rs1use s3s::dto::SelectObjectContentInput;
16use std::sync::Arc;
17
18use crate::{SelectInputMetrics, SelectObjectSnapshot};
19
20pub mod analyzer;
21pub mod ast;
22pub mod dispatcher;
23pub mod execution;
24pub mod function;
25pub mod logical_planner;
26pub mod optimizer;
27pub mod parser;
28pub mod physical_planner;
29pub mod scheduler;
30pub mod session;
31
32#[derive(Clone)]
33pub struct Context {
34 pub input: Arc<SelectObjectContentInput>,
36}
37
38#[derive(Clone)]
39pub struct Query {
40 context: Context,
41 content: String,
42 snapshot: Option<Arc<SelectObjectSnapshot>>,
43 input_metrics: Arc<SelectInputMetrics>,
44}
45
46impl Query {
47 #[inline(always)]
48 pub fn new(context: Context, content: String) -> Self {
49 Self {
50 context,
51 content,
52 snapshot: None,
53 input_metrics: Arc::new(SelectInputMetrics::default()),
54 }
55 }
56
57 #[inline(always)]
58 pub fn new_with_snapshot(context: Context, content: String, snapshot: Arc<SelectObjectSnapshot>) -> Self {
59 Self {
60 context,
61 content,
62 snapshot: Some(snapshot),
63 input_metrics: Arc::new(SelectInputMetrics::default()),
64 }
65 }
66
67 pub fn context(&self) -> &Context {
68 &self.context
69 }
70
71 pub fn content(&self) -> &str {
72 self.content.as_str()
73 }
74
75 pub fn snapshot(&self) -> Option<&Arc<SelectObjectSnapshot>> {
76 self.snapshot.as_ref()
77 }
78
79 pub fn input_metrics(&self) -> &Arc<SelectInputMetrics> {
80 &self.input_metrics
81 }
82
83 pub fn for_execution(&self) -> Self {
84 Self {
85 context: self.context.clone(),
86 content: self.content.clone(),
87 snapshot: self.snapshot.clone(),
88 input_metrics: Arc::new(SelectInputMetrics::default()),
89 }
90 }
91}
92
93#[cfg(test)]
94fn test_query() -> Query {
95 use s3s::dto::{CSVInput, CSVOutput, ExpressionType, InputSerialization, OutputSerialization, SelectObjectContentRequest};
96
97 let input = SelectObjectContentInput {
98 bucket: "bucket".to_string(),
99 expected_bucket_owner: None,
100 key: "input.csv".to_string(),
101 sse_customer_algorithm: None,
102 sse_customer_key: None,
103 sse_customer_key_md5: None,
104 request: SelectObjectContentRequest {
105 expression: "SELECT * FROM S3Object".to_string(),
106 expression_type: ExpressionType::from_static(ExpressionType::SQL),
107 input_serialization: InputSerialization {
108 csv: Some(CSVInput::default()),
109 ..Default::default()
110 },
111 output_serialization: OutputSerialization {
112 csv: Some(CSVOutput::default()),
113 ..Default::default()
114 },
115 request_progress: None,
116 scan_range: None,
117 },
118 };
119 Query::new(Context { input: Arc::new(input) }, "SELECT * FROM S3Object".to_string())
120}