PDGGK opened a new issue, #39730:
URL: https://github.com/apache/beam/issues/39730

   ### What happened?
   
   `AttributeValueCoder.encode` cannot encode a DynamoDB attribute whose value 
is an **empty list** or an **empty map** — it throws `CoderException("Unknown 
Type")`.
   
   The L and M branches are selected with a size check:
   
   ```java
   } else if (value.ss() != null && value.ss().size() > 0) {   // correct: 
DynamoDB rejects empty sets
   ...
   } else if (value.l() != null && value.l().size() > 0) {     // wrong: 
DynamoDB allows an empty L
   } else if (value.m() != null && value.m().size() > 0) {     // wrong: 
DynamoDB allows an empty M
   } else if (value.nul() != null) {
   ...
   } else {
     throw new CoderException("Unknown Type");
   }
   ```
   
   For an empty `L`, `l()` is non-null and `size()` is 0, so the guard fails; 
`m()` and `nul()` do not match either, and it falls through to the terminal 
`else`.
   
   **The blast radius is the whole item, not one attribute.** 
`MAP_ATTRIBUTE_CODER` re-enters this coder for every child, so a single empty 
list nested anywhere inside an item makes that item unencodable:
   
   ```java
   Map<String, AttributeValue> item = new HashMap<>();
   item.put("name", AttributeValue.builder().s("widget").build());
   item.put("tags", AttributeValue.builder().l(new ArrayList<>()).build());
   AttributeValueCoder.of().encode(AttributeValue.builder().m(item).build(), 
out);
   // CoderException: Unknown Type
   ```
   
   Empty `L` and `M` are valid DynamoDB attribute values and the service 
returns them, unlike the `SS`/`NS`/`BS` set types where the `size() > 0` guard 
is legitimate — DynamoDB rejects empty sets.
   
   The `decode` side already copes: `case l:` and `case m:` delegate to 
`ListCoder`/`MapCoder`, which round-trip empties fine. Only `encode` rejects 
them.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Java SDK
   - [x] Component: IO connector
   


-- 
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]

Reply via email to