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
1 change: 1 addition & 0 deletions packages/cubejs-backend-native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/cubenativeutils/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 8 additions & 13 deletions rust/cubesql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ minijinja = { version = "1", features = ["json", "loader"] }
lru = "0.12.1"
sha2 = "0.10.8"
bigdecimal = "0.4.2"
indexmap = "1.9.3"


[dev-dependencies]
Expand Down
55 changes: 49 additions & 6 deletions rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14369,7 +14369,11 @@ ORDER BY "source"."str0" ASC
.wrapped_sql
.unwrap()
.sql;
assert!(sql.contains("\"limit\":1000"));
if Rewriter::top_down_extractor_enabled() {
assert!(sql.contains("LIMIT 1000"));
} else {
assert!(sql.contains("\"limit\":1000"));
}
assert!(sql.contains("% 7"));

let physical_plan = query_plan.as_physical_plan().await.unwrap();
Expand Down Expand Up @@ -16547,7 +16551,7 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
measure(count) AS cnt,
date_trunc('month', order_date) AS dt
FROM KibanaSampleDataEcommerce
WHERE order_date IN (to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US'))
WHERE date_trunc('month', order_date) IN (to_timestamp('2019-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US'))
GROUP BY 2
;"#
.to_string(),
Expand All @@ -16565,10 +16569,18 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
granularity: Some("month".to_string()),
date_range: Some(json!(vec![
"2019-01-01T00:00:00.000Z".to_string(),
"2019-01-01T00:00:00.000Z".to_string()
]))
date_range: if Rewriter::top_down_extractor_enabled() {
Some(json!(vec![
"2019-01-01T00:00:00.000Z".to_string(),
"2019-01-31T23:59:59.999Z".to_string()
]))
} else {
// Non-optimal variant with top down extractor disabled
Some(json!(vec![
"2019-01-01 00:00:00.000".to_string(),
"2019-01-31 23:59:59.999".to_string()
]))

Check warning on line 16582 in rust/cubesql/cubesql/src/compile/mod.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/mod.rs#L16580-L16582

Added lines #L16580 - L16582 were not covered by tests
}
}]),
order: Some(vec![]),
limit: None,
Expand Down Expand Up @@ -16915,4 +16927,35 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),

Ok(())
}

#[tokio::test]
async fn test_wrapper_limit_zero() {
if !Rewriter::sql_push_down_enabled() {
return;
}
init_testing_logger();

let query_plan = convert_select_to_query_plan(
r#"
SELECT MAX(order_date) FROM KibanaSampleDataEcommerce LIMIT 0
"#
.to_string(),
DatabaseProtocol::PostgreSQL,
)
.await;

let logical_plan = query_plan.as_logical_plan();
let sql = logical_plan
.find_cube_scan_wrapper()
.wrapped_sql
.unwrap()
.sql;
assert!(sql.contains("LIMIT 0"));

let physical_plan = query_plan.as_physical_plan().await.unwrap();
println!(
"Physical plan: {}",
displayable(physical_plan.as_ref()).indent()
);
}
}
8 changes: 7 additions & 1 deletion rust/cubesql/cubesql/src/compile/query_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ pub trait QueryEngine {
let mut rewriter = Rewriter::new(finalized_graph, cube_ctx.clone());

let result = rewriter
.find_best_plan(root, state.auth_context().unwrap(), qtrace, span_id.clone())
.find_best_plan(
root,
state.auth_context().unwrap(),
qtrace,
span_id.clone(),
self.config_ref().top_down_extractor(),
)
.await
.map_err(|e| match e.cause {
CubeErrorCauseType::Internal(_) => CompilationError::Internal(
Expand Down
Loading
Loading