How to map a custom payloadShape in a streamProces...
# umh-support
s
Lets say I have a payload shape like payloadShapes: work-order: # Shape name (referenced in models) description: "Work order record" fields: orderId: _type: string productId: _type: string quantity: _type: number status: _type: string # created/in-progress/completed operatorId: _type: string timestamp: _type: string # ISO 8601 format How do I map that in a streamProcessor? I tried something in the lines of work-order: | ({ orderId: "", productId: "", quantity: 0, status: "", operatorId: "", timestamp: "", }) But that gives an error about work-order being a timeseries-string.
m
Hey @sander075071, The mapping needs to be a nested YAML object with one entry per field, not a single string with a JS object literal. That's why it treats work-order as a plain timeseries-string, a bare key with a string value is read as one scalar field, not a multi-field shape. Instead of: yaml mapping: work-order: | ({ orderId: "", productId: "", quantity: 0, status: "", operatorId: "", timestamp: "" }) do this: yaml mapping: work-order: orderId: ".orderId" productId: ".productId" quantity: ".quantity" status: ".status" operatorId: ".operatorId" timestamp: ".timestamp" Each field gets its own key matching your payload shape's fields, and the value is a reference into whatever you defined under sources: (or a constant/expression), not a JS object. This mirrors how our reference example handles a multi-field model (a motor sub-model with speed/current/temperature/status is mapped the same nested way).
d
why not use the nodered_js processor? Way easier to code input: uns: umh_topics: ["umh.v1.enterprise.site._raw.work_order_events"] consumer_group: work-order-builder pipeline: processors: - nodered_js: code: | msg.payload = { orderId: msg.payload.orderId, productId: msg.payload.productId, quantity: msg.payload.qty, status: "created", operatorId: msg.payload.operator, timestamp: new Date().toISOString() }; msg.meta.umh_topic = "umh.v1.enterprise.site._work-order_v1."; return msg; output: uns: bridged_by: work-order-builder
s
Hi, now I have mapping: work-order: orderId: ".orderId ?? ''" productId: ".productId ?? ''" quantity: ".quantity ?? ''" status: ".status ?? ''" operatorId: ".operatorId ?? ''" timestamp: ".timestamp ?? ''" (I don't have clue what is in my source. Can I log somewhere what the streamProcessor sees as source?) Anyway, with this mapping I get errors about the virtual_path does not match the schema, is work-order.orderId instead of work-order
Turns out this is intended behaviour. The streamProcessor will flatten 'work-order' to 'work-order.orderId', etc.
8 Views