Skip to content

Commit bdb4c20

Browse files
authored
chore(tesseract): Join Graph mock (#10143)
1 parent 8a0f841 commit bdb4c20

26 files changed

+1355
-1468
lines changed

rust/cubesqlplanner/Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubesqlplanner/cubesqlplanner/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ lazy_static = "1.4.0"
2222
regex = "1.3.9"
2323
typed-builder = "0.21.2"
2424

25+
[dev-dependencies]
26+
petgraph = "0.6"
27+
2528
[dependencies.neon]
2629
version = "=1"
2730
default-features = false

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
/// This macro generates a helper method that returns an owned StaticData struct.
44
/// The helper is used by the trait's static_data() method which applies Box::leak.
55
///
6-
/// # Usage
7-
/// ```ignore
8-
/// impl_static_data!(
9-
/// MockDimensionDefinition, // The mock type
10-
/// DimensionDefinitionStatic, // The static data type
11-
/// dimension_type, // Fields to include
12-
/// owned_by_cube,
13-
/// multi_stage
14-
/// );
15-
/// ```
16-
///
17-
/// # Generated Code
18-
/// ```ignore
19-
/// impl MockDimensionDefinition {
20-
/// pub fn static_data(&self) -> DimensionDefinitionStatic {
21-
/// DimensionDefinitionStatic {
22-
/// dimension_type: self.dimension_type.clone(),
23-
/// owned_by_cube: self.owned_by_cube.clone(),
24-
/// multi_stage: self.multi_stage.clone(),
25-
/// }
26-
/// }
27-
/// }
286
/// ```
297
#[macro_export]
308
macro_rules! impl_static_data {
@@ -54,24 +32,6 @@ macro_rules! impl_static_data {
5432
/// - The leaked memory is minimal and reclaimed when the test process exits
5533
/// - This approach significantly simplifies test code by avoiding complex lifetime management
5634
///
57-
/// # Usage
58-
/// ```ignore
59-
/// impl DimensionDefinition for MockDimensionDefinition {
60-
/// impl_static_data_method!(DimensionDefinitionStatic);
61-
///
62-
/// fn sql(&self) -> Result<Option<Rc<dyn MemberSql>>, CubeError> {
63-
/// // ... other trait methods
64-
/// }
65-
/// }
66-
/// ```
67-
///
68-
/// # Generated Code
69-
/// ```ignore
70-
/// fn static_data(&self) -> &DimensionDefinitionStatic {
71-
/// // Intentional memory leak - acceptable for test mocks
72-
/// // The Box::leak pattern converts the owned value to a static reference
73-
/// Box::leak(Box::new(Self::static_data(self)))
74-
/// }
7535
/// ```
7636
#[macro_export]
7737
macro_rules! impl_static_data_method {

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

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ use typed_builder::TypedBuilder;
2020
/// security_context_for_rust, and sql_utils_for_rust.
2121
/// Other methods throw todo!() errors.
2222
///
23-
/// # Example
24-
///
25-
/// ```
26-
/// use cubesqlplanner::test_fixtures::cube_bridge::MockBaseTools;
27-
///
28-
/// // Use builder pattern
29-
/// let tools = MockBaseTools::builder().build();
30-
/// let driver_tools = tools.driver_tools(false).unwrap();
31-
/// let sql_templates = tools.sql_templates().unwrap();
32-
///
33-
/// // Or with custom components
34-
/// let custom_driver = MockDriverTools::with_timezone("Europe/London".to_string());
35-
/// let tools = MockBaseTools::builder()
36-
/// .driver_tools(custom_driver)
37-
/// .build();
3823
/// ```
3924
#[derive(Clone, TypedBuilder)]
4025
pub struct MockBaseTools {
@@ -62,27 +47,22 @@ impl BaseTools for MockBaseTools {
6247
self
6348
}
6449

65-
/// Returns driver tools - uses MockDriverTools
6650
fn driver_tools(&self, _external: bool) -> Result<Rc<dyn DriverTools>, CubeError> {
6751
Ok(self.driver_tools.clone())
6852
}
6953

70-
/// Returns SQL templates renderer - uses MockSqlTemplatesRender
7154
fn sql_templates(&self) -> Result<Rc<dyn SqlTemplatesRender>, CubeError> {
7255
Ok(self.sql_templates.clone())
7356
}
7457

75-
/// Returns security context - uses MockSecurityContext
7658
fn security_context_for_rust(&self) -> Result<Rc<dyn SecurityContext>, CubeError> {
7759
Ok(self.security_context.clone())
7860
}
7961

80-
/// Returns SQL utils - uses MockSqlUtils
8162
fn sql_utils_for_rust(&self) -> Result<Rc<dyn SqlUtils>, CubeError> {
8263
Ok(self.sql_utils.clone())
8364
}
8465

85-
/// Generate time series - not implemented in mock
8666
fn generate_time_series(
8767
&self,
8868
_granularity: String,
@@ -91,7 +71,6 @@ impl BaseTools for MockBaseTools {
9171
todo!("generate_time_series not implemented in mock")
9272
}
9373

94-
/// Generate custom time series - not implemented in mock
9574
fn generate_custom_time_series(
9675
&self,
9776
_granularity: String,
@@ -101,22 +80,18 @@ impl BaseTools for MockBaseTools {
10180
todo!("generate_custom_time_series not implemented in mock")
10281
}
10382

104-
/// Get allocated parameters - not implemented in mock
10583
fn get_allocated_params(&self) -> Result<Vec<String>, CubeError> {
10684
todo!("get_allocated_params not implemented in mock")
10785
}
10886

109-
/// Get all cube members - not implemented in mock
11087
fn all_cube_members(&self, _path: String) -> Result<Vec<String>, CubeError> {
11188
todo!("all_cube_members not implemented in mock")
11289
}
11390

114-
/// Get interval and minimal time unit - not implemented in mock
11591
fn interval_and_minimal_time_unit(&self, _interval: String) -> Result<Vec<String>, CubeError> {
11692
todo!("interval_and_minimal_time_unit not implemented in mock")
11793
}
11894

119-
/// Get pre-aggregation by name - not implemented in mock
12095
fn get_pre_aggregation_by_name(
12196
&self,
12297
_cube_name: String,
@@ -125,7 +100,6 @@ impl BaseTools for MockBaseTools {
125100
todo!("get_pre_aggregation_by_name not implemented in mock")
126101
}
127102

128-
/// Get pre-aggregation table name - not implemented in mock
129103
fn pre_aggregation_table_name(
130104
&self,
131105
_cube_name: String,
@@ -134,128 +108,10 @@ impl BaseTools for MockBaseTools {
134108
todo!("pre_aggregation_table_name not implemented in mock")
135109
}
136110

137-
/// Get join tree for hints - not implemented in mock
138111
fn join_tree_for_hints(
139112
&self,
140113
_hints: Vec<JoinHintItem>,
141114
) -> Result<Rc<dyn JoinDefinition>, CubeError> {
142115
todo!("join_tree_for_hints not implemented in mock")
143116
}
144117
}
145-
146-
#[cfg(test)]
147-
mod tests {
148-
use super::*;
149-
150-
#[test]
151-
fn test_builder_default() {
152-
let tools = MockBaseTools::builder().build();
153-
assert!(tools.driver_tools(false).is_ok());
154-
assert!(tools.sql_templates().is_ok());
155-
assert!(tools.security_context_for_rust().is_ok());
156-
assert!(tools.sql_utils_for_rust().is_ok());
157-
}
158-
159-
#[test]
160-
fn test_default_trait() {
161-
let tools = MockBaseTools::default();
162-
assert!(tools.driver_tools(false).is_ok());
163-
assert!(tools.sql_templates().is_ok());
164-
assert!(tools.security_context_for_rust().is_ok());
165-
assert!(tools.sql_utils_for_rust().is_ok());
166-
}
167-
168-
#[test]
169-
fn test_driver_tools() {
170-
let tools = MockBaseTools::builder().build();
171-
let driver_tools = tools.driver_tools(false).unwrap();
172-
173-
// Test that it returns a valid DriverTools implementation
174-
let result = driver_tools
175-
.time_grouped_column("day".to_string(), "created_at".to_string())
176-
.unwrap();
177-
assert_eq!(result, "date_trunc('day', created_at)");
178-
}
179-
180-
#[test]
181-
fn test_driver_tools_external_flag() {
182-
let tools = MockBaseTools::builder().build();
183-
184-
// Both external true and false should work (mock ignores the flag)
185-
assert!(tools.driver_tools(false).is_ok());
186-
assert!(tools.driver_tools(true).is_ok());
187-
}
188-
189-
#[test]
190-
fn test_sql_templates() {
191-
let tools = MockBaseTools::builder().build();
192-
let templates = tools.sql_templates().unwrap();
193-
194-
// Test that it returns a valid SqlTemplatesRender implementation
195-
assert!(templates.contains_template("filters/equals"));
196-
assert!(templates.contains_template("functions/SUM"));
197-
}
198-
199-
#[test]
200-
fn test_security_context() {
201-
let tools = MockBaseTools::builder().build();
202-
// Just verify it returns without error
203-
assert!(tools.security_context_for_rust().is_ok());
204-
}
205-
206-
#[test]
207-
fn test_sql_utils() {
208-
let tools = MockBaseTools::builder().build();
209-
// Just verify it returns without error
210-
assert!(tools.sql_utils_for_rust().is_ok());
211-
}
212-
213-
#[test]
214-
fn test_builder_with_custom_driver_tools() {
215-
let custom_driver = MockDriverTools::with_timezone("Europe/London".to_string());
216-
let tools = MockBaseTools::builder()
217-
.driver_tools(Rc::new(custom_driver))
218-
.build();
219-
220-
let driver_tools = tools.driver_tools(false).unwrap();
221-
let result = driver_tools.convert_tz("timestamp".to_string()).unwrap();
222-
assert_eq!(
223-
result,
224-
"(timestamp::timestamptz AT TIME ZONE 'Europe/London')"
225-
);
226-
}
227-
228-
#[test]
229-
fn test_builder_with_custom_sql_templates() {
230-
let mut custom_templates = std::collections::HashMap::new();
231-
custom_templates.insert("test/template".to_string(), "TEST {{value}}".to_string());
232-
let sql_templates = MockSqlTemplatesRender::try_new(custom_templates).unwrap();
233-
234-
let tools = MockBaseTools::builder()
235-
.sql_templates(Rc::new(sql_templates))
236-
.build();
237-
238-
let templates = tools.sql_templates().unwrap();
239-
assert!(templates.contains_template("test/template"));
240-
}
241-
242-
#[test]
243-
fn test_builder_with_all_custom_components() {
244-
let driver_tools = MockDriverTools::with_timezone("Asia/Tokyo".to_string());
245-
let sql_templates = MockSqlTemplatesRender::default_templates();
246-
let security_context = MockSecurityContext;
247-
let sql_utils = MockSqlUtils;
248-
249-
let tools = MockBaseTools::builder()
250-
.driver_tools(Rc::new(driver_tools))
251-
.sql_templates(Rc::new(sql_templates))
252-
.security_context(Rc::new(security_context))
253-
.sql_utils(Rc::new(sql_utils))
254-
.build();
255-
256-
assert!(tools.driver_tools(false).is_ok());
257-
assert!(tools.sql_templates().is_ok());
258-
assert!(tools.security_context_for_rust().is_ok());
259-
assert!(tools.sql_utils_for_rust().is_ok());
260-
}
261-
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::any::Any;
77
use std::rc::Rc;
88
use typed_builder::TypedBuilder;
99

10-
/// Mock implementation of CaseDefinition for testing
1110
#[derive(TypedBuilder)]
1211
pub struct MockCaseDefinition {
1312
when: Vec<Rc<MockCaseItem>>,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::any::Any;
55
use std::rc::Rc;
66
use typed_builder::TypedBuilder;
77

8-
/// Mock implementation of CaseElseItem for testing
98
#[derive(Debug, Clone, TypedBuilder)]
109
pub struct MockCaseElseItem {
1110
label: StringOrSql,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::any::Any;
77
use std::rc::Rc;
88
use typed_builder::TypedBuilder;
99

10-
/// Mock implementation of CaseItem for testing
1110
#[derive(Debug, Clone, TypedBuilder)]
1211
pub struct MockCaseItem {
1312
sql: String,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::any::Any;
1010
use std::rc::Rc;
1111
use typed_builder::TypedBuilder;
1212

13-
/// Mock implementation of CaseSwitchDefinition for testing
1413
#[derive(TypedBuilder)]
1514
pub struct MockCaseSwitchDefinition {
1615
switch: String,

0 commit comments

Comments
 (0)