Skip to content

Commit

Permalink
#2001 Fold traversal before aggregate it
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 30, 2021
1 parent df2e8a4 commit 0f693b9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions thehive/app/org/thp/thehive/services/th3/Aggregation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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[_]],
Expand All @@ -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[_]]],
Expand All @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit 0f693b9

Please sign in to comment.