Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(isthmus): support for SQL expressions in CLI #209

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
333989f
feat: convert sql expression into proto extended expressions
davisusanibar Oct 24, 2023
f4b6581
fix: implement nameToNodeMap and nameToTypeMap dyamically instead of …
davisusanibar Oct 26, 2023
a79f57d
fix: cover support also for project extended expression
davisusanibar Oct 26, 2023
a37be92
fix: cover support also for project extended expression
davisusanibar Oct 27, 2023
9f6aaf3
fix: create schema dynamically
davisusanibar Nov 15, 2023
52b41e3
fix: set function reference and extensions dinamically
davisusanibar Nov 16, 2023
74d13d3
Merge branch 'main' into feature/sql_to_extended_expression
davisusanibar Nov 16, 2023
3d80d1f
fix: clean code
davisusanibar Nov 16, 2023
ae84176
Merge branch 'main' into feature/sql_to_extended_expression
davisusanibar Nov 16, 2023
5954a62
fix: clean code
davisusanibar Nov 16, 2023
fc33a32
fix: rename variables to clean code
davisusanibar Nov 17, 2023
217f2a0
fix: from/to pojo/protobuf
davisusanibar Nov 23, 2023
75e4f48
feat: enable support from/to pojo/protobuf for extended expressions
davisusanibar Nov 24, 2023
1d23187
Merge branch 'main' into feature/from_to_protobuf_pojo
davisusanibar Nov 24, 2023
5adc79f
fix: consume core module for proto/pojo conversions
davisusanibar Nov 24, 2023
940f703
fix: clean code redundant method
davisusanibar Nov 25, 2023
e281f2f
Merge branch 'main' into feature/sql_to_extended_expression
davisusanibar Nov 25, 2023
f817eb0
fix: apply suggestions from code review
davisusanibar Nov 29, 2023
b1c96bd
fix: code review core module
davisusanibar Nov 29, 2023
3d9b927
fix: code review core module testing side
davisusanibar Nov 29, 2023
e790492
feat: support aggregation function in extended expression from/to poj…
davisusanibar Dec 6, 2023
ef7c076
fix: merge from/to proto/pojo
davisusanibar Dec 6, 2023
d1b4efb
fix: merge from/to proto/pojo
davisusanibar Dec 6, 2023
c26fecd
fix: merge from/to proto/pojo + solve comments on the PR
davisusanibar Dec 6, 2023
bdde874
Merge branch 'main' into feature/sql_to_extended_expression
davisusanibar Dec 6, 2023
c3cd3e6
feat: expose sql expression to extended expression thru Pico CLI
davisusanibar Dec 6, 2023
8d0f81d
feat: expose Isthmus native image commands for SQL Query and SQL Expr…
davisusanibar Dec 12, 2023
6c90456
fix: conflicting files on merge
davisusanibar Jan 20, 2024
6fe70bb
fix: delete files not needed
davisusanibar Jan 20, 2024
c112a27
fix: clean code
davisusanibar Jan 20, 2024
1667cd7
fix: clean validation for empty values that could be supported for Li…
davisusanibar Jan 22, 2024
4677b9e
fix: clean code
davisusanibar Jan 25, 2024
0553366
fix: test if error appear on sequential process
davisusanibar Jan 25, 2024
370fa30
fix: upgrade gradle build action version
davisusanibar Feb 2, 2024
6f9f6fb
fix: delegate to gradle/actions/setup-gradle@v3
davisusanibar Feb 2, 2024
f5e743c
fix: code review suggestion
davisusanibar Feb 3, 2024
67a2543
fix: rename planEntryPoint to isthmusEntryPoint
davisusanibar Feb 3, 2024
0e1d142
feat: add support for help version image command options
davisusanibar Feb 4, 2024
686a91f
Merge branch 'main' into GH-MANY-EXPRESSION
davisusanibar Feb 4, 2024
123d859
feat: enable support for N expression + refacto Isthmus CLI
davisusanibar Feb 5, 2024
10e52c7
feat: allow to execute more than one epression + testing custom separ…
davisusanibar Feb 5, 2024
5cd32d6
fix: delete separator of expressions. Migrate to use expression as St…
davisusanibar Feb 5, 2024
908d5e3
refactor: small PR changes
vbarua Feb 6, 2024
9041b7c
test: remove reference to comma separator
vbarua Feb 6, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
java-version: '17'
distribution: 'adopt'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle
run: gradle build
isthmus-native-image-mac-linux:
Expand All @@ -63,7 +63,7 @@ jobs:
# helps avoid rate-limiting issues
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
- name: Report Java Version
run: java -version
- name: Install GraalVM native image
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# helps avoid rate-limiting issues
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
- name: Report Java Version
run: java -version
- name: Install GraalVM native image
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
with:
node-version: '20'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
- name: Download isthmus-ubuntu-latest binary
uses: actions/download-artifact@v4
with:
Expand Down
243 changes: 238 additions & 5 deletions isthmus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

