Skip to content

Commit 91f8dea

Browse files
authored
chore(tesseract): Small sql-call building refactoring (#10193)
1 parent 53d79bb commit 91f8dea

File tree

11 files changed

+54
-44
lines changed

11 files changed

+54
-44
lines changed

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/base_tools.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::driver_tools::{DriverTools, NativeDriverTools};
22
use super::join_definition::{JoinDefinition, NativeJoinDefinition};
33
use super::pre_aggregation_obj::{NativePreAggregationObj, PreAggregationObj};
4-
use super::security_context::{NativeSecurityContext, SecurityContext};
54
use super::sql_templates_render::{NativeSqlTemplatesRender, SqlTemplatesRender};
65
use super::sql_utils::{NativeSqlUtils, SqlUtils};
76
use crate::cube_bridge::join_hints::JoinHintItem;
@@ -18,7 +17,6 @@ use std::rc::Rc;
1817
pub trait BaseTools {
1918
fn driver_tools(&self, external: bool) -> Result<Rc<dyn DriverTools>, CubeError>;
2019
fn sql_templates(&self) -> Result<Rc<dyn SqlTemplatesRender>, CubeError>;
21-
fn security_context_for_rust(&self) -> Result<Rc<dyn SecurityContext>, CubeError>;
2220
fn sql_utils_for_rust(&self) -> Result<Rc<dyn SqlUtils>, CubeError>;
2321
fn generate_time_series(
2422
&self,

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/member_sql.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{
33
security_context::{NativeSecurityContext, SecurityContext},
44
sql_utils::NativeSqlUtils,
55
};
6-
use crate::cube_bridge::sql_utils::SqlUtils;
6+
use crate::cube_bridge::base_tools::BaseTools;
77
use crate::planner::sql_evaluator::SqlCallArg;
88
use crate::utils::UniqueVector;
99
use cubenativeutils::wrappers::object::{NativeFunction, NativeStruct, NativeType};
@@ -301,7 +301,7 @@ pub trait MemberSql {
301301
fn as_any(self: Rc<Self>) -> Rc<dyn Any>;
302302
fn compile_template_sql(
303303
&self,
304-
sql_utils: Rc<dyn SqlUtils>,
304+
base_tools: Rc<dyn BaseTools>,
305305
security_context: Rc<dyn SecurityContext>,
306306
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError>;
307307
}
@@ -634,7 +634,7 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
634634

635635
fn compile_template_sql(
636636
&self,
637-
sql_utils: Rc<dyn SqlUtils>,
637+
base_tools: Rc<dyn BaseTools>,
638638
security_context: Rc<dyn SecurityContext>,
639639
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError> {
640640
let state = ProxyState::new();
@@ -667,8 +667,8 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
667667
context_obj,
668668
)?
669669
} else if arg == "SQL_UTILS" {
670-
sql_utils
671-
.clone()
670+
base_tools
671+
.sql_utils_for_rust()?
672672
.as_any()
673673
.downcast::<NativeSqlUtils<IT>>()
674674
.unwrap()

rust/cubesqlplanner/cubesqlplanner/src/planner/query_tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl QueryTools {
135135
};
136136
let evaluator_compiler = Rc::new(RefCell::new(Compiler::new(
137137
cube_evaluator.clone(),
138-
base_tools.sql_utils_for_rust()?,
138+
base_tools.clone(),
139139
security_context.clone(),
140140
timezone.clone(),
141141
)));

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/compiler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ use super::{
44
CubeNameSymbolFactory, CubeTableSymbolFactory, DimensionSymbolFactory, MeasureSymbolFactory,
55
SqlCall, SymbolFactory, TraversalVisitor,
66
};
7+
use crate::cube_bridge::base_tools::BaseTools;
78
use crate::cube_bridge::evaluator::CubeEvaluator;
89
use crate::cube_bridge::join_hints::JoinHintItem;
910
use crate::cube_bridge::member_sql::MemberSql;
1011
use crate::cube_bridge::security_context::SecurityContext;
11-
use crate::cube_bridge::sql_utils::SqlUtils;
1212
use crate::planner::sql_evaluator::sql_call_builder::SqlCallBuilder;
1313
use chrono_tz::Tz;
1414
use cubenativeutils::CubeError;
1515
use std::collections::HashMap;
1616
use std::rc::Rc;
1717
pub struct Compiler {
1818
cube_evaluator: Rc<dyn CubeEvaluator>,
19-
sql_utils: Rc<dyn SqlUtils>,
19+
base_tools: Rc<dyn BaseTools>,
2020
security_context: Rc<dyn SecurityContext>,
2121
timezone: Tz,
2222
/* (type, name) */
@@ -26,14 +26,14 @@ pub struct Compiler {
2626
impl Compiler {
2727
pub fn new(
2828
cube_evaluator: Rc<dyn CubeEvaluator>,
29-
sql_utils: Rc<dyn SqlUtils>,
29+
base_tools: Rc<dyn BaseTools>,
3030
security_context: Rc<dyn SecurityContext>,
3131
timezone: Tz,
3232
) -> Self {
3333
Self {
3434
cube_evaluator,
3535
security_context,
36-
sql_utils,
36+
base_tools,
3737
timezone,
3838
members: HashMap::new(),
3939
}
@@ -132,7 +132,7 @@ impl Compiler {
132132
let call_builder = SqlCallBuilder::new(
133133
self,
134134
self.cube_evaluator.clone(),
135-
self.sql_utils.clone(),
135+
self.base_tools.clone(),
136136
self.security_context.clone(),
137137
);
138138
let sql_call = call_builder.build(&cube_name, member_sql.clone())?;

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/sql_call_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::symbols::MemberSymbol;
22
use super::Compiler;
33
use super::{SqlCall, SqlCallDependency, SqlCallFilterGroupItem, SqlCallFilterParamsItem};
4+
use crate::cube_bridge::base_tools::BaseTools;
45
use crate::cube_bridge::evaluator::CubeEvaluator;
56
use crate::cube_bridge::member_sql::*;
67
use crate::cube_bridge::security_context::SecurityContext;
7-
use crate::cube_bridge::sql_utils::SqlUtils;
88
use crate::planner::sql_evaluator::TimeDimensionSymbol;
99
use crate::planner::GranularityHelper;
1010
use cubenativeutils::CubeError;
@@ -13,21 +13,21 @@ use std::rc::Rc;
1313
pub struct SqlCallBuilder<'a> {
1414
compiler: &'a mut Compiler,
1515
cube_evaluator: Rc<dyn CubeEvaluator>,
16-
sql_utils: Rc<dyn SqlUtils>,
16+
base_tools: Rc<dyn BaseTools>,
1717
security_context: Rc<dyn SecurityContext>,
1818
}
1919

2020
impl<'a> SqlCallBuilder<'a> {
2121
pub fn new(
2222
compiler: &'a mut Compiler,
2323
cube_evaluator: Rc<dyn CubeEvaluator>,
24-
sql_utils: Rc<dyn SqlUtils>,
24+
base_tools: Rc<dyn BaseTools>,
2525
security_context: Rc<dyn SecurityContext>,
2626
) -> Self {
2727
Self {
2828
compiler,
2929
cube_evaluator,
30-
sql_utils,
30+
base_tools,
3131
security_context,
3232
}
3333
}
@@ -38,7 +38,7 @@ impl<'a> SqlCallBuilder<'a> {
3838
member_sql: Rc<dyn MemberSql>,
3939
) -> Result<SqlCall, CubeError> {
4040
let (template, template_args) = member_sql
41-
.compile_template_sql(self.sql_utils.clone(), self.security_context.clone())?;
41+
.compile_template_sql(self.base_tools.clone(), self.security_context.clone())?;
4242

4343
let deps = template_args
4444
.symbol_paths

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/cube_bridge/mock_base_tools.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ use crate::cube_bridge::driver_tools::DriverTools;
33
use crate::cube_bridge::join_definition::JoinDefinition;
44
use crate::cube_bridge::join_hints::JoinHintItem;
55
use crate::cube_bridge::pre_aggregation_obj::PreAggregationObj;
6-
use crate::cube_bridge::security_context::SecurityContext;
76
use crate::cube_bridge::sql_templates_render::SqlTemplatesRender;
87
use crate::cube_bridge::sql_utils::SqlUtils;
9-
use crate::test_fixtures::cube_bridge::{
10-
MockDriverTools, MockSecurityContext, MockSqlTemplatesRender, MockSqlUtils,
11-
};
8+
use crate::test_fixtures::cube_bridge::{MockDriverTools, MockSqlTemplatesRender, MockSqlUtils};
129
use cubenativeutils::CubeError;
1310
use std::any::Any;
1411
use std::rc::Rc;
@@ -29,9 +26,6 @@ pub struct MockBaseTools {
2926
#[builder(default = Rc::new(MockSqlTemplatesRender::default_templates()))]
3027
sql_templates: Rc<MockSqlTemplatesRender>,
3128

32-
#[builder(default = Rc::new(MockSecurityContext))]
33-
security_context: Rc<MockSecurityContext>,
34-
3529
#[builder(default = Rc::new(MockSqlUtils))]
3630
sql_utils: Rc<MockSqlUtils>,
3731
}
@@ -55,10 +49,6 @@ impl BaseTools for MockBaseTools {
5549
Ok(self.sql_templates.clone())
5650
}
5751

58-
fn security_context_for_rust(&self) -> Result<Rc<dyn SecurityContext>, CubeError> {
59-
Ok(self.security_context.clone())
60-
}
61-
6252
fn sql_utils_for_rust(&self) -> Result<Rc<dyn SqlUtils>, CubeError> {
6353
Ok(self.sql_utils.clone())
6454
}

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/cube_bridge/mock_member_sql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::cube_bridge::base_tools::BaseTools;
12
use crate::cube_bridge::member_sql::{MemberSql, SqlTemplate, SqlTemplateArgs};
23
use crate::cube_bridge::security_context::SecurityContext;
3-
use crate::cube_bridge::sql_utils::SqlUtils;
44
use cubenativeutils::CubeError;
55
use std::any::Any;
66
use std::rc::Rc;
@@ -112,7 +112,7 @@ impl MemberSql for MockMemberSql {
112112

113113
fn compile_template_sql(
114114
&self,
115-
_sql_utils: Rc<dyn SqlUtils>,
115+
_base_tools: Rc<dyn BaseTools>,
116116
_security_context: Rc<dyn SecurityContext>,
117117
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError> {
118118
Ok((
@@ -240,7 +240,7 @@ mod tests {
240240
let mock = Rc::new(MockMemberSql::new("{CUBE.field} / {other.field}").unwrap());
241241
let (template, args) = mock
242242
.compile_template_sql(
243-
Rc::new(crate::test_fixtures::cube_bridge::MockSqlUtils),
243+
Rc::new(crate::test_fixtures::cube_bridge::MockBaseTools::default()),
244244
Rc::new(crate::test_fixtures::cube_bridge::MockSecurityContext),
245245
)
246246
.unwrap();

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/cube_bridge/mock_schema.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ mod tests {
507507
use crate::cube_bridge::join_item_definition::JoinItemDefinition;
508508
use crate::cube_bridge::measure_definition::MeasureDefinition;
509509
use crate::cube_bridge::segment_definition::SegmentDefinition;
510+
use crate::test_fixtures::cube_bridge::MockBaseTools;
510511

511512
#[test]
512513
fn test_basic_schema() {
@@ -1043,7 +1044,7 @@ mod tests {
10431044

10441045
#[test]
10451046
fn test_view_with_multiple_long_join_paths() {
1046-
use crate::test_fixtures::cube_bridge::{MockSecurityContext, MockSqlUtils};
1047+
use crate::test_fixtures::cube_bridge::MockSecurityContext;
10471048
use std::rc::Rc;
10481049

10491050
let schema = MockSchemaBuilder::new()
@@ -1103,7 +1104,10 @@ mod tests {
11031104

11041105
// Compile template and check symbol_paths structure
11051106
let (_template, args) = checkin_id_sql
1106-
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
1107+
.compile_template_sql(
1108+
Rc::new(MockBaseTools::default()),
1109+
Rc::new(MockSecurityContext),
1110+
)
11071111
.unwrap();
11081112

11091113
// Should have exactly one symbol path
@@ -1126,7 +1130,10 @@ mod tests {
11261130
let checkin_count_sql = checkin_count_measure.sql().unwrap().unwrap();
11271131

11281132
let (_template, args) = checkin_count_sql
1129-
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
1133+
.compile_template_sql(
1134+
Rc::new(MockBaseTools::default()),
1135+
Rc::new(MockSecurityContext),
1136+
)
11301137
.unwrap();
11311138

11321139
assert_eq!(
@@ -1146,7 +1153,10 @@ mod tests {
11461153
let id_sql = id_dim.sql().unwrap().unwrap();
11471154

11481155
let (_template, args) = id_sql
1149-
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
1156+
.compile_template_sql(
1157+
Rc::new(MockBaseTools::default()),
1158+
Rc::new(MockSecurityContext),
1159+
)
11501160
.unwrap();
11511161

11521162
assert_eq!(
@@ -1164,7 +1174,10 @@ mod tests {
11641174
let count_sql = count_measure.sql().unwrap().unwrap();
11651175

11661176
let (_template, args) = count_sql
1167-
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
1177+
.compile_template_sql(
1178+
Rc::new(MockBaseTools::default()),
1179+
Rc::new(MockSecurityContext),
1180+
)
11681181
.unwrap();
11691182

11701183
assert_eq!(

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/cube_bridge/mock_segment_definition.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ impl SegmentDefinition for MockSegmentDefinition {
4141

4242
#[cfg(test)]
4343
mod tests {
44+
use crate::test_fixtures::cube_bridge::MockBaseTools;
45+
4446
use super::*;
4547

4648
#[test]
@@ -88,9 +90,12 @@ mod tests {
8890
let sql = segment.sql().unwrap();
8991
assert_eq!(sql.args_names(), &vec!["CUBE"]);
9092

91-
use crate::test_fixtures::cube_bridge::{MockSecurityContext, MockSqlUtils};
93+
use crate::test_fixtures::cube_bridge::MockSecurityContext;
9294
let (template, args) = sql
93-
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
95+
.compile_template_sql(
96+
Rc::new(MockBaseTools::default()),
97+
Rc::new(MockSecurityContext),
98+
)
9499
.unwrap();
95100

96101
match template {

rust/cubesqlplanner/cubesqlplanner/src/test_fixtures/schemas/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod visitors_schema;
33
pub use visitors_schema::create_visitors_schema;
44

55
use crate::planner::sql_evaluator::Compiler;
6-
use crate::test_fixtures::cube_bridge::{MockCubeEvaluator, MockSecurityContext, MockSqlUtils};
6+
use crate::test_fixtures::cube_bridge::{MockBaseTools, MockCubeEvaluator, MockSecurityContext};
77
use chrono_tz::Tz;
88
use std::rc::Rc;
99

@@ -20,9 +20,9 @@ impl TestCompiler {
2020

2121
/// Create a new TestCompiler with a specific timezone
2222
pub fn new_with_timezone(evaluator: Rc<MockCubeEvaluator>, timezone: Tz) -> Self {
23-
let sql_utils = Rc::new(MockSqlUtils);
23+
let base_tools = Rc::new(MockBaseTools::default());
2424
let security_context = Rc::new(MockSecurityContext);
25-
let compiler = Compiler::new(evaluator, sql_utils, security_context, timezone);
25+
let compiler = Compiler::new(evaluator, base_tools, security_context, timezone);
2626

2727
Self { compiler }
2828
}

0 commit comments

Comments
 (0)