Skip to content

Commit

Permalink
fix(core) fix count_values query. (#1545)
Browse files Browse the repository at this point in the history
throw exceptions only for histogram type.
---------
Co-authored-by: Yu Zhang <yzhang999272@apple.com>
  • Loading branch information
yu-shipit committed Mar 31, 2023
1 parent f3eabac commit 59ffa04
Showing 1 changed file with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,30 @@ object RowAggregator {
*/
def apply(aggrOp: AggregationOperator, params: Seq[Any], schema: ResultSchema): RowAggregator = {
val valColType = ResultSchema.valueColumnType(schema)
if (valColType == ColumnType.HistogramColumn) {
aggrOp match {
case Sum if isHistMax(valColType, schema) => HistMaxSumAggregator
case Sum => HistSumRowAggregator
case Count => CountRowAggregator.hist
case _ => throw new IllegalArgumentException(s"The ${aggrOp} operation is not supported directly for histogram"
+ s" types. Check if you need to resolve to the individual histogram buckets,"
+ s"or calculate the rate and histogram_quantile before applying the aggregation. "
+ s"If you have a genuine use case for this query, please get in touch.")
}
} else if (valColType == ColumnType.DoubleColumn) {
aggrOp match {
case Min => MinRowAggregator
case Max => MaxRowAggregator
case Sum => SumRowAggregator
case Count => CountRowAggregator.double
case Group => GroupRowAggregator
case Avg => AvgRowAggregator
case TopK => new TopBottomKRowAggregator(params(0).asInstanceOf[Double].toInt, false)
case BottomK => new TopBottomKRowAggregator(params(0).asInstanceOf[Double].toInt, true)
case Quantile => new QuantileRowAggregator(params(0).asInstanceOf[Double])
case Stdvar => StdvarRowAggregator
case Stddev => StddevRowAggregator
case CountValues => new CountValuesRowAggregator(params(0).asInstanceOf[String])
}
} else {
throw new UnsupportedOperationException(s"The ${aggrOp} operation is not supported for ${valColType}");
aggrOp match {
case Min if valColType != ColumnType.HistogramColumn => MinRowAggregator
case Max if valColType != ColumnType.HistogramColumn => MaxRowAggregator
case Sum if valColType == ColumnType.DoubleColumn => SumRowAggregator
case Sum if isHistMax(valColType, schema) => HistMaxSumAggregator
case Sum if valColType == ColumnType.HistogramColumn => HistSumRowAggregator
case Count if valColType == ColumnType.DoubleColumn => CountRowAggregator.double
case Count if valColType == ColumnType.HistogramColumn => CountRowAggregator.hist
case Group if valColType != ColumnType.HistogramColumn => GroupRowAggregator
case Avg if valColType != ColumnType.HistogramColumn => AvgRowAggregator
case TopK => new TopBottomKRowAggregator(params(0).asInstanceOf[Double].toInt, false)
case BottomK => new TopBottomKRowAggregator(params(0).asInstanceOf[Double].toInt, true)
case Quantile => new QuantileRowAggregator(params(0).asInstanceOf[Double])
case Stdvar if valColType != ColumnType.HistogramColumn => StdvarRowAggregator
case Stddev if valColType != ColumnType.HistogramColumn => StddevRowAggregator
case CountValues => new CountValuesRowAggregator(params(0).asInstanceOf[String])
case _ =>
if (valColType == ColumnType.HistogramColumn) {
throw new IllegalArgumentException(s"The ${aggrOp} operation is not supported directly for histogram"
+ s" types. Check if you need to resolve to the individual histogram buckets,"
+ s"or calculate the rate and histogram_quantile before applying the aggregation. "
+ s"If you have a genuine use case for this query, please get in touch.")
}
throw new UnsupportedOperationException(s"The ${aggrOp} operation is not supported for ${valColType}");
}
}
}

0 comments on commit 59ffa04

Please sign in to comment.