Substrait Isthmus is a Java library which enables serializing SQL to [Substrait Protobuf](https://substrait.io/serialization/binary_serialization/) via
Substrait Isthmus is a Java library which enables serializing SQL queries to [Substrait Protobuf](https://substrait.io/serialization/binary_serialization/) and SQL expressions to [Extended Expressions](https://substrait.io/expressions/extended_expression/) via
the Calcite SQL compiler. Optionally, you can leverage the Calcite RelNode to Substrait Plan translator as an IR translation.

## Build
Expand All @@ -15,20 +15,51 @@ Isthmus can be built as a native executable via Graal

## Usage

### Version

```
$ ./isthmus/build/graal/isthmus --version

isthmus 0.1
```

### Help

```
$ ./isthmus/build/graal/isthmus
$ ./isthmus/build/graal/isthmus --help

Usage: isthmus [-m] [-c=<createStatements>]... <sql>
Converts a SQL query to a Substrait Plan
<sql> The sql we should parse.
Usage: isthmus [-hmV] [--crossjoinpolicy=<crossJoinPolicy>]
[--outputformat=<outputFormat>]
[--sqlconformancemode=<sqlConformanceMode>]
[-c=<createStatements>]... [-e=<sqlExpressions>...]... [<sql>]
Convert SQL Queries and SQL Expressions to Substrait
[<sql>] A SQL query
-c, --create=<createStatements>
One or multiple create table statements e.g. CREATE
TABLE T1(foo int, bar bigint)
--crossjoinpolicy=<crossJoinPolicy>
One of built-in Calcite SQL compatibility modes:
KEEP_AS_CROSS_JOIN, CONVERT_TO_INNER_JOIN
-e, --expression=<sqlExpressions>...
One or more SQL expressions e.g. col + 1
-h, --help Show this help message and exit.
-m, --multistatement Allow multiple statements terminated with a semicolon
--outputformat=<outputFormat>
Set the output format for the generated plan:
PROTOJSON, PROTOTEXT, BINARY
--sqlconformancemode=<sqlConformanceMode>
One of built-in Calcite SQL compatibility modes:
DEFAULT, LENIENT, BABEL, STRICT_92, STRICT_99,
PRAGMATIC_99, BIG_QUERY, MYSQL_5, ORACLE_10,
ORACLE_12, STRICT_2003, PRAGMATIC_2003, PRESTO,
SQL_SERVER_2008
-V, --version Print version information and exit.
```

## Example

### SQL to Substrait Plan

```
> $ ./isthmus/build/graal/isthmus \
-c "CREATE TABLE Persons ( firstName VARCHAR, lastName VARCHAR, zip INT )" \
Expand Down Expand Up @@ -155,3 +186,205 @@ Converts a SQL query to a Substrait Plan
"expectedTypeUrls": []
}
```

### SQL Expression to Substrait Extended Expression

#### Projection

```
$ ./isthmus/build/graal/isthmus -c "CREATE TABLE NATION (N_NATIONKEY BIGINT NOT NULL, N_NAME CHAR(25), N_REGIONKEY BIGINT NOT NULL, N_COMMENT VARCHAR(152))" \
-e "N_REGIONKEY + 10"

{
"extensionUris": [{
"extensionUriAnchor": 1,
"uri": "/functions_arithmetic.yaml"
}],
"extensions": [{
"extensionFunction": {
"extensionUriReference": 1,
"functionAnchor": 0,
"name": "add:i64_i64"
}
}],
"referredExpr": [{
"expression": {
"scalarFunction": {
"functionReference": 0,
"args": [],
"outputType": {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"arguments": [{
"value": {
"selection": {
"directReference": {
"structField": {
"field": 2
}
},
"rootReference": {
}
}
}
}, {
"value": {
"cast": {
"type": {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"input": {
"literal": {
"i32": 10,
"nullable": false,
"typeVariationReference": 0
}
},
"failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
}
}
}],
"options": []
}
},
"outputNames": ["new-column"]
}],
"baseSchema": {
"names": ["N_NATIONKEY", "N_NAME", "N_REGIONKEY", "N_COMMENT"],
"struct": {
"types": [{
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
}, {
"fixedChar": {
"length": 25,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
}, {
"varchar": {
"length": 152,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}],
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"expectedTypeUrls": []
}
```

#### Filter

```
$ ./isthmus/build/graal/isthmus -c "CREATE TABLE NATION (N_NATIONKEY BIGINT NOT NULL, N_NAME CHAR(25), N_REGIONKEY BIGINT NOT NULL, N_COMMENT VARCHAR(152))" \
-e "N_REGIONKEY > 10"

{
"extensionUris": [{
"extensionUriAnchor": 1,
"uri": "/functions_comparison.yaml"
}],
"extensions": [{
"extensionFunction": {
"extensionUriReference": 1,
"functionAnchor": 0,
"name": "gt:any_any"
}
}],
"referredExpr": [{
"expression": {
"scalarFunction": {
"functionReference": 0,
"args": [],
"outputType": {
"bool": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"arguments": [{
"value": {
"selection": {
"directReference": {
"structField": {
"field": 2
}
},
"rootReference": {
}
}
}
}, {
"value": {
"cast": {
"type": {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"input": {
"literal": {
"i32": 10,
"nullable": false,
"typeVariationReference": 0
}
},
"failureBehavior": "FAILURE_BEHAVIOR_UNSPECIFIED"
}
}
}],
"options": []
}
},
"outputNames": ["new-column"]
}],
"baseSchema": {
"names": ["N_NATIONKEY", "N_NAME", "N_REGIONKEY", "N_COMMENT"],
"struct": {
"types": [{
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
}, {
"fixedChar": {
"length": 25,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}, {
"i64": {
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
}, {
"varchar": {
"length": 152,
"typeVariationReference": 0,
"nullability": "NULLABILITY_NULLABLE"
}
}],
"typeVariationReference": 0,
"nullability": "NULLABILITY_REQUIRED"
}
},
"expectedTypeUrls": []
}
```
5 changes: 3 additions & 2 deletions isthmus/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ dependencies {
implementation("org.reflections:reflections:0.9.12")
implementation("com.google.guava:guava:29.0-jre")
implementation("org.graalvm.sdk:graal-sdk:22.1.0")
implementation("info.picocli:picocli:4.6.1")
implementation("info.picocli:picocli:4.7.5")
annotationProcessor("info.picocli:picocli-codegen:4.7.5")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.4")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.13.4")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.4")
Expand All @@ -99,7 +100,7 @@ dependencies {
}

graal {
mainClass("io.substrait.isthmus.PlanEntryPoint")
vibhatha marked this conversation as resolved.
Show resolved Hide resolved
mainClass("io.substrait.isthmus.IsthmusEntryPoint")
outputName("isthmus")
graalVersion("22.1.0")
javaVersion("17")
Expand Down
Loading
Loading