Skip to content
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

[Backport] Fix crash when using AVRO CharSequence encodings and nested objects #164

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.axual.ksml.data.schema.SchemaLibrary;
import io.axual.ksml.data.schema.StructSchema;
import io.axual.ksml.data.type.*;
import io.axual.ksml.data.util.MapUtil;
import io.axual.ksml.data.value.Tuple;

import java.util.ArrayList;
Expand Down Expand Up @@ -98,7 +99,7 @@ public DataObject toDataObject(DataType expected, Object value) {
if (value instanceof List<?> val)
return nativeToDataList((List<Object>) val, expected instanceof ListType expectedList ? expectedList.valueType() : DataType.UNKNOWN);
if (value instanceof Map<?, ?> val)
return nativeToDataStruct((Map<String, Object>) val, expected instanceof StructType expectedStruct ? expectedStruct.schema() : null);
return nativeToDataStruct(MapUtil.stringKeys(val), expected instanceof StructType expectedStruct ? expectedStruct.schema() : null);
if (value instanceof Tuple<?> val) return toDataTuple((Tuple<Object>) val);
throw new ExecutionException("Can not convert to DataObject: " + value.getClass().getSimpleName());
}
Expand Down
12 changes: 12 additions & 0 deletions ksml-data/src/main/java/io/axual/ksml/data/util/MapUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.axual.ksml.data.util;

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

public class MapUtil {
public static Map<String, Object> stringKeys(Map<?, ?> map) {
final var result = new HashMap<String, Object>();
map.forEach((key, value) -> result.put(key != null ? key.toString() : null, value));
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.axual.ksml.data.mapper.NativeDataObjectMapper;
import io.axual.ksml.data.object.*;
import io.axual.ksml.data.type.*;
import io.axual.ksml.data.util.MapUtil;
import io.axual.ksml.util.ExecutionUtil;
import org.graalvm.polyglot.Value;

Expand Down Expand Up @@ -134,7 +135,7 @@ private Object arrayToNative(DataType expected, Value object) {
private DataObject mapToNative(DataType expected, Value object) {
Map<?, ?> map = ExecutionUtil.tryThis(() -> object.as(Map.class));
if (map == null) return null;
return nativeToDataStruct((Map<String, Object>) map, expected instanceof StructType structType ? structType.schema() : null);
return nativeToDataStruct(MapUtil.stringKeys(map), expected instanceof StructType structType ? structType.schema() : null);
}

@Override
Expand Down