-
Notifications
You must be signed in to change notification settings - Fork 218
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
Release prql-java #781
Merged
Release prql-java #781
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0796268
rename java test package name
doki23 6c240f8
cross try
doki23 2d79f47
Merge branch 'prql:main' into release_java
doki23 3e09bb0
release conf
doki23 2e80f95
fix tests
doki23 35f5f2c
update doc
doki23 9329931
profile adjustment
doki23 58e3bc8
Merge branch 'main' into release_java
max-sixty 451c5e8
Merge branch 'main' into pr/doki23/781
max-sixty 5a6e433
pre-commit
doki23 ce43e76
update developers
doki23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,3 @@ dist | |
.idea | ||
|
||
target/ | ||
|
||
**/libprql_java* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target/ | ||
|
||
**/libprql_java* | ||
**/prql_java.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# development description for prql-java module | ||
|
||
--- | ||
|
||
## Implementation | ||
|
||
We implement rust bindings to java with [jni](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/). | ||
|
||
First, define a native method -- `public static native String toSql(String query)` for PrqlCompiler, `toJson` is same. | ||
|
||
And then implement it in rust with this [crate](https://docs.rs/jni/latest/jni/). | ||
|
||
## Build | ||
|
||
For ease of use to users, we need pre-build dynamic libs for different platforms. This process is combined into the build of java module. | ||
|
||
We use [maven](https://maven.apache.org/) to build the java lib. To add the rust cross compilation into the maven build process, we add the following xml segment to the `pom.xml`: | ||
|
||
```xml | ||
<plugin> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<id>Build for release</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>exec</goal> | ||
</goals> | ||
<configuration> | ||
<executable>../cross.sh</executable> | ||
<arguments> | ||
<argument>${project.basedir}/../</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
``` | ||
|
||
When we build, it will execute the `cross.sh` script to get all the rust cdylibs. This process is time-consuming. | ||
|
||
As to cross compilation toolchains, we use [cross](https://github.com/cross-rs/cross). | ||
|
||
## Publish(for maintainer) | ||
|
||
To publish the java lib to maven public repo, | ||
project maintainer need first register a project in the maven nexus repo, by the doc: | ||
https://central.sonatype.org/publish/publish-guide/. | ||
|
||
And then, we can release our artifact in the `release` workflow. | ||
The action we used is [action-maven-publish](https://github.com/marketplace/actions/action-maven-publish). | ||
Project maintainer has to configure some personal information, those used in the first step, by the action's doc, such as `nexus_username`, `nexus_password`, `gpg_private_key`, `gpg_passphrase`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# prql-java | ||
|
||
`prql-java` offers rust bindings to the `prql-compiler` rust library. It | ||
exposes a java native method `public static native String toSql(String query)`. | ||
|
||
## Installation | ||
|
||
```xml | ||
<dependency> | ||
<groupId>org.prqllang</groupId> | ||
<artifactId>prql-java</artifactId> | ||
<version>${PRQL_VERSION}</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
```java | ||
import org.prqllang.prql4j.PrqlCompiler; | ||
|
||
class Main { | ||
public static void main(String[] args) { | ||
String sql = PrqlCompiler.toSql("from table"); | ||
System.out.println(sql); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
PRQL_JAVA_MODULE=$1 | ||
echo PRQL_JAVA_MODULE="${PRQL_JAVA_MODULE}" | ||
CONTEXT_PATH=$(pwd) | ||
echo CONTEXT_PATH="${CONTEXT_PATH}" | ||
cd "${PRQL_JAVA_MODULE}" || exit 1 | ||
|
||
# install cross | ||
cargo install cross | ||
|
||
# x86_64-unknown-linux-gnu | ||
echo "compiling for x86_64-unknown-linux-gnu" | ||
rustup target add x86_64-unknown-linux-gnu | ||
cross build --release --target x86_64-unknown-linux-gnu | ||
ls -la ../target/x86_64-unknown-linux-gnu/release | ||
cp -f ../target/x86_64-unknown-linux-gnu/release/libprql_java.so java/src/main/resources/libprql_java-linux64.so | ||
|
||
## x86_64-unknown-linux-musl | ||
#echo "compiling for x86_64-unknown-linux-musl" | ||
#rustup target add x86_64-unknown-linux-musl | ||
#cross build --release --target x86_64-unknown-linux-musl | ||
#ls -la ../target/x86_64-unknown-linux-musl/release | ||
#cp ../target/x86_64-unknown-linux-musl/release/libprql_java.so java/src/main/resources/libprql_java-linux64-musl.so | ||
|
||
## x86_64-apple-darwin | ||
#echo "compiling for x86_64-apple-darwin" | ||
#rustup target add x86_64-apple-darwin | ||
#cross build --release --target x86_64-apple-darwin | ||
#ls -la ../target/x86_64-apple-darwin/release | ||
#cp ../target/x86_64-apple-darwin/release/libprql_java.dylib java/src/main/resources/libprql_java-osx-x86_64.dylib | ||
|
||
# x86_64-pc-windows-gnu | ||
echo "compiling for x86_64-pc-windows-gnu" | ||
rustup target add x86_64-pc-windows-gnu | ||
cross build --release --target x86_64-pc-windows-gnu | ||
ls -la ../target/x86_64-pc-windows-gnu/release | ||
cp -f ../target/x86_64-pc-windows-gnu/release/prql_java.dll java/src/main/resources/libprql_java-win64.dll | ||
|
||
# aarch64-unknown-linux-gnu | ||
echo "compiling for aarch64-unknown-linux-gnu" | ||
rustup target add aarch64-unknown-linux-gnu | ||
cross build --release --target aarch64-unknown-linux-gnu | ||
ls -la ../target/x86_64-unknown-linux-gnu/release | ||
cp -f ../target/x86_64-unknown-linux-gnu/release/libprql_java.so java/src/main/resources/libprql_java-linux-aarch64.so | ||
|
||
# aarch64-unknown-linux-musl | ||
#echo "compiling for aarch64-unknown-linux-musl" | ||
#rustup target add aarch64-unknown-linux-musl | ||
#cross build --release --target aarch64-unknown-linux-musl | ||
#ls -la ../target/aarch64-unknown-linux-musl/release | ||
#cp -f ../target/aarch64-unknown-linux-musl/release/libprql_java.so java/src/main/resources/libprql_java-linux-aarch64-musl.so | ||
|
||
## aarch64-apple-darwin | ||
#echo "compiling for aarch64-apple-darwin" | ||
#rustup target add aarch64-apple-darwin | ||
#cross build --release --target aarch64-apple-darwin | ||
#ls -la ../target/x86_64-apple-darwin/release | ||
#cp -f ../target/x86_64-apple-darwin/release/libprql_java.dylib java/src/main/resources/libprql_java-osx-arm64.dylib | ||
|
||
cd "${CONTEXT_PATH}" || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My guess is that this file could move to a workflow eventually; but to the extent you've been iterating on it locally, it looks good, and we can move to a workflow later.