Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::driver_tools::{DriverTools, NativeDriverTools};
use super::join_definition::{JoinDefinition, NativeJoinDefinition};
use super::pre_aggregation_obj::{NativePreAggregationObj, PreAggregationObj};
use super::security_context::{NativeSecurityContext, SecurityContext};
use super::sql_templates_render::{NativeSqlTemplatesRender, SqlTemplatesRender};
use super::sql_utils::{NativeSqlUtils, SqlUtils};
use crate::cube_bridge::join_hints::JoinHintItem;
Expand All @@ -18,7 +17,6 @@ use std::rc::Rc;
pub trait BaseTools {
fn driver_tools(&self, external: bool) -> Result<Rc<dyn DriverTools>, CubeError>;
fn sql_templates(&self) -> Result<Rc<dyn SqlTemplatesRender>, CubeError>;
fn security_context_for_rust(&self) -> Result<Rc<dyn SecurityContext>, CubeError>;
fn sql_utils_for_rust(&self) -> Result<Rc<dyn SqlUtils>, CubeError>;
fn generate_time_series(
&self,
Expand Down
10 changes: 5 additions & 5 deletions rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/member_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
security_context::{NativeSecurityContext, SecurityContext},
sql_utils::NativeSqlUtils,
};
use crate::cube_bridge::sql_utils::SqlUtils;
use crate::cube_bridge::base_tools::BaseTools;
use crate::planner::sql_evaluator::SqlCallArg;
use crate::utils::UniqueVector;
use cubenativeutils::wrappers::object::{NativeFunction, NativeStruct, NativeType};
Expand Down Expand Up @@ -301,7 +301,7 @@ pub trait MemberSql {
fn as_any(self: Rc<Self>) -> Rc<dyn Any>;
fn compile_template_sql(
&self,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError>;
}
Expand Down Expand Up @@ -634,7 +634,7 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {

fn compile_template_sql(
&self,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError> {
let state = ProxyState::new();
Expand Down Expand Up @@ -667,8 +667,8 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
context_obj,
)?
} else if arg == "SQL_UTILS" {
sql_utils
.clone()
base_tools
.sql_utils_for_rust()?
.as_any()
.downcast::<NativeSqlUtils<IT>>()
.unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl QueryTools {
};
let evaluator_compiler = Rc::new(RefCell::new(Compiler::new(
cube_evaluator.clone(),
base_tools.sql_utils_for_rust()?,
base_tools.clone(),
security_context.clone(),
timezone.clone(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use super::{
CubeNameSymbolFactory, CubeTableSymbolFactory, DimensionSymbolFactory, MeasureSymbolFactory,
SqlCall, SymbolFactory, TraversalVisitor,
};
use crate::cube_bridge::base_tools::BaseTools;
use crate::cube_bridge::evaluator::CubeEvaluator;
use crate::cube_bridge::join_hints::JoinHintItem;
use crate::cube_bridge::member_sql::MemberSql;
use crate::cube_bridge::security_context::SecurityContext;
use crate::cube_bridge::sql_utils::SqlUtils;
use crate::planner::sql_evaluator::sql_call_builder::SqlCallBuilder;
use chrono_tz::Tz;
use cubenativeutils::CubeError;
use std::collections::HashMap;
use std::rc::Rc;
pub struct Compiler {
cube_evaluator: Rc<dyn CubeEvaluator>,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
timezone: Tz,
/* (type, name) */
Expand All @@ -26,14 +26,14 @@ pub struct Compiler {
impl Compiler {
pub fn new(
cube_evaluator: Rc<dyn CubeEvaluator>,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
timezone: Tz,
) -> Self {
Self {
cube_evaluator,
security_context,
sql_utils,
base_tools,
timezone,
members: HashMap::new(),
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Compiler {
let call_builder = SqlCallBuilder::new(
self,
self.cube_evaluator.clone(),
self.sql_utils.clone(),
self.base_tools.clone(),
self.security_context.clone(),
);
let sql_call = call_builder.build(&cube_name, member_sql.clone())?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::symbols::MemberSymbol;
use super::Compiler;
use super::{SqlCall, SqlCallDependency, SqlCallFilterGroupItem, SqlCallFilterParamsItem};
use crate::cube_bridge::base_tools::BaseTools;
use crate::cube_bridge::evaluator::CubeEvaluator;
use crate::cube_bridge::member_sql::*;
use crate::cube_bridge::security_context::SecurityContext;
use crate::cube_bridge::sql_utils::SqlUtils;
use crate::planner::sql_evaluator::TimeDimensionSymbol;
use crate::planner::GranularityHelper;
use cubenativeutils::CubeError;
Expand All @@ -13,21 +13,21 @@ use std::rc::Rc;
pub struct SqlCallBuilder<'a> {
compiler: &'a mut Compiler,
cube_evaluator: Rc<dyn CubeEvaluator>,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
}

impl<'a> SqlCallBuilder<'a> {
pub fn new(
compiler: &'a mut Compiler,
cube_evaluator: Rc<dyn CubeEvaluator>,
sql_utils: Rc<dyn SqlUtils>,
base_tools: Rc<dyn BaseTools>,
security_context: Rc<dyn SecurityContext>,
) -> Self {
Self {
compiler,
cube_evaluator,
sql_utils,
base_tools,
security_context,
}
}
Expand All @@ -38,7 +38,7 @@ impl<'a> SqlCallBuilder<'a> {
member_sql: Rc<dyn MemberSql>,
) -> Result<SqlCall, CubeError> {
let (template, template_args) = member_sql
.compile_template_sql(self.sql_utils.clone(), self.security_context.clone())?;
.compile_template_sql(self.base_tools.clone(), self.security_context.clone())?;

let deps = template_args
.symbol_paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ use crate::cube_bridge::driver_tools::DriverTools;
use crate::cube_bridge::join_definition::JoinDefinition;
use crate::cube_bridge::join_hints::JoinHintItem;
use crate::cube_bridge::pre_aggregation_obj::PreAggregationObj;
use crate::cube_bridge::security_context::SecurityContext;
use crate::cube_bridge::sql_templates_render::SqlTemplatesRender;
use crate::cube_bridge::sql_utils::SqlUtils;
use crate::test_fixtures::cube_bridge::{
MockDriverTools, MockSecurityContext, MockSqlTemplatesRender, MockSqlUtils,
};
use crate::test_fixtures::cube_bridge::{MockDriverTools, MockSqlTemplatesRender, MockSqlUtils};
use cubenativeutils::CubeError;
use std::any::Any;
use std::rc::Rc;
Expand All @@ -29,9 +26,6 @@ pub struct MockBaseTools {
#[builder(default = Rc::new(MockSqlTemplatesRender::default_templates()))]
sql_templates: Rc<MockSqlTemplatesRender>,

#[builder(default = Rc::new(MockSecurityContext))]
security_context: Rc<MockSecurityContext>,

#[builder(default = Rc::new(MockSqlUtils))]
sql_utils: Rc<MockSqlUtils>,
}
Expand All @@ -55,10 +49,6 @@ impl BaseTools for MockBaseTools {
Ok(self.sql_templates.clone())
}

fn security_context_for_rust(&self) -> Result<Rc<dyn SecurityContext>, CubeError> {
Ok(self.security_context.clone())
}

fn sql_utils_for_rust(&self) -> Result<Rc<dyn SqlUtils>, CubeError> {
Ok(self.sql_utils.clone())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cube_bridge::base_tools::BaseTools;
use crate::cube_bridge::member_sql::{MemberSql, SqlTemplate, SqlTemplateArgs};
use crate::cube_bridge::security_context::SecurityContext;
use crate::cube_bridge::sql_utils::SqlUtils;
use cubenativeutils::CubeError;
use std::any::Any;
use std::rc::Rc;
Expand Down Expand Up @@ -112,7 +112,7 @@ impl MemberSql for MockMemberSql {

fn compile_template_sql(
&self,
_sql_utils: Rc<dyn SqlUtils>,
_base_tools: Rc<dyn BaseTools>,
_security_context: Rc<dyn SecurityContext>,
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError> {
Ok((
Expand Down Expand Up @@ -240,7 +240,7 @@ mod tests {
let mock = Rc::new(MockMemberSql::new("{CUBE.field} / {other.field}").unwrap());
let (template, args) = mock
.compile_template_sql(
Rc::new(crate::test_fixtures::cube_bridge::MockSqlUtils),
Rc::new(crate::test_fixtures::cube_bridge::MockBaseTools::default()),
Rc::new(crate::test_fixtures::cube_bridge::MockSecurityContext),
)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ mod tests {
use crate::cube_bridge::join_item_definition::JoinItemDefinition;
use crate::cube_bridge::measure_definition::MeasureDefinition;
use crate::cube_bridge::segment_definition::SegmentDefinition;
use crate::test_fixtures::cube_bridge::MockBaseTools;

#[test]
fn test_basic_schema() {
Expand Down Expand Up @@ -1043,7 +1044,7 @@ mod tests {

#[test]
fn test_view_with_multiple_long_join_paths() {
use crate::test_fixtures::cube_bridge::{MockSecurityContext, MockSqlUtils};
use crate::test_fixtures::cube_bridge::MockSecurityContext;
use std::rc::Rc;

let schema = MockSchemaBuilder::new()
Expand Down Expand Up @@ -1103,7 +1104,10 @@ mod tests {

// Compile template and check symbol_paths structure
let (_template, args) = checkin_id_sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();

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

let (_template, args) = checkin_count_sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();

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

let (_template, args) = id_sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();

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

let (_template, args) = count_sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();

assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ impl SegmentDefinition for MockSegmentDefinition {

#[cfg(test)]
mod tests {
use crate::test_fixtures::cube_bridge::MockBaseTools;

use super::*;

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

use crate::test_fixtures::cube_bridge::{MockSecurityContext, MockSqlUtils};
use crate::test_fixtures::cube_bridge::MockSecurityContext;
let (template, args) = sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();

match template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod visitors_schema;
pub use visitors_schema::create_visitors_schema;

use crate::planner::sql_evaluator::Compiler;
use crate::test_fixtures::cube_bridge::{MockCubeEvaluator, MockSecurityContext, MockSqlUtils};
use crate::test_fixtures::cube_bridge::{MockBaseTools, MockCubeEvaluator, MockSecurityContext};
use chrono_tz::Tz;
use std::rc::Rc;

Expand All @@ -20,9 +20,9 @@ impl TestCompiler {

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

Self { compiler }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ mod tests {
use super::*;
use crate::cube_bridge::dimension_definition::DimensionDefinition;
use crate::cube_bridge::segment_definition::SegmentDefinition;
use crate::test_fixtures::cube_bridge::MockBaseTools;

#[test]
fn test_schema_has_both_cubes() {
Expand All @@ -205,7 +206,7 @@ mod tests {

#[test]
fn test_visitors_dimensions() {
use crate::test_fixtures::cube_bridge::{MockSecurityContext, MockSqlUtils};
use crate::test_fixtures::cube_bridge::MockSecurityContext;
use std::rc::Rc;

let schema = create_visitors_schema();
Expand Down Expand Up @@ -240,7 +241,10 @@ mod tests {
let sql = question_mark.sql().unwrap().unwrap();
// Verify SQL contains question marks
let (template, _args) = sql
.compile_template_sql(Rc::new(MockSqlUtils), Rc::new(MockSecurityContext))
.compile_template_sql(
Rc::new(MockBaseTools::default()),
Rc::new(MockSecurityContext),
)
.unwrap();
match template {
crate::cube_bridge::member_sql::SqlTemplate::String(s) => {
Expand Down
Loading