Skip to content

Commit c4b8e05

Browse files
committed
refactor modules testkit and bridge
1 parent 9683f1d commit c4b8e05

File tree

47 files changed

+1326
-1012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1326
-1012
lines changed

.gitignore

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ target
88
.bsp
99
.bloop
1010
actions-runner
11-
target-es*
12-
es6/core/testkit
13-
es7/core/testkit
14-
es8/core/testkit
15-
es9/core/testkit
16-
es6/sql/bridge
17-
es7/sql/bridge
18-
es8/sql/bridge
19-
es9/sql/bridge
11+
bridge/target*
12+
es6/testkit
13+
es7/bridge
14+
es7/testkit
15+
es8/bridge
16+
es8/testkit
17+
es9/bridge
18+
es9/testkit
19+
testkit/target*
20+
*.sc
File renamed without changes.

sql/bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticAggregation.scala renamed to bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticAggregation.scala

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package app.softnetwork.elastic.sql.bridge
218

319
import app.softnetwork.elastic.sql.PainlessContext
420
import app.softnetwork.elastic.sql.query.{
521
Asc,
622
Bucket,
723
BucketIncludesExcludes,
8-
MetricSelectorScript,
9-
Field,
1024
Criteria,
1125
Desc,
26+
Field,
27+
MetricSelectorScript,
1228
NestedElement,
1329
NestedElements,
1430
SortOrder
@@ -33,7 +49,7 @@ import com.sksamuel.elastic4s.requests.searches.aggs.{
3349
FilterAggregation,
3450
NestedAggregation,
3551
TermsAggregation,
36-
TermsOrder,
52+
TermsOrder
3753
}
3854
import com.sksamuel.elastic4s.requests.searches.sort.FieldSort
3955

@@ -51,16 +67,17 @@ case class ElasticAggregation(
5167
aggType: AggregateFunction,
5268
agg: Aggregation,
5369
direction: Option[SortOrder] = None,
54-
nestedElement: Option[NestedElement] = None) {
70+
nestedElement: Option[NestedElement] = None
71+
) {
5572
val nested: Boolean = nestedElement.nonEmpty
5673
val filtered: Boolean = filteredAgg.nonEmpty
5774
}
5875

5976
object ElasticAggregation {
6077
def apply(
61-
sqlAgg: Field,
62-
having: Option[Criteria],
63-
bucketsDirection: Map[String, SortOrder]
78+
sqlAgg: Field,
79+
having: Option[Criteria],
80+
bucketsDirection: Map[String, SortOrder]
6481
): ElasticAggregation = {
6582
import sqlAgg._
6683
val sourceField = identifier.path
@@ -142,11 +159,13 @@ object ElasticAggregation {
142159
.map(_.sourceField)
143160
.toArray,
144161
Array.empty
145-
).copy(
146-
scripts = th.fields.filter(_.isScriptField).map(f =>
147-
f.sourceField -> Script(f.painless(None)).lang("painless")
148-
).toMap
149-
)
162+
)
163+
.copy(
164+
scripts = th.fields
165+
.filter(_.isScriptField)
166+
.map(f => f.sourceField -> Script(f.painless(None)).lang("painless"))
167+
.toMap
168+
)
150169
.size(limit) sortBy th.orderBy.sorts.map(sort =>
151170
sort.order match {
152171
case Some(Desc) =>
@@ -231,11 +250,11 @@ object ElasticAggregation {
231250
}
232251

233252
def buildBuckets(
234-
buckets: Seq[Bucket],
235-
bucketsDirection: Map[String, SortOrder],
236-
aggregations: Seq[Aggregation],
237-
aggregationsDirection: Map[String, SortOrder],
238-
having: Option[Criteria]
253+
buckets: Seq[Bucket],
254+
bucketsDirection: Map[String, SortOrder],
255+
aggregations: Seq[Aggregation],
256+
aggregationsDirection: Map[String, SortOrder],
257+
having: Option[Criteria]
239258
): Option[TermsAggregation] = {
240259
buckets.reverse.foldLeft(Option.empty[TermsAggregation]) { (current, bucket) =>
241260
var agg = {

sql/bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticBridge.scala renamed to bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticBridge.scala

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package app.softnetwork.elastic.sql.bridge
218

319
import app.softnetwork.elastic.sql.operator.AND
@@ -6,7 +22,6 @@ import app.softnetwork.elastic.sql.query.{
622
ElasticBoolQuery,
723
ElasticChild,
824
ElasticFilter,
9-
MatchCriteria,
1025
ElasticNested,
1126
ElasticParent,
1227
GenericExpression,
@@ -15,6 +30,7 @@ import app.softnetwork.elastic.sql.query.{
1530
IsNotNullExpr,
1631
IsNullCriteria,
1732
IsNullExpr,
33+
MatchCriteria,
1834
NestedElement,
1935
NestedElements,
2036
Predicate
@@ -64,7 +80,7 @@ case class ElasticBridge(filter: ElasticFilter) {
6480
inner = inner.fetchSource(
6581
FetchSourceContext(
6682
fetchSource = true,
67-
includes = n.sources.map {source =>
83+
includes = n.sources.map { source =>
6884
(n.path.split('.').toSeq ++ Seq(source)).mkString(".")
6985
}.toArray
7086
)
@@ -151,15 +167,15 @@ case class ElasticBridge(filter: ElasticFilter) {
151167
criteria.asQuery(group = group, innerHitsNames = innerHitsNames),
152168
score = false
153169
)
154-
case expression: GenericExpression => expression
155-
case isNull: IsNullExpr => isNull
156-
case isNotNull: IsNotNullExpr => isNotNull
157-
case in: InExpr[_, _] => in
158-
case between: BetweenExpr => between
170+
case expression: GenericExpression => expression
171+
case isNull: IsNullExpr => isNull
172+
case isNotNull: IsNotNullExpr => isNotNull
173+
case in: InExpr[_, _] => in
174+
case between: BetweenExpr => between
159175
// case geoDistance: DistanceCriteria => geoDistance
160-
case matchExpression: MatchCriteria => matchExpression
161-
case isNull: IsNullCriteria => isNull
162-
case isNotNull: IsNotNullCriteria => isNotNull
176+
case matchExpression: MatchCriteria => matchExpression
177+
case isNull: IsNullCriteria => isNull
178+
case isNotNull: IsNotNullCriteria => isNotNull
163179
case other =>
164180
throw new IllegalArgumentException(s"Unsupported filter type: ${other.getClass.getName}")
165181
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package app.softnetwork.elastic.sql.bridge
18+
19+
import app.softnetwork.elastic.sql.query.Criteria
20+
import com.sksamuel.elastic4s.requests.searches.queries.Query
21+
22+
case class ElasticCriteria(criteria: Criteria) {
23+
24+
def asQuery(group: Boolean = true, innerHitsNames: Set[String] = Set.empty): Query = {
25+
val query = criteria.boolQuery.copy(group = group)
26+
query
27+
.filter(criteria.asFilter(Option(query)))
28+
.unfilteredMatchCriteria()
29+
.query(innerHitsNames, Option(query))
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package app.softnetwork.elastic.sql.bridge
18+
19+
import com.sksamuel.elastic4s.requests.searches.{MultiSearchBuilderFn, MultiSearchRequest}
20+
21+
case class ElasticMultiSearchRequest(
22+
requests: Seq[ElasticSearchRequest],
23+
multiSearch: MultiSearchRequest
24+
) {
25+
def query: String = MultiSearchBuilderFn(multiSearch).replace("\"version\":true,", "") /*FIXME*/
26+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package app.softnetwork.elastic.sql.bridge
18+
19+
import app.softnetwork.elastic.sql.query.{Bucket, Criteria, Except, Field}
20+
import com.sksamuel.elastic4s.requests.searches.{SearchBodyBuilderFn, SearchRequest}
21+
22+
case class ElasticSearchRequest(
23+
fields: Seq[Field],
24+
except: Option[Except],
25+
sources: Seq[String],
26+
criteria: Option[Criteria],
27+
limit: Option[Int],
28+
offset: Option[Int],
29+
search: SearchRequest,
30+
buckets: Seq[Bucket] = Seq.empty,
31+
aggregations: Seq[ElasticAggregation] = Seq.empty
32+
) {
33+
def minScore(score: Option[Double]): ElasticSearchRequest = {
34+
score match {
35+
case Some(s) => this.copy(search = search minScore s)
36+
case _ => this
37+
}
38+
}
39+
40+
def query: String =
41+
SearchBodyBuilderFn(search).string.replace("\"version\":true,", "") /*FIXME*/
42+
}

sql/bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/package.scala renamed to bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/package.scala

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025 SOFTNETWORK
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package app.softnetwork.elastic.sql
218

319
import app.softnetwork.elastic.sql.`type`.{SQLBigInt, SQLDouble, SQLTemporal, SQLVarchar}
@@ -11,7 +27,11 @@ import com.sksamuel.elastic4s.ElasticApi._
1127
import com.sksamuel.elastic4s.requests.common.FetchSourceContext
1228
import com.sksamuel.elastic4s.requests.script.Script
1329
import com.sksamuel.elastic4s.requests.script.ScriptType.Source
14-
import com.sksamuel.elastic4s.requests.searches.aggs.{Aggregation, FilterAggregation, NestedAggregation}
30+
import com.sksamuel.elastic4s.requests.searches.aggs.{
31+
Aggregation,
32+
FilterAggregation,
33+
NestedAggregation
34+
}
1535
import com.sksamuel.elastic4s.requests.searches.queries.{InnerHit, Query}
1636
import com.sksamuel.elastic4s.requests.searches.sort.FieldSort
1737
import com.sksamuel.elastic4s.requests.searches.{
@@ -378,8 +398,8 @@ package object bridge {
378398
}
379399

380400
implicit def requestToMultiSearchRequest(
381-
request: SQLMultiSearchRequest
382-
): MultiSearchRequest = {
401+
request: SQLMultiSearchRequest
402+
): MultiSearchRequest = {
383403
MultiSearchRequest(
384404
request.requests.map(implicitly[SearchRequest](_))
385405
)
@@ -848,7 +868,7 @@ package object bridge {
848868
ElasticApi.search("") query {
849869
queryFiltered
850870
}
851-
aggregations {
871+
aggregations {
852872
val filtered =
853873
filteredAgg match {
854874
case Some(filtered) => filtered.subAggregations(aggregation.agg)
@@ -859,7 +879,7 @@ package object bridge {
859879
case _ => filtered
860880
}
861881
}
862-
size 0
882+
size 0
863883
)
864884
}).string.replace("\"version\":true,", "") /*FIXME*/
865885
)

sql/bridge/src/test/scala/app/softnetwork/elastic/sql/SQLCriteriaSpec.scala renamed to bridge/src/test/scala/app/softnetwork/elastic/sql/SQLCriteriaSpec.scala

File renamed without changes.

0 commit comments

Comments
 (0)