davsclaus opened a new pull request, #27612:
URL: https://github.com/apache/camel/pull/27612

   ## Summary
   
   [CAMEL-25481](https://issues.apache.org/jira/browse/CAMEL-25481): the 
DataWeave to DataSonnet conversion (camel-dataweave, with the 
`camel-dataweave.libsonnet` runtime library of camel-datasonnet) now follows 
the DataWeave XML semantics. Before this change, XML namespaces and attributes 
in the output failed the conversion. Worse, several XML input cases converted 
without error but gave wrong results: a SOAP selector such as 
`payload.Envelope.Body` returned `null`, and `payload.order` written as JSON 
included the attributes, namespace declarations and `~` positions of the 
DataSonnet XML model.
   
   ### XML input
   - A selector matches an element by its local name, whatever its namespace 
prefix (SOAP envelopes).
   - `ns` header directives are supported, and `.ns#name` matches only in that 
namespace (`payload.s#Envelope.o#Body` is `null`, as in DataWeave).
   - `.@` gives all the attributes, and `..*name` all the descendants (`..name` 
takes the first of an element that repeats).
   - An empty element is `null`. `.name` of an element that repeats gives the 
first, `.*name` gives all of them.
   - Attributes can be read from an element in a variable or given to a lambda 
(`o.@id`, `$.@id`).
   - `keysOf`, `sizeOf`, `mapObject`, `pluck`, `entriesOf` (with the 
attributes), `groupBy`, `orderBy`, `-`, `--` and `{ (x) }` see the child 
elements in document order.
   - An output other than XML writes the elements as DataWeave does 
(`dw.output`).
   
   ### XML output
   - Attributes `key @(name: value)`: a null attribute is written as `"null"`, 
and is left out with `skipNullOn="attributes"`.
   - Namespace-qualified keys `ns0#key` and attributes, declared on the root 
element. An undeclared prefix fails the conversion.
   - `null` is written as an empty element.
   - Arrays, object spreads and keys that repeat are written as elements that 
repeat, in the order of the script. For example `{ items: { (payload.items map 
{ item: $.sku }) } }` used to keep only the last item.
   - An element of the input is written with its children, attributes and 
namespaces. Placed under another key, it gets the attributes of that key, as in 
DataWeave.
   - Writer properties `writeDeclaration` and `skipNullOn` (`elements`, 
`attributes`, `everywhere`) are supported. `indent`, `encoding` and 
`inlineCloseOn` are formatting only.
   
   ### Performance fix in the runtime library
   DataSonnet 3.0.1.3 does not memoize lazy values: `Val.Lazy.force()` uses a 
local `lazy val`, so every use of a function argument, and every access to an 
array element, evaluates it again. Nested calls of library functions therefore 
took exponential time in the depth of the nesting. A 4-level SOAP selection did 
not finish within 20 s. With 300 items, `map`, `filter` and `orderBy` took more 
than 120 s with the library on `main`; it now takes 0.6 s. Every library 
function that uses an argument more than once now evaluates it once (`strict`, 
through the initial value of `std.foldl`, which DataSonnet does evaluate only 
once). `orderBy` computes each key once.
   
   ## Tests
   - The corpus has 29 new XML entries. H02, H07, O12 and XM04 now have real 
expectations; before, they were `@unsupported` or `?`. All 41 XML entries match 
the DataWeave CLI (`dw` 2.12). `DataWeaveCorpusTest` compares XML outputs 
without formatting or namespace-declaration placement.
   - Converter and parser unit tests cover the new constructs.
   - `camel-dataweave`: 101 tests pass. `camel-datasonnet`: 445 tests pass, 
including 360 corpus entries.
   
   ## Known differences (documented)
   A DataSonnet object cannot repeat a key. So in a JSON or Java output, 
elements that repeat under one name, and mixed-content `__text`, become an 
array, where DataWeave writes the key repeatedly. The XML output does write 
repeated elements. `..@` is still not converted: the conversion fails.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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