forked from risingwavelabs/risingwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java-binding): support java binding on stream chunk (risingwavel…
- Loading branch information
Showing
20 changed files
with
635 additions
and
188 deletions.
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 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 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 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 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; | ||
|
||
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 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; | ||
|
||
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 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.