-
Notifications
You must be signed in to change notification settings - Fork 707
feat(java-binding): support java binding on stream chunk #8517
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39978e1
feat(java-binding): support java binding on stream chunk
wenym1 6486af4
rename the previous general iterator and add demo and ci for data chu…
wenym1 ddbcfd9
fix license
wenym1 c4a6e9d
fix license again
wenym1 5cfd57b
rename iterator to HummockJavaBindingIterator
wenym1 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
43 changes: 43 additions & 0 deletions
43
...a-binding-integration-test/src/main/java/com/risingwave/java/binding/StreamChunkDemo.java
This file contains hidden or 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,43 @@ | ||
| // Copyright 2023 RisingWave Labs | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.risingwave.java.binding; | ||
|
|
||
| import static com.risingwave.java.binding.Utils.validateRow; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class StreamChunkDemo { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| byte[] payload = System.in.readAllBytes(); | ||
| try (StreamChunkIterator iter = new StreamChunkIterator(payload)) { | ||
| int count = 0; | ||
| while (true) { | ||
| try (StreamChunkRow row = iter.next()) { | ||
| if (row == null) { | ||
| break; | ||
| } | ||
| count += 1; | ||
| validateRow(row); | ||
| } | ||
| } | ||
| int expectedCount = 30000; | ||
| if (count != expectedCount) { | ||
| throw new RuntimeException( | ||
| String.format("row count is %s, should be %s", count, expectedCount)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
java/java-binding-integration-test/src/main/java/com/risingwave/java/binding/Utils.java
This file contains hidden or 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,56 @@ | ||
| // Copyright 2023 RisingWave Labs | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.risingwave.java.binding; | ||
wenym1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public class Utils { | ||
| public static void validateRow(BaseRow row) { | ||
| // The validation of row data are according to the data generation rule | ||
| // defined in ${REPO_ROOT}/src/java_binding/gen-demo-insert-data.py | ||
| short rowIndex = row.getShort(0); | ||
| if (row.getInt(1) != rowIndex) { | ||
| throw new RuntimeException( | ||
| String.format("invalid int value: %s %s", row.getInt(1), rowIndex)); | ||
| } | ||
| if (row.getLong(2) != rowIndex) { | ||
| throw new RuntimeException( | ||
| String.format("invalid long value: %s %s", row.getLong(2), rowIndex)); | ||
| } | ||
| if (row.getFloat(3) != (float) rowIndex) { | ||
| throw new RuntimeException( | ||
| String.format("invalid float value: %s %s", row.getFloat(3), rowIndex)); | ||
| } | ||
| if (row.getDouble(4) != (double) rowIndex) { | ||
| throw new RuntimeException( | ||
| String.format("invalid double value: %s %s", row.getDouble(4), rowIndex)); | ||
| } | ||
| if (row.getBoolean(5) != (rowIndex % 3 == 0)) { | ||
| throw new RuntimeException( | ||
| String.format( | ||
| "invalid bool value: %s %s", row.getBoolean(5), (rowIndex % 3 == 0))); | ||
| } | ||
| if (!row.getString(6).equals(((Short) rowIndex).toString().repeat((rowIndex % 10) + 1))) { | ||
| throw new RuntimeException( | ||
| String.format( | ||
| "invalid string value: %s %s", | ||
| row.getString(6), | ||
| ((Short) rowIndex).toString().repeat((rowIndex % 10) + 1))); | ||
| } | ||
| if (row.isNull(7) != (rowIndex % 5 == 0)) { | ||
| throw new RuntimeException( | ||
| String.format( | ||
| "invalid isNull value: %s %s", row.isNull(7), (rowIndex % 5 == 0))); | ||
| } | ||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
java/java-binding/src/main/java/com/risingwave/java/binding/BaseRow.java
This file contains hidden or 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,65 @@ | ||
| // Copyright 2023 RisingWave Labs | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.risingwave.java.binding; | ||
wenym1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public class BaseRow implements AutoCloseable { | ||
| protected final long pointer; | ||
| private boolean isClosed; | ||
|
|
||
| protected BaseRow(long pointer) { | ||
| this.pointer = pointer; | ||
| this.isClosed = false; | ||
| } | ||
|
|
||
| public boolean isNull(int index) { | ||
| return Binding.rowIsNull(pointer, index); | ||
| } | ||
|
|
||
| public short getShort(int index) { | ||
| return Binding.rowGetInt16Value(pointer, index); | ||
| } | ||
|
|
||
| public int getInt(int index) { | ||
| return Binding.rowGetInt32Value(pointer, index); | ||
| } | ||
|
|
||
| public long getLong(int index) { | ||
| return Binding.rowGetInt64Value(pointer, index); | ||
| } | ||
|
|
||
| public float getFloat(int index) { | ||
| return Binding.rowGetFloatValue(pointer, index); | ||
| } | ||
|
|
||
| public double getDouble(int index) { | ||
| return Binding.rowGetDoubleValue(pointer, index); | ||
| } | ||
|
|
||
| public boolean getBoolean(int index) { | ||
| return Binding.rowGetBooleanValue(pointer, index); | ||
| } | ||
|
|
||
| public String getString(int index) { | ||
| return Binding.rowGetStringValue(pointer, index); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (!isClosed) { | ||
| isClosed = true; | ||
| Binding.rowClose(pointer); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.