ngibanel commented on code in PR #40108:
URL: https://github.com/apache/beam/pull/40108#discussion_r4013718464
##########
sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/data/Solace.java:
##########
@@ -599,5 +623,47 @@ private static byte[] readAttachment(BytesXMLMessage msg) {
buffer.get(attachment);
return attachment;
}
+
+ private static Map<String, String> getUserProperties(@Nullable SDTMap
properties) {
+ if (properties == null || properties.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ Map<String, String> userProperties = new HashMap<>();
+ for (String key : properties.keySet()) {
+ String value = stringifyUserProperty(properties, key);
+ if (value == null) {
+ LOG.warn("User property '{}' has a null value, skipping.", key);
+ continue;
+ }
+ userProperties.put(key, value);
+ }
+ return Collections.unmodifiableMap(userProperties);
+ }
+
+ private static @Nullable String stringifyUserProperty(SDTMap properties,
String key) {
+ try {
+ Object value = properties.get(key);
+ if (value == null) {
+ return null;
+ }
+ return String.valueOf(value);
Review Comment:
good catch I didn't check all the types. Maybe translating all types into
string is not the good choice at the end because with this design we won't be
able to reverse to Solace types.
What do you think if instead to have a Map<String, String>, having a
Map<String, UserPropertyValue> where UserPropertyValue will be a beam schema
compatible model that support all the type kinds :
```java
@AutoValue
@DefaultSchema(AutoValueSchema.class)
public abstract static class UserPropertyValue {
public enum Kind {
BOOLEAN,
BYTE,
SHORT,
INTEGER,
LONG,
FLOAT,
DOUBLE,
CHARACTER,
STRING,
BYTES,
TOPIC,
QUEUE,
MAP,
STREAM
}
public abstract Kind getKind();
public abstract @Nullable Map<String, UserPropertyValue> getMapValue();
public abstract @Nullable List<UserPropertyValue> getStreamValue();
...
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]