Skip to content

Commit fe9cf7f

Browse files
committed
update README.md
1 parent b9d784e commit fe9cf7f

File tree

3 files changed

+75
-19
lines changed

3 files changed

+75
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,18 +787,18 @@ ThisBuild / resolvers ++= Seq(
787787

788788
// For Elasticsearch 6
789789
// Using Jest client
790-
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es6-jest-client" % 0.13.1
790+
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es6-jest-client" % 0.14.0
791791
// Or using Rest High Level client
792-
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es6-rest-client" % 0.13.1
792+
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es6-rest-client" % 0.14.0
793793

794794
// For Elasticsearch 7
795-
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es7-rest-client" % 0.13.1
795+
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es7-rest-client" % 0.14.0
796796

797797
// For Elasticsearch 8
798-
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es8-java-client" % 0.13.1
798+
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es8-java-client" % 0.14.0
799799

800800
// For Elasticsearch 9
801-
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es9-java-client" % 0.13.1
801+
libraryDependencies += "app.softnetwork.elastic" %% s"softclient4es9-java-client" % 0.14.0
802802
```
803803

804804
### **Quick Example**

es6/bridge/src/test/scala/app/softnetwork/elastic/sql/SQLQuerySpec.scala

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,19 +3738,75 @@ class SQLQuerySpec extends AnyFlatSpec with Matchers {
37383738
}
37393739

37403740
it should "test" in {
3741-
val query =
3741+
/*val query =
37423742
"""SELECT
3743-
| category,
3744-
| SUM(amount) AS totalSales,
3745-
| COUNT(*) AS orderCount,
3746-
| DATE_TRUNC(sales_date, MONTH) as salesMonth
3747-
| FROM orders
3748-
| GROUP BY DATE_TRUNC(sales_date, MONTH), category
3749-
| ORDER BY DATE_TRUNC(sales_date, MONTH) DESC, category ASC""".stripMargin.replaceAll(
3750-
"\n",
3751-
" "
3752-
)
3743+
| category,
3744+
| SUM(amount) AS totalSales,
3745+
| COUNT(*) AS orderCount,
3746+
| DATE_TRUNC(sales_date, MONTH) as salesMonth,
3747+
| YEAR(sales_date) as salesYear
3748+
|FROM orders
3749+
|WHERE sales_date IS NOT NULL AND sales_date BETWEEN '2024-01-01' AND '2024-12-31' AND category IN ('Electronics', 'Books', 'Clothing')
3750+
|GROUP BY YEAR(sales_date), DATE_TRUNC(sales_date, MONTH), category
3751+
|ORDER BY YEAR(sales_date) DESC, DATE_TRUNC(sales_date, MONTH) DESC, category ASC""".stripMargin
3752+
.replaceAll(
3753+
"\n",
3754+
" "
3755+
)
37533756
val select: ElasticSearchRequest = SQLQuery(query)
3754-
println(select.query)
3757+
println(select.query)*/
3758+
val query =
3759+
""" SELECT
3760+
| product_id AS productId,
3761+
| product_name AS productName,
3762+
| DATE_TRUNC( sale_date, MONTH ) AS saleMonth,
3763+
| SUM(amount) AS monthlySales,
3764+
| FIRST_VALUE(amount) OVER (
3765+
| PARTITION BY product_id, DATE_TRUNC( sale_date, MONTH )
3766+
| ORDER BY sale_date ASC
3767+
| ) AS launchMonthSales,
3768+
| LAST_VALUE(amount) OVER (
3769+
| PARTITION BY product_id, DATE_TRUNC( sale_date, MONTH )
3770+
| ORDER BY sale_date ASC
3771+
| ) AS peakMonthSales,
3772+
| ARRAY_AGG(amount) OVER (
3773+
| PARTITION BY product_id
3774+
| ORDER BY sale_date ASC
3775+
| ) AS allMonthlySales
3776+
| FROM sales
3777+
| WHERE sale_date >= '2024-01-01'
3778+
| GROUP BY product_id, product_name, DATE_TRUNC( sale_date, MONTH )
3779+
| ORDER BY product_id, DATE_TRUNC( sale_date, MONTH )
3780+
|""".stripMargin
3781+
SQLQuery(query).request.flatMap(_.left.toOption) match {
3782+
case Some(request) =>
3783+
val aggRequest =
3784+
request
3785+
.copy(
3786+
select = request.select.copy(fields = request.windowFields),
3787+
groupBy = None, //request.groupBy.map(_.copy(buckets = request.windowBuckets)),
3788+
orderBy = None, // Not needed for aggregations
3789+
limit = None // Need all buckets
3790+
)
3791+
.update()
3792+
3793+
val windowRequest: ElasticSearchRequest = aggRequest
3794+
println(windowRequest.query)
3795+
3796+
// Remove window function fields from SELECT
3797+
val baseFields = request.select.fields.filterNot(_.identifier.hasWindow)
3798+
3799+
// Create modified request
3800+
val baseRequest: ElasticSearchRequest = request
3801+
.copy(
3802+
select = request.select.copy(fields = baseFields)
3803+
)
3804+
.update()
3805+
3806+
println(baseRequest.query)
3807+
3808+
case _ =>
3809+
3810+
}
37553811
}
37563812
}

project/SoftClient4es.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ trait SoftClient4es {
153153
case 6 =>
154154
Seq(
155155
"io.searchbox" % "jest" % Versions.jest,
156-
"com.google.guava" % "guava" % "33.5.0-jre",
157-
).map(_.excludeAll((httpComponentsExclusions /*++ Seq(guavaExclusion)*/) *))
156+
"com.google.guava" % "guava" % "33.5.0-jre"
157+
).map(_.excludeAll(httpComponentsExclusions /*++ Seq(guavaExclusion)*/ *))
158158
case _ => Seq.empty
159159
})
160160
}

0 commit comments

Comments
 (0)