Skip to content

Commit

Permalink
test(cubesql): More tests for LIMIT 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Nov 13, 2024
1 parent cad6918 commit 284215b
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions rust/cubesql/cubesql/src/compile/test/test_cube_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,120 @@ async fn cubescan_limit_offset_limit_offset() {
);
}
}

/// Test that LIMIT 0 is pushed to grouped CubeScan
#[tokio::test]
async fn cubescan_limit_zero() {
init_testing_logger();

let query_plan = convert_select_to_query_plan(
// language=PostgreSQL
r#"
SELECT
customer_gender
FROM
KibanaSampleDataEcommerce
GROUP BY
1
LIMIT 0
"#
.to_string(),
DatabaseProtocol::PostgreSQL,
)
.await;

let logical_plan = query_plan.as_logical_plan();
assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec![]),
dimensions: Some(vec!["KibanaSampleDataEcommerce.customer_gender".to_string()]),
segments: Some(vec![]),
order: Some(vec![]),
limit: Some(0),
..Default::default()
}
);
}

/// Test that LIMIT 0 is pushed to ungrouped CubeScan
#[tokio::test]
async fn cubescan_ungrouped_limit_zero() {
init_testing_logger();

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

let logical_plan = query_plan.as_logical_plan();
assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec![]),
dimensions: Some(vec!["KibanaSampleDataEcommerce.customer_gender".to_string()]),
segments: Some(vec![]),
order: Some(vec![]),
limit: Some(0),
ungrouped: Some(true),
..Default::default()
}
);
}

/// Test that LIMIT 0 is pushed to CubeScan for SELECT *
#[tokio::test]
async fn cubescan_star_limit_zero() {
init_testing_logger();

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

let logical_plan = query_plan.as_logical_plan();
assert_eq!(
logical_plan.find_cube_scan().request,
V1LoadRequestQuery {
measures: Some(vec![
"KibanaSampleDataEcommerce.count".to_string(),
"KibanaSampleDataEcommerce.maxPrice".to_string(),
"KibanaSampleDataEcommerce.sumPrice".to_string(),
"KibanaSampleDataEcommerce.minPrice".to_string(),
"KibanaSampleDataEcommerce.avgPrice".to_string(),
"KibanaSampleDataEcommerce.countDistinct".to_string(),
]),
dimensions: Some(vec![
"KibanaSampleDataEcommerce.order_date".to_string(),
"KibanaSampleDataEcommerce.last_mod".to_string(),
"KibanaSampleDataEcommerce.customer_gender".to_string(),
"KibanaSampleDataEcommerce.notes".to_string(),
"KibanaSampleDataEcommerce.taxful_total_price".to_string(),
"KibanaSampleDataEcommerce.has_subscription".to_string(),
]),
segments: Some(vec![]),
order: Some(vec![]),
limit: Some(0),
ungrouped: Some(true),
..Default::default()
}
);
}

0 comments on commit 284215b

Please sign in to comment.