Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ For programmatic access, add SoftClient4ES to your project:
resolvers += "Softnetwork" at "https://softnetwork.jfrog.io/artifactory/releases/"

// Choose your Elasticsearch version
libraryDependencies += "app.softnetwork.elastic" %% "softclient4es8-java-client" % "0.17.3"
libraryDependencies += "app.softnetwork.elastic" %% "softclient4es8-java-client" % "0.17.4"
// Add the community extensions for materialized views (optional)
libraryDependencies += "app.softnetwork.elastic" %% "softclient4es-community-extensions" % "0.1.1"
```
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ThisBuild / organization := "app.softnetwork"

name := "softclient4es"

ThisBuild / version := "0.17-SNAPSHOT"
ThisBuild / version := "0.17.4"

ThisBuild / scalaVersion := scala213

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,28 @@ trait ElasticConversion {
val ret = parseAggregations(aggs, ListMap.empty, fieldAliases, aggregations)
val groupedRows: Map[String, Seq[ListMap[String, Any]]] =
ret.groupBy(_.getOrElse("bucket_root", "").toString)
groupedRows.values.foldLeft(Seq(ListMap.empty[String, Any])) { (acc, group) =>
for {
accMap <- acc
groupMap <- group
} yield accMap ++ groupMap
}
groupedRows.values
.foldLeft(Seq(ListMap.empty[String, Any])) { (acc, group) =>
for {
accMap <- acc
groupMap <- group
} yield accMap ++ groupMap
}
.map(_ - "bucket_root")

case (Some(hits), Some(aggs)) if hits.isEmpty =>
// Case 3 : aggregations with no hits
val ret = parseAggregations(aggs, ListMap.empty, fieldAliases, aggregations)
val groupedRows: Map[String, Seq[ListMap[String, Any]]] =
ret.groupBy(_.getOrElse("bucket_root", "").toString)
groupedRows.values.foldLeft(Seq(ListMap.empty[String, Any])) { (acc, group) =>
for {
accMap <- acc
groupMap <- group
} yield accMap ++ groupMap
}
groupedRows.values
.foldLeft(Seq(ListMap.empty[String, Any])) { (acc, group) =>
for {
accMap <- acc
groupMap <- group
} yield accMap ++ groupMap
}
.map(_ - "bucket_root")

case (Some(hits), Some(aggs)) if hits.nonEmpty =>
// Case 4 : Hits + global aggregations + top_hits aggregations
Expand All @@ -204,7 +208,9 @@ trait ElasticConversion {
}

// Normalize all rows at the end, after all transformations (flattening, aggregation merging)
rows.map(row => normalizeRow(row, fields))
// Filter out "*" from fields — it is an artifact of COUNT(*) and not a real column
val effectiveFields = fields.filterNot(_ == "*")
rows.map(row => normalizeRow(row, effectiveFields))
}

def findKeyValue(path: String, map: Map[String, Any]): Option[Any] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,54 @@ class ElasticConversionSpec extends AnyFlatSpec with Matchers with ElasticConver
}
}

it should "parse global aggregation COUNT(*) without GROUP BY" in {
// Simulates: SELECT COUNT(*) FROM ecommerce
// ES response for a global value_count aggregation (no buckets, no GROUP BY)
val results =
"""{
| "took": 3,
| "timed_out": false,
| "hits": { "total": { "value": 20, "relation": "eq" }, "hits": [] },
| "aggregations": {
| "COUNT(*)" : {
| "value": 20
| }
| }
|}""".stripMargin

val aggregations = ListMap(
"COUNT(*)" -> ClientAggregation(
aggName = "COUNT(*)",
aggType = AggregationType.Count,
distinct = false,
sourceField = "*",
windowing = false,
bucketPath = "",
bucketRoot = ""
)
)

// fields as produced by the SQL parser: "*" (artifact) + "COUNT(*)" (actual column)
val fields = Seq("*", "COUNT(*)")

parseResponse(results, ListMap.empty, aggregations, fields) match {
case Success(rows) =>
rows.foreach(println)
rows.size shouldBe 1
val row = rows.head
// Issue #002: bucket_root must not leak into the output
row.keys should not contain "bucket_root"
// Issue #003: "*" must not appear as a column
row.keys should not contain "*"
// Only the aggregation column should be present
row.keys should contain("COUNT(*)")
row("COUNT(*)") shouldBe 20L
row.size shouldBe 1
case Failure(error) =>
throw error
}
}

it should "parse window results with distinct partitions" in {
val results =
"""
Expand Down
Loading