Skip to content

Commit

Permalink
Add code style check for both java and rust
Browse files Browse the repository at this point in the history
  • Loading branch information
beinan committed Feb 21, 2024
1 parent 3447b43 commit 392454e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@ jobs:
run: |
sudo apt update
sudo apt install -y protobuf-compiler libssl-dev
- name: Install Java
- name: Install Java 11
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: 'maven'
- run: echo "JAVA_17=$JAVA_HOME" >> $GITHUB_ENV
- name: Install Java
- name: Install Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 11
cache: 'maven'
- name: Java Style Check
run: mvn checkstyle:check
- name: Rust Clippy
working-directory: ./java/rust-jni
run: cargo clippy --all-targets -- -D warnings
- name: Build with Maven with Java 11
run: mvn package -DskipTests=true
- name: Running tests with Java 11
Expand Down
2 changes: 1 addition & 1 deletion java/lance-jni/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use jni::JNIEnv;
use lance::dataset::{WriteMode, WriteParams};

#[no_mangle]
pub extern "system" fn Java_com_lancedb_lance_Dataset_writeWithFFIStream<'local>(
pub extern "system" fn Java_com_lancedb_lance_Dataset_writeWithFfiStream<'local>(
mut env: JNIEnv<'local>,
_obj: JObject,
arrow_array_stream_addr: jlong,
Expand Down
28 changes: 25 additions & 3 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lancedb</groupId>
Expand Down Expand Up @@ -48,6 +49,27 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<violationSeverity>warning</violationSeverity>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.questdb</groupId>
<artifactId>rust-maven-plugin</artifactId>
Expand Down Expand Up @@ -114,4 +136,4 @@
</plugins>
</pluginManagement>
</build>
</project>
</project>
15 changes: 7 additions & 8 deletions java/src/main/java/com/lancedb/lance/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.lancedb.lance;

import io.questdb.jar.jni.JarJniLoader;
import org.apache.arrow.c.ArrowArrayStream;
import org.apache.arrow.c.jni.JniLoader;

import java.io.Closeable;
import java.util.Map;
import org.apache.arrow.c.ArrowArrayStream;

/**
* Class representing a Lance dataset, interfacing with the native lance library.
* This class provides functionality to open and manage datasets with native code.
*
* The native library is loaded statically and utilized through native methods.
* It implements the {@link java.io.Closeable} interface to ensure proper resource management.
*/
Expand All @@ -38,10 +36,10 @@ private Dataset() {
}

public static Dataset write(ArrowArrayStream stream, String path, WriteParams params) {
return writeWithFFIStream(stream.memoryAddress(), path, params.toMap());
return writeWithFfiStream(stream.memoryAddress(), path, params.toMap());
}

private static native Dataset writeWithFFIStream(long ArrowStreamMemoryAddress, String path,
private static native Dataset writeWithFfiStream(long arrowStreamMemoryAddress, String path,
Map<String, Object> params);

/**
Expand All @@ -50,11 +48,12 @@ private static native Dataset writeWithFFIStream(long ArrowStreamMemoryAddress,
* @param path The file path of the dataset to open.
* @return A new instance of {@link Dataset} linked to the opened dataset.
*/
public native static Dataset open(String path);
public static native Dataset open(String path);

/**
* Count the number of rows in the dataset.
* @return num of rows
*
* @return num of rows.
*/
public native int countRows();

Expand Down
19 changes: 18 additions & 1 deletion java/src/main/java/com/lancedb/lance/WriteParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.lancedb.lance;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* Write Params for Write Operations of Lance.
*/
public class WriteParams {

/**
* Write Mode.
*/
public enum WriteMode {
CREATE,
APPEND,
Expand All @@ -37,6 +45,11 @@ private WriteParams(Optional<Integer> maxRowsPerFile, Optional<Integer> maxRowsP
this.mode = mode;
}

/**
* Create a map of the key-value pair of write params.
*
* @return a map of write params
*/
public Map<String, Object> toMap() {
Map<String, Object> params = new HashMap<>();
maxRowsPerFile.ifPresent(value -> params.put("max_rows_per_file", value));
Expand All @@ -46,6 +59,10 @@ public Map<String, Object> toMap() {
return params;
}


/**
* A builder of WriteParams.
*/
public static class Builder {
private Optional<Integer> maxRowsPerFile = Optional.empty();
private Optional<Integer> maxRowsPerGroup = Optional.empty();
Expand Down Expand Up @@ -73,7 +90,7 @@ public Builder withMode(WriteMode mode) {
}

public WriteParams build() {
return new WriteParams(this.maxRowsPerFile, this.maxRowsPerGroup, this.maxBytesPerFile, this.mode);
return new WriteParams(maxRowsPerFile, maxRowsPerGroup, maxBytesPerFile, mode);
}
}
}

0 comments on commit 392454e

Please sign in to comment.