From 0f693b9438edef769bc9a5b1827bdd43c623551c Mon Sep 17 00:00:00 2001 From: To-om Date: Fri, 30 Apr 2021 11:06:00 +0200 Subject: [PATCH] #2001 Fold traversal before aggregate it --- .../org/thp/thehive/services/th3/Aggregation.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/thehive/app/org/thp/thehive/services/th3/Aggregation.scala b/thehive/app/org/thp/thehive/services/th3/Aggregation.scala index 511da78b9d..a560d1aefa 100644 --- a/thehive/app/org/thp/thehive/services/th3/Aggregation.scala +++ b/thehive/app/org/thp/thehive/services/th3/Aggregation.scala @@ -170,10 +170,11 @@ case class AggSum(aggName: Option[String], fieldName: String, filter: Option[Inp .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) filter .fold(traversal)(_(publicProperties, traversalType, traversal, authContext)) + .fold .coalesce( t => property - .select(fieldPath, t, authContext) + .select(fieldPath, t.unfold, authContext) .sum .domainMap(sum => Output(Json.obj(name -> JsNumber(BigDecimal(sum.toString))))) .castDomain[Output[_]], @@ -196,10 +197,11 @@ case class AggAvg(aggName: Option[String], fieldName: String, filter: Option[Inp .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) filter .fold(traversal)(_(publicProperties, traversalType, traversal, authContext)) + .fold .coalesce( t => property - .select(fieldPath, t, authContext) + .select(fieldPath, t.unfold, authContext) .mean .domainMap(avg => Output(Json.obj(name -> avg))) .asInstanceOf[Traversal.Domain[Output[_]]], @@ -222,10 +224,11 @@ case class AggMin(aggName: Option[String], fieldName: String, filter: Option[Inp .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) filter .fold(traversal)(_(publicProperties, traversalType, traversal, authContext)) + .fold .coalesce( t => property - .select(fieldPath, t, authContext) + .select(fieldPath, t.unfold, authContext) .min .domainMap(min => Output(Json.obj(name -> property.toJson(min)))), Output(Json.obj(name -> JsNull)) @@ -247,10 +250,11 @@ case class AggMax(aggName: Option[String], fieldName: String, filter: Option[Inp .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) filter .fold(traversal)(_(publicProperties, traversalType, traversal, authContext)) + .fold .coalesce( t => property - .select(fieldPath, t, authContext) + .select(fieldPath, t.unfold, authContext) .max .domainMap(max => Output(Json.obj(name -> property.toJson(max)))), Output(Json.obj(name -> JsNull))