Skip to content

Commit 840348d

Browse files
committed
query-generator: Allow where in + aggregates
Lifts most of the restriction of `ff819dc0d9cede2af458e17a30830f2a1e843821`, which prevented WHERE IN and aggregates from being generated for the same query. After `8c9bc345a6a42f071bf1b621047f840eb9b31379`, we can generate most aggregations alongside `IN` clauses, but we still need to disallow `DISTINCT`, either as a plain modifier on a column or as a modifier on certain aggregation function (`sum`, `count`). Change-Id: I76ac3573d864e39a8d3b91a6155fc32914332dce Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7479 Tested-by: Buildkite CI Reviewed-by: Ethan Donowitz <[email protected]>
1 parent 6a8a03b commit 840348d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

query-generator/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,14 @@ impl AggregateType {
10701070
AggregateType::Min { column_type } => column_type.clone(),
10711071
}
10721072
}
1073+
1074+
pub fn is_distinct(&self) -> bool {
1075+
match self {
1076+
AggregateType::Count { distinct, .. } => *distinct,
1077+
AggregateType::Sum { distinct, .. } => *distinct,
1078+
_ => false,
1079+
}
1080+
}
10731081
}
10741082

10751083
/// Parameters for generating an arbitrary FilterRhs
@@ -2243,9 +2251,10 @@ impl Arbitrary for Operations {
22432251
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
22442252
any_with::<Vec<QueryOperation>>(args)
22452253
.prop_map(|mut ops| {
2246-
// Don't generate an aggregate or distinct in the same query as a WHERE IN clause,
2254+
// Don't generate an aggregate with distinct keyword or a plain distinct
2255+
// in the same query as a WHERE IN clause,
22472256
// since we don't support those queries (ENG-2942)
2248-
let mut agg_or_distinct_found = false;
2257+
let mut distinct_found = false;
22492258
let mut in_parameter_found = false;
22502259

22512260
// Don't generate an OR filter in the same query as a parameter of any kind, since
@@ -2254,16 +2263,24 @@ impl Arbitrary for Operations {
22542263
let mut or_filter_found = false;
22552264

22562265
ops.retain(|op| match op {
2257-
QueryOperation::ColumnAggregate(_) | QueryOperation::Distinct => {
2266+
QueryOperation::ColumnAggregate(agg) if agg.is_distinct() => {
2267+
if in_parameter_found {
2268+
false
2269+
} else {
2270+
distinct_found = true;
2271+
true
2272+
}
2273+
}
2274+
QueryOperation::Distinct => {
22582275
if in_parameter_found {
22592276
false
22602277
} else {
2261-
agg_or_distinct_found = true;
2278+
distinct_found = true;
22622279
true
22632280
}
22642281
}
22652282
QueryOperation::InParameter { .. } => {
2266-
if agg_or_distinct_found || or_filter_found {
2283+
if distinct_found | or_filter_found {
22672284
false
22682285
} else {
22692286
in_parameter_found = true;

0 commit comments

Comments
 (0)