diff --git a/query-generator/src/lib.rs b/query-generator/src/lib.rs index f67f86bfd5..a4d0603eda 100644 --- a/query-generator/src/lib.rs +++ b/query-generator/src/lib.rs @@ -1070,6 +1070,14 @@ impl AggregateType { AggregateType::Min { column_type } => column_type.clone(), } } + + pub fn is_distinct(&self) -> bool { + match self { + AggregateType::Count { distinct, .. } => *distinct, + AggregateType::Sum { distinct, .. } => *distinct, + _ => false, + } + } } /// Parameters for generating an arbitrary FilterRhs @@ -2243,9 +2251,10 @@ impl Arbitrary for Operations { fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { any_with::>(args) .prop_map(|mut ops| { - // Don't generate an aggregate or distinct in the same query as a WHERE IN clause, + // Don't generate an aggregate with distinct keyword or a plain distinct + // in the same query as a WHERE IN clause, // since we don't support those queries (ENG-2942) - let mut agg_or_distinct_found = false; + let mut distinct_found = false; let mut in_parameter_found = false; // 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 { let mut or_filter_found = false; ops.retain(|op| match op { - QueryOperation::ColumnAggregate(_) | QueryOperation::Distinct => { + QueryOperation::ColumnAggregate(agg) if agg.is_distinct() => { + if in_parameter_found { + false + } else { + distinct_found = true; + true + } + } + QueryOperation::Distinct => { if in_parameter_found { false } else { - agg_or_distinct_found = true; + distinct_found = true; true } } QueryOperation::InParameter { .. } => { - if agg_or_distinct_found || or_filter_found { + if distinct_found | or_filter_found { false } else { in_parameter_found = true;