From de0ab605ebe5298393f61669ab022f01ffc80efb Mon Sep 17 00:00:00 2001 From: wes-johnson Date: Tue, 1 Dec 2026 23:02:20 +0000 Subject: [PATCH] [#449] A metric's datatype MUST NOT accompany a value in DATA The 4.0.0 features document recorded "MUST NOT in DATA" but the chapter said SHOULD NOT, so the decision and the text had been out of step since it was taken. A datatype in a DATA message is redundant once the metric is defined, and one that disagrees with the definition is an ambiguity the specification does not resolve. Removing the field removes the ambiguity rather than having to define it. payloads-metric-datatype-not-req is now a MUST NOT over NDATA and DDATA, in the Google Protocol Buffers encoding. NCMD and DCMD are no longer covered: a Command invocation is identified by a metric datatype of Command, so a prohibition there would make one unidentifiable. The rule names an encoding because the field it governs only exists separately in one of them. A Metric's own datatype field and the datatype of the TypedValue carrying the value are separate fields in Protocol Buffers, and only the Metric's is omitted. The JSON encoding flattens a Metric's TypedValue into the enclosing Metric, so a metric carrying a value has a single datatype key which is the TypedValue's and which payloads-json-typedvalue-flat requires. Without naming the encoding, an spJv4.0 DATA message would be required both to carry that key and not to. payloads-json-typedvalue-carries-both required a converting application to set both the Metric field and the TypedValue field from that single key, which would turn a conforming JSON payload into a Protocol Buffers payload breaking the rule the JSON payload was keeping. It now sets the TypedValue field only where the Metric datatype field is not permitted. The structural illustration of the spPv4.0 DDATA message now says which datatype it shows, since the same flattening makes a single key ambiguous there too. Three TCK corrections go with it: The check was scored through setShouldResult, which records a MAYBE rather than a failure. It now uses setResultIfNotFail, so a MUST is recorded as a failure and one violating message is not erased by the next conforming one. The topic filter drops NCMD and DCMD to match the assertion, which leaves the call from checkCommandTopicPayload matching nothing, so that call is removed. The log text quoted the old SHOULD NOT wording and now quotes the requirement. --- .../chapters/Sparkplug_6_Payloads.adoc | 24 ++++++++++++++++--- .../tck/test/edge/SendComplexDataTest.java | 12 +++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc index ead1c438..40193499 100644 --- a/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc +++ b/specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc @@ -820,7 +820,19 @@ than for a metric. A metric's properties are carried in its properties field.*# ** [tck-testable tck-id-payloads-metric-datatype-req]#[yellow-background]*[tck-id-payloads-metric-datatype-req] The datatype MUST be included with each metric definition in NBIRTH and DBIRTH messages.*# ** [tck-testable tck-id-payloads-metric-datatype-not-req]#[yellow-background]*[tck-id-payloads-metric-datatype-not-req] The -datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages.*# +Metric's own datatype field MUST NOT be included with a metric in NDATA or DDATA messages in the +Google Protocol Buffers encoding. A metric's datatype is established by the message that defines +it, and a change of datatype is published by amending that definition rather than alongside a +value.*# +*** Non-normative comment: a Metric's own datatype field and the datatype of the TypedValue that +carries the value are separate fields in that encoding, and only the Metric's is omitted. The +TypedValue's selects the field the value occupies and is therefore structural rather than metadata. +The JSON encoding flattens a Metric's TypedValue into the enclosing Metric, as the +link:#payloads_json_typed_values[Typed Values] section requires, so a metric carrying a value has a +single 'datatype' key which is the TypedValue's. There is no separate Metric datatype field there +for this rule to govern, which is why it names the Protocol Buffers encoding. +*** Non-normative comment: NCMD and DCMD are not covered, because a Command invocation is +identified by a metric datatype of Command. * *quality* ** This defines the quality of the value associated with the metric. It is defined in the link:#payloads_p_quality[Quality] section. This property is optional and is only required if the @@ -3754,7 +3766,11 @@ Google Protocol Buffers encoding, the two MUST be equal, and the same applies to [tck-testable tck-id-payloads-json-typedvalue-carries-both]#[yellow-background]*[tck-id-payloads-json-typedvalue-carries-both] The single 'datatype' and 'is_null' key a flattened JSON value carries represents both, so an application converting a JSON payload to the Google Protocol Buffers encoding MUST set the Metric -field and the TypedValue field from it.*# +field and the TypedValue field from it, except that where the Protocol Buffers encoding does not +permit the Metric datatype field it sets the TypedValue field only.*# +Non-normative comment: without that exception, converting a conforming JSON payload would produce a +Protocol Buffers payload that breaks the rule the JSON payload was keeping, because the one JSON +key stands for two fields of which only one is permitted. [tck-testable tck-id-payloads-json-parameter-is-null]#[yellow-background]*[tck-id-payloads-json-parameter-is-null] A Template.Parameter whose value is null MUST carry 'is_null' set to true and omit 'value', as any @@ -4045,7 +4061,9 @@ Sparkplug JSON payload MUST validate against the JSON Schema below.*# The following is a non-normative example of one DDATA message shown in both encodings, so the two may be compared directly. The payload reports a single aliased Float metric. -The spPv4.0 form, shown as a structural illustration of the Protocol Buffers message: +The spPv4.0 form, shown as a structural illustration of the Protocol Buffers message. The datatype +shown is the TypedValue's, which the message carries; the Metric's own datatype field is absent, as +a DATA message requires: ---- Acme/Dublin/Packaging/spPv4.0/DDATA/EdgeNode1/Line3 diff --git a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java index 191832cb..82755d77 100644 --- a/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java +++ b/tck/src/main/java/org/eclipse/sparkplug/tck/test/edge/SendComplexDataTest.java @@ -308,7 +308,6 @@ private void checkCommandTopicPayload(final @NotNull String clientId, final @Not final PayloadOrBuilder sparkplugPayload = Utils.getSparkplugPayload(packet); if (sparkplugPayload != null) { checkAliasInData(sparkplugPayload, topic); - checkMetricsDataTypeNotRec(sparkplugPayload, topic); checkPayloadsNameRequirement(sparkplugPayload); } else { logger.error("Skip Edge payload validation - no sparkplug payload."); @@ -486,10 +485,11 @@ public void checkAliasInData(final @NotNull PayloadOrBuilder sparkplugPayload, S id = ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ) public void checkMetricsDataTypeNotRec(final @NotNull PayloadOrBuilder sparkplugPayload, String topic) { logger.debug( - "Check Req: The datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages."); + "Check Req: The datatype MUST NOT be included with a metric in NDATA or DDATA messages."); boolean isValid = true; - if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA) || topic.contains(TOPIC_PATH_NCMD) - || topic.contains(TOPIC_PATH_DCMD)) { + // The Metric's own datatype field, which is separate from the TypedValue's. NCMD and DCMD + // are not covered: a Command invocation is identified by a metric datatype of Command. + if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA)) { for (Metric m : sparkplugPayload.getContent().getMetricsList()) { if (m.hasDatatype()) { logger.info("On topic={} - Invalid payload: {}", topic, sparkplugPayload); @@ -497,8 +497,8 @@ public void checkMetricsDataTypeNotRec(final @NotNull PayloadOrBuilder sparkplug break; } } - testResults.put(ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ, - Utils.setShouldResult(isValid, PAYLOADS_METRIC_DATATYPE_NOT_REQ)); + Utils.setResultIfNotFail(testResults, isValid, ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ, + PAYLOADS_METRIC_DATATYPE_NOT_REQ); } }