Skip to content

Commit

Permalink
Improve example 12
Browse files Browse the repository at this point in the history
- Allow example 12 to run in parallel to other examples by consuming from a separate topic
- Improve on the Python mapping for Java arrays by forcing a conversion to Python lists
  • Loading branch information
jeroenvandisseldorp committed Sep 24, 2024
1 parent f853d25 commit 5549d32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/12-example-byte-manipulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ functions:
code: |
global newSchemaId
log.info("Replacing schema in message value: {}", value)
if value is not None:
if isinstance(value, list):
if value[0] == 0 and len(value) >= 5:
value[1] = (newSchemaId & 0xff000000) >> 24
value[2] = (newSchemaId & 0xff0000) >> 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.axual.ksml.util.ExecutionUtil;
import org.graalvm.polyglot.Value;

import java.util.ArrayList;
import java.util.Map;

public class PythonDataObjectMapper extends NativeDataObjectMapper {
Expand Down Expand Up @@ -146,7 +147,13 @@ public Value fromDataObject(DataObject object) {
if (object instanceof DataLong val) return Value.asValue(val.value());
if (object instanceof DataFloat val) return Value.asValue(val.value());
if (object instanceof DataDouble val) return Value.asValue(val.value());
if (object instanceof DataBytes val) return Value.asValue(val.value());
if (object instanceof DataBytes val) {
// Convert the contained byte array to a list, so it can be converted to a Python list by the PythonFunction
// wrapper code downstream...
final var bytes = new ArrayList<Byte>(val.value().length);
for (byte b : val.value()) bytes.add(b);
return Value.asValue(bytes);
}
if (object instanceof DataString val) return Value.asValue(val.value());
if (object instanceof DataList val) return Value.asValue(fromDataList(val));
if (object instanceof DataStruct val) return Value.asValue(fromDataStruct(val));
Expand Down

0 comments on commit 5549d32

Please sign in to comment.