Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7d10e7c
major refactoring adding new packages
fupelaqu Sep 20, 2025
ded5100
add package query
fupelaqu Sep 21, 2025
c40d69e
move validation to parser package
fupelaqu Sep 21, 2025
d9d71de
add identifier object
fupelaqu Sep 21, 2025
c691b9e
rename parsers
fupelaqu Sep 22, 2025
2269cca
updates related to identifier
fupelaqu Sep 22, 2025
dc41be8
finalize updates related to identifier
fupelaqu Sep 22, 2025
3010f9c
add parser packages
fupelaqu Sep 22, 2025
880412a
update Tokens regex
fupelaqu Sep 23, 2025
d3c98f4
fix boolean regex
fupelaqu Sep 23, 2025
33e3d3d
add time field, fix extractors
fupelaqu Sep 23, 2025
540da9f
update regex for aliases
fupelaqu Sep 23, 2025
b5c075d
update object class names, add support for RLIKE
fupelaqu Sep 23, 2025
d6ca17a
update SQL queries to test
fupelaqu Sep 23, 2025
f29663c
init top hits aggregation
fupelaqu Sep 23, 2025
5984945
generate top hits aggregation
fupelaqu Sep 24, 2025
c87aef6
add support for group by with field index
fupelaqu Sep 24, 2025
5418167
update specifications for queries
fupelaqu Sep 24, 2025
dca9e30
add support for last day function, update extract function
fupelaqu Sep 25, 2025
af2cbb1
add support for today, quarter and week functions, simplify parsing
fupelaqu Sep 25, 2025
071bcc7
add specifications for today, quarter and week functions
fupelaqu Sep 25, 2025
3850ba1
fix criteria specifications
fupelaqu Sep 25, 2025
78ec296
fix criteria specifications for es 7+
fupelaqu Sep 25, 2025
fceb085
add support for ARRAY_AGG aggregation
fupelaqu Sep 25, 2025
07b893f
add support for CONVERT, TRY_CAST / SAFE_CAST functions and cast oper…
fupelaqu Sep 26, 2025
16fe45a
add support for OFFSET with LIMIT
fupelaqu Sep 26, 2025
ac9cfb3
fix baseTypes and TimeFieldExtract
fupelaqu Sep 27, 2025
b338e0f
add support for geo distance as script field
fupelaqu Sep 27, 2025
d76065e
add support for geo distance as script query
fupelaqu Sep 28, 2025
8f90063
add support for geo distance with between operator
fupelaqu Sep 29, 2025
00cac37
fix validation error message for expression, update validation for be…
fupelaqu Sep 29, 2025
8bca4a1
add haversine support for distance with 2 geo points
fupelaqu Sep 29, 2025
2210ffe
move haversine to Distance companion object
fupelaqu Sep 29, 2025
0636e34
init sql engine documentation
fupelaqu Sep 29, 2025
b057505
fix link to Query structure
fupelaqu Sep 29, 2025
a8d2cff
update sql engine documentation, update window functions parsing in o…
fupelaqu Sep 29, 2025
012070c
to fix lint failures + rename Length to LengthOp and SQLLength to Length
fupelaqu Sep 29, 2025
8d83cfc
add support for LTRIM and RTRIM string functions
fupelaqu Sep 29, 2025
6592285
add support for LEFT, RIGHT, REPLACE, REVERSE, POSITION and REGEXP_LI…
fupelaqu Sep 30, 2025
7cc4dc4
update RIGHT and REGEXP_LIKE string functions
fupelaqu Sep 30, 2025
fb9c0b1
add link to SQL engine documentation
fupelaqu Sep 30, 2025
4f22fa7
update keywords
fupelaqu Sep 30, 2025
0f88cc0
update documentation
fupelaqu Sep 30, 2025
fd596d4
update date time patterns to use MySQL-style
fupelaqu Sep 30, 2025
072c619
add date time MySQL-style patterns to convert
fupelaqu Sep 30, 2025
d5c8d70
rename MathScript to DateMathScript, add SQLNull type
fupelaqu Oct 1, 2025
ccd8b6a
add support for between with identifiers, support for rounding date m…
fupelaqu Oct 1, 2025
450307c
finalize support for temporal between
fupelaqu Oct 2, 2025
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 @@ -20,7 +20,7 @@ This project provides a trait-based interface (`ElasticClientApi`) that aggregat
By relying on these concrete implementations, developers can switch between versions with minimal changes to their business logic.

**SQL to Elasticsearch Query Translation**
Elastic Client includes a parser capable of translating SQL `SELECT` queries into Elasticsearch queries. The parser produces an intermediate representation, which is then converted into [Elastic4s](https://github.com/sksamuel/elastic4s) DSL queries and ultimately into native Elasticsearch queries. This allows data engineers and analysts to express queries in familiar SQL syntax.
Elastic Client includes a parser capable of translating SQL `SELECT` queries into Elasticsearch queries. The parser produces an intermediate representation, which is then converted into [Elastic4s](https://github.com/sksamuel/elastic4s) DSL queries and ultimately into native Elasticsearch queries. This allows data engineers and analysts to express queries in familiar [SQL](documentation/README.md) syntax.

**Dynamic Mapping Migration**
Elastic Client provides tools to analyze and compare existing mappings with new ones. If differences are detected, it can automatically perform safe migrations. This includes creating temporary indices, reindexing, and renaming — all while preserving data integrity. This eliminates the need for manual mapping migrations and reduces downtime.
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ThisBuild / organization := "app.softnetwork"

name := "softclient4es"

ThisBuild / version := "0.8.0"
ThisBuild / version := "0.9.0"

ThisBuild / scalaVersion := scala213

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.softnetwork.elastic.client

import app.softnetwork.elastic.sql.AggregateFunction
import app.softnetwork.elastic.sql.function.aggregate.AggregateFunction

sealed trait AggregateResult {
def field: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import _root_.akka.stream.{FlowShape, Materializer}
import akka.stream.scaladsl._
import app.softnetwork.persistence.model.Timestamped
import app.softnetwork.serialization._
import app.softnetwork.elastic.sql.{SQLQuery, SQLSearchRequest}
import app.softnetwork.elastic.sql.query.{SQLQuery, SQLSearchRequest}
import com.google.gson.JsonParser
import com.typesafe.config.{Config, ConfigFactory}
import org.json4s.{DefaultFormats, Formats}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.softnetwork.elastic.client
import com.google.gson._
import com.typesafe.scalalogging.StrictLogging

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.util.{Failure, Success, Try}

object MappingComparator extends StrictLogging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.collection.mutable
import scala.language.reflectiveCalls
import scala.util.{Failure, Success, Try}

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

/** Created by smanciot on 30/06/2018.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.softnetwork.elastic.persistence.query

import app.softnetwork.elastic.client.ElasticClientApi
import app.softnetwork.elastic.sql.SQLQuery
import app.softnetwork.elastic.sql.query.SQLQuery
import mustache.Mustache
import org.json4s.Formats
import app.softnetwork.persistence._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import akka.actor.ActorSystem
import app.softnetwork.elastic.model.{Binary, Child, Parent, Sample}
import app.softnetwork.elastic.persistence.query.ElasticProvider
import app.softnetwork.elastic.scalatest.ElasticDockerTestKit
import app.softnetwork.elastic.sql.SQLQuery
import app.softnetwork.elastic.sql.query.SQLQuery
import app.softnetwork.persistence._
import app.softnetwork.persistence.person.model.Person
import com.fasterxml.jackson.core.JsonParseException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app.softnetwork.elastic.client
import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.scaladsl.Flow
import app.softnetwork.elastic.sql.{SQLQuery, SQLSearchRequest}
import app.softnetwork.elastic.sql.query.{SQLQuery, SQLSearchRequest}
import org.json4s.Formats
import app.softnetwork.persistence.model.Timestamped
import org.slf4j.{Logger, LoggerFactory}
Expand Down
15 changes: 15 additions & 0 deletions documentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SQL Engine Documentation

Welcome to the SQL Engine Documentation. Navigate through the sections below:

- [Query Structure](request_structure.md)
- [Operators](operators.md)
- [Operator Precedence](operator_precedence.md)
- [Aggregate Functions](functions_aggregate.md)
- [Date/Time Functions](functions_date_time.md)
- [Math Functions](functions_math.md)
- [String Functions](functions_string.md)
- [Type Conversion](type_conversion.md)
- [Conditional Functions](functions_conditional.md)
- [Geo Functions](functions_geo.md)
- [Keywords](keywords.md)
171 changes: 171 additions & 0 deletions documentation/functions_aggregate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
[Back to index](./README.md)

# Aggregate Functions

**Navigation:** [Functions — Date / Time](./functions_date_time.md) · [Functions — Conditional](./functions_conditional.md)

This page documents aggregate functions.

---

### Function: COUNT
**Description:**
Count rows or non-null expressions.
With `DISTINCT` counts distinct values.

**Inputs:**
- `expr` or `*`; optional `DISTINCT`

**Output:**
- `BIGINT`

**Example:**
```sql
SELECT COUNT(*) AS total FROM emp;
-- Result: total = 42

SELECT COUNT(DISTINCT salary) AS distinct_salaries FROM emp;
-- Result: 8
```

---

### Function: SUM
**Description:**
Sum of values.

**Inputs:**
- `expr` (`NUMERIC`)

**Output:**
- `NUMERIC`

**Example:**
```sql
SELECT SUM(salary) AS total_salary FROM emp;
```

---

### Function: AVG
**Description:**
Average of values.

**Inputs:**
- `expr` (`NUMERIC`)

**Output:**
- `DOUBLE`

**Example:**
```sql
SELECT AVG(salary) AS avg_salary FROM emp;
```

---

### Function: MIN
**Description:**
Minimum value in group.

**Inputs:**
- `expr` (comparable)

**Output:**
- same as input

**Example:**
```sql
SELECT MIN(hire_date) AS earliest FROM emp;
```

---

### Function: MAX
**Description:**
Maximum value in group.

**Inputs:**
- `expr` (comparable)

**Output:**
- same as input

**Example:**
```sql
SELECT MAX(salary) AS top_salary FROM emp;
```

---

### Function: FIRST_VALUE
**Description:**
Window: first value ordered by `ORDER BY`. Pushed as `top_hits size=1` to ES when possible.

**Inputs:**
- `expr` with optional `OVER (PARTITION BY ... ORDER BY ...)`
If `OVER` is not provided, only the expr column name is used for the sorting.

**Output:**
- same as input

**Example:**
```sql
SELECT FIRST_VALUE(salary)
OVER (
PARTITION BY department
ORDER BY hire_date ASC
) AS first_salary
FROM emp;
```

---

### Function: LAST_VALUE
**Description:**
Window: last value ordered by `ORDER BY. Pushed to ES by flipping sort order in `top_hits`.

**Inputs:**
- `expr` with optional `OVER (PARTITION BY ... ORDER BY ...)`
If `OVER` is not provided, only the expr column name is used for the sorting.

**Output:**
- same as input

**Example:**
```sql
SELECT LAST_VALUE(salary)
OVER (
PARTITION BY department
ORDER BY hire_date ASC
) AS last_salary
FROM emp;
```

---

### Function: ARRAY_AGG
**Description:**
Collect values into an array for each partition. Implemented using `OVER` and pushed to ES as `top_hits`. Post-processing converts hits to an array of scalars.

**Inputs:**
- `expr` with optional `OVER (PARTITION BY ... ORDER BY ... LIMIT n)`
If `OVER` is not provided, only the expr column name is used for the sorting.

**Output:**
- `ARRAY<type_of_expr>`

**Example:**
```sql
SELECT department,
ARRAY_AGG(name) OVER (
PARTITION BY department
ORDER BY hire_date ASC
LIMIT 100
) AS employees
FROM emp;
-- Result: employees as an array of name values
-- per department (sorted and limited)
```

[Back to index](./README.md)
Loading