Skip to content

Commit dd6df54

Browse files
committed
prepare release v9.x
1 parent 04cdf55 commit dd6df54

File tree

7 files changed

+307
-54
lines changed

7 files changed

+307
-54
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ jobs:
3030
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
3131
JVM_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
3232
steps:
33+
- name: Env
34+
run: |
35+
echo "JFROG_USER=${{ secrets.JFROG_USER }}" >> $GITHUB_ENV
36+
echo "JFROG_PASSWORD=${{ secrets.JFROG_PASSWORD }}" >> $GITHUB_ENV
37+
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
38+
echo "CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}" >> $GITHUB_ENV
3339
- name: Checkout
3440
uses: actions/checkout@v3
3541
- name: Set up JDK 17
@@ -43,7 +49,7 @@ jobs:
4349
- name: Set vm.max_map_count
4450
run: sudo sysctl -w vm.max_map_count=262144
4551
- name: Run tests
46-
run: sbt test
52+
run: SBT_OPTS="-Xss4M -Xms1g -Xmx4g -Dfile.encoding=UTF-8" sbt test
4753

4854
lint:
4955
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name: Release
88
on:
99
workflow_dispatch:
1010
push:
11-
branches:
11+
branches:
1212
- 'main'
1313
# - '*' # matches every branch that doesn't contain a '/'
1414
# - '*/*' # matches every branch containing a single '/'
@@ -27,6 +27,12 @@ jobs:
2727
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
2828
JVM_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
2929
steps:
30+
- name: Env
31+
run: |
32+
echo "JFROG_USER=${{ secrets.JFROG_USER }}" >> $GITHUB_ENV
33+
echo "JFROG_PASSWORD=${{ secrets.JFROG_PASSWORD }}" >> $GITHUB_ENV
34+
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
35+
echo "CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}" >> $GITHUB_ENV
3036
- name: Checkout
3137
uses: actions/checkout@v3
3238
- name: Set up JDK 17
@@ -42,7 +48,7 @@ jobs:
4248
- name: Set vm.max_map_count
4349
run: sudo sysctl -w vm.max_map_count=262144
4450
- name: Run tests & Coverage Report
45-
run: sbt coverage test coverageReport coverageAggregate
51+
run: SBT_OPTS="-Xss4M -Xms1g -Xmx4g -Dfile.encoding=UTF-8" sbt coverage test coverageReport coverageAggregate
4652
- name: Upload coverage to Codecov
4753
uses: codecov/codecov-action@v3
4854
with:
@@ -51,4 +57,4 @@ jobs:
5157
fail_ci_if_error: false
5258
verbose: true
5359
- name: Publish
54-
run: sbt publish
60+
run: SBT_OPTS="-Xss4M -Xms1g -Xmx4g -Dfile.encoding=UTF-8" sbt publish

client/src/main/scala/app/softnetwork/elastic/client/AggregateResult.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@ sealed trait MetricAgregateResult extends AggregateResult {
1111
def function: AggregateFunction
1212
}
1313

14+
sealed trait AggregateValue
15+
case class NumericValue(value: Double) extends AggregateValue
16+
case class StringValue(value: String) extends AggregateValue
17+
case object EmptyValue extends AggregateValue
18+
1419
case class SingleValueAggregateResult(
1520
field: String,
1621
function: AggregateFunction,
17-
value: Double,
22+
value: AggregateValue,
1823
error: Option[String] = None
19-
) extends MetricAgregateResult
24+
) extends MetricAgregateResult {
25+
def asDoubleOption: Option[Double] = value match {
26+
case NumericValue(v) => Some(v)
27+
case _ => None
28+
}
29+
def asStringOption: Option[String] = value match {
30+
case StringValue(v) => Some(v)
31+
case _ => None
32+
}
33+
}

java/src/main/scala/app/softnetwork/elastic/client/java/ElasticsearchClientApi.scala

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ trait ElasticsearchClientSettingsApi extends SettingsApi with ElasticsearchClien
124124
}
125125

126126
override def loadSettings(): String = {
127-
apply()
127+
val settings = apply()
128128
.indices()
129129
.getSettings(
130130
new GetIndicesSettingsRequest.Builder().index("*").build()
131131
)
132132
.toString
133+
settings.substring(settings.indexOf(':') + 1).trim
133134
}
134135
}
135136

@@ -144,12 +145,13 @@ trait ElasticsearchClientMappingApi extends MappingApi with ElasticsearchClientC
144145
}
145146

146147
override def getMapping(index: String): String = {
147-
apply()
148+
val mapping = apply()
148149
.indices()
149150
.getMapping(
150151
new GetMappingRequest.Builder().index(index).build()
151152
)
152153
.toString
154+
mapping.substring(mapping.indexOf(':') + 1).trim
153155
}
154156
}
155157

@@ -190,11 +192,26 @@ trait ElasticsearchClientCountApi extends CountApi with ElasticsearchClientCompa
190192
.toDouble
191193
)
192194
}
195+
196+
override def countAsync(query: client.JSONQuery)(implicit
197+
ec: ExecutionContext
198+
): Future[Option[Double]] = {
199+
fromCompletableFuture(
200+
async()
201+
.count(
202+
new CountRequest.Builder().index(query.indices.asJava).build()
203+
)
204+
).map(response => Option(response.count().toDouble))
205+
}
193206
}
194207

195208
trait ElasticsearchClientSingleValueAggregateApi
196209
extends SingleValueAggregateApi
197210
with ElasticsearchClientCountApi {
211+
private[this] def aggregateValue(value: Double, valueAsString: String): AggregateValue =
212+
if (valueAsString.nonEmpty) StringValue(valueAsString)
213+
else NumericValue(value)
214+
198215
override def aggregate(
199216
sqlQuery: SQLQuery
200217
)(implicit ec: ExecutionContext): Future[Seq[SingleValueAggregateResult]] = {
@@ -220,13 +237,15 @@ trait ElasticsearchClientSingleValueAggregateApi
220237
SingleValueAggregateResult(
221238
field,
222239
aggType,
223-
result.getOrElse(0d),
240+
NumericValue(result.getOrElse(0d)),
224241
None
225242
)
226243
)
227244
case Failure(f) =>
228245
logger.error(f.getMessage, f.fillInStackTrace())
229-
promise.success(SingleValueAggregateResult(field, aggType, 0d, Some(f.getMessage)))
246+
promise.success(
247+
SingleValueAggregateResult(field, aggType, EmptyValue, Some(f.getMessage))
248+
)
230249
}
231250
promise.future
232251
case _ =>
@@ -236,6 +255,9 @@ trait ElasticsearchClientSingleValueAggregateApi
236255
collection.immutable.Seq.empty[String]
237256
)
238257
import jsonQuery._
258+
logger.info(
259+
s"Aggregating with query: ${jsonQuery.query} on indices: ${indices.mkString(", ")}"
260+
)
239261
// Create a parser for the query
240262
Try(
241263
apply().search(
@@ -248,6 +270,9 @@ trait ElasticsearchClientSingleValueAggregateApi
248270
)
249271
) match {
250272
case Success(response) =>
273+
logger.whenDebugEnabled(
274+
s"Aggregation response: ${response.toString}"
275+
)
251276
val agg = aggName.split("\\.").last
252277

253278
val itAgg = aggName.split("\\.").iterator
@@ -269,20 +294,25 @@ trait ElasticsearchClientSingleValueAggregateApi
269294
aggType,
270295
aggType match {
271296
case sql.Count =>
272-
if (aggregation.distinct) {
273-
root.get(agg).cardinality().value().toDouble
274-
} else {
275-
root.get(agg).valueCount().value().toDouble
276-
}
297+
NumericValue(
298+
if (aggregation.distinct) {
299+
root.get(agg).cardinality().value()
300+
} else {
301+
root.get(agg).valueCount().value()
302+
}
303+
)
277304
case sql.Sum =>
278-
root.get(agg).sum().value().toDouble
305+
NumericValue(root.get(agg).sum().value())
279306
case sql.Avg =>
280-
root.get(agg).avg().value().toDouble
307+
val avgAgg = root.get(agg).avg()
308+
aggregateValue(avgAgg.value(), avgAgg.valueAsString())
281309
case sql.Min =>
282-
root.get(agg).min().value().toDouble
310+
val minAgg = root.get(agg).min()
311+
aggregateValue(minAgg.value(), minAgg.valueAsString())
283312
case sql.Max =>
284-
root.get(agg).max().value().toDouble
285-
case _ => 0d
313+
val maxAgg = root.get(agg).max()
314+
aggregateValue(maxAgg.value(), maxAgg.valueAsString())
315+
case _ => EmptyValue
286316
},
287317
None
288318
)
@@ -293,7 +323,7 @@ trait ElasticsearchClientSingleValueAggregateApi
293323
SingleValueAggregateResult(
294324
field,
295325
aggType,
296-
0d,
326+
EmptyValue,
297327
Some(exception.getMessage)
298328
)
299329
)

project/plugins.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionSch
44

55
resolvers += "Softnetwork releases" at "https://softnetwork.jfrog.io/artifactory/releases/"
66

7-
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-git" % "0.1.7")
7+
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-git" % "0.2.0")
88

9-
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-info" % "0.1.7")
9+
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-info" % "0.2.0")
1010

11-
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-publish" % "0.1.7")
11+
addSbtPlugin("app.softnetwork.sbt-softnetwork" % "sbt-softnetwork-publish" % "0.2.0")
1212

1313
addDependencyTreePlugin
1414

1515
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
1616

17-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")
17+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.0")

testkit/src/main/scala/app/softnetwork/elastic/scalatest/ElasticTestKit.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.scalatest.matchers.{MatchResult, Matcher}
1515
import org.slf4j.Logger
1616

1717
import scala.concurrent.{ExecutionContext, Future}
18-
import scala.util.{Failure, Success}
18+
import scala.util.{Failure, Success, Try}
1919

2020
/** Created by smanciot on 18/05/2021.
2121
*/
@@ -195,6 +195,25 @@ trait ElasticTestKit extends ElasticDsl with CompletionTestKit with BeforeAndAft
195195
}
196196
}
197197

198+
def isIndexOpened(name: String): Boolean = {
199+
elasticClient
200+
.execute {
201+
indexStats(name)
202+
}
203+
.complete() match {
204+
case Success(s) =>
205+
Try(s.result.indices.contains(name)) match {
206+
case Success(_) => true
207+
case Failure(_) => false
208+
}
209+
case _ => false
210+
}
211+
}
212+
213+
def isIndexClosed(name: String): Boolean = {
214+
doesIndexExists(name) && !isIndexOpened(name)
215+
}
216+
198217
def doesAliasExists(name: String): Boolean = {
199218
elasticClient
200219
.execute {

0 commit comments

Comments
 (0)