gnodet-bot commented on code in PR #27535:
URL: https://github.com/apache/camel/pull/27535#discussion_r4220315736


##########
components/camel-dataweave/src/main/java/org/apache/camel/component/dataweave/DataWeaveConverter.java:
##########
@@ -510,9 +649,12 @@ private String emitGroupBy(GroupByExpr gbe) {
         if (gbe.lambda() instanceof Lambda lam) {
             List<String> paramNames = lambdaParamNames(lam);
             String body = emitNode(lam.body());
-            return "c.groupBy(" + collection + ", function(" + 
paramNames.get(0) + ") " + body + ")";
+            // Jsonnet object keys must be strings. DataWeave allows any type 
as a groupBy key,
+            // so we wrap with std.toString() unconditionally to ensure valid 
Jsonnet output.
+            // If the key expression is already a string, std.toString() is a 
no-op.
+            return "c.groupBy(" + collection + ", function(" + 
paramNames.get(0) + ") std.toString(" + body + "))";
         }
-        return "c.groupBy(" + collection + ", " + emitNode(gbe.lambda()) + ")";
+        return "c.groupBy(" + collection + ", function(x) std.toString(" + 
emitNode(gbe.lambda()) + "(x)))";

Review Comment:
   ⚠️ **Bug: missing parentheses around emitted lambda**
   
   When `emitNode(gbe.lambda())` produces `function(x) x.qty`, the generated 
Jsonnet is:
   ```
   function(x) std.toString(function(x) x.qty(x))
   ```
   `(x)` binds to `x.qty` (a field access), not to `function(x) x.qty`. The 
inner lambda is never called — it is just returned as a value, then `(x)` tries 
to call the result of `x.qty`.
   
   Parenthesize the emitted node:
   ```suggestion
           return "c.groupBy(" + collection + ", function(x) std.toString((" + 
emitNode(gbe.lambda()) + ")(x)))";
   ```



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