Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cubesql): Segment mixed with a filter and a date range filter may… #7684

Merged
merged 1 commit into from
Jan 24, 2024
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
56 changes: 56 additions & 0 deletions rust/cubesql/cubesql/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3432,6 +3432,62 @@ ORDER BY \"COUNT(count)\" DESC"
);
}

#[tokio::test]
async fn superset_pg_time_filter_with_in_filter() {
init_logger();

let query_plan = convert_select_to_query_plan(
"SELECT \"notes\", DATE_TRUNC('week', \"order_date\") AS __timestamp,
count(count) AS \"COUNT(count)\"
FROM public.\"KibanaSampleDataEcommerce\"
WHERE \"notes\" IN ('1', '2', '3', '4', '5') AND \"is_female\" = true AND \"order_date\" >= TO_TIMESTAMP('2021-05-15 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
AND \"order_date\" < TO_TIMESTAMP('2022-05-15 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
GROUP BY \"notes\", DATE_TRUNC('week', \"order_date\")
ORDER BY \"COUNT(count)\" DESC LIMIT 10000"
.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()]),
segments: Some(vec!["KibanaSampleDataEcommerce.is_female".to_string()]),
dimensions: Some(vec!["KibanaSampleDataEcommerce.notes".to_string()]),
time_dimensions: Some(vec![V1LoadRequestQueryTimeDimension {
dimension: "KibanaSampleDataEcommerce.order_date".to_string(),
granularity: Some("week".to_string()),
date_range: Some(json!(vec![
"2021-05-15T00:00:00.000Z".to_string(),
"2022-05-14T23:59:59.999Z".to_string()
]))
}]),
order: Some(vec![vec![
"KibanaSampleDataEcommerce.count".to_string(),
"desc".to_string()
]]),
limit: Some(10000),
offset: None,
filters: Some(vec![V1LoadRequestQueryFilterItem {
member: Some("KibanaSampleDataEcommerce.notes".to_string()),
operator: Some("equals".to_string()),
values: Some(vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
"4".to_string(),
"5".to_string()
]),
or: None,
and: None
}]),
ungrouped: None,
}
);
}

#[tokio::test]
async fn superset_pg_time_filter_with_generalized_filters() {
init_logger();
Expand Down
13 changes: 10 additions & 3 deletions rust/cubesql/cubesql/src/compile/rewrite/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::{
expr_column_name, AggregateUDFExprFun, AliasExprAlias, AllMembersAlias, AllMembersCube,
ChangeUserCube, ColumnExprColumn, DimensionName, FilterMemberMember, FilterMemberOp,
LiteralExprValue, LiteralMemberRelation, LiteralMemberValue, LogicalPlanLanguage,
MeasureName, ScalarFunctionExprFun, SegmentName, TableScanSourceTableName,
TimeDimensionDateRange, TimeDimensionGranularity, TimeDimensionName, VirtualFieldCube,
VirtualFieldName,
MeasureName, ScalarFunctionExprFun, SegmentMemberMember, SegmentName,
TableScanSourceTableName, TimeDimensionDateRange, TimeDimensionGranularity,
TimeDimensionName, VirtualFieldCube, VirtualFieldName,
},
},
transport::ext::{V1CubeMetaDimensionExt, V1CubeMetaMeasureExt, V1CubeMetaSegmentExt},
Expand Down Expand Up @@ -686,6 +686,13 @@ impl LogicalPlanAnalysis {
.to_string();
Some(vec![(member, op)])
}
LogicalPlanLanguage::SegmentMember(params) => {
let member = var_iter!(egraph[params[0]], SegmentMemberMember)
.next()
.unwrap()
.to_string();
Some(vec![(member, "equals".to_string())])
}
_ => None,
}
}
Expand Down
Loading