Skip to content

[#449] A metric's datatype MUST NOT accompany a value in DATA - #664

Merged
wes-johnson merged 1 commit into
eclipse-sparkplug:developfrom
wes-johnson:449-pr-a
Dec 2, 2026
Merged

wes-johnson merged 1 commit into
eclipse-sparkplug:developfrom
wes-johnson:449-pr-a

Conversation

@wes-johnson

@wes-johnson wes-johnson commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the part of #449 that is uncontroversial. Supersedes #662, which grew past what one PR should carry.

The change

The 4.0.0 features document recorded "MUST NOT in DATA" but the chapter said SHOULD NOT, so decision and text had been out of step since it was taken.

payloads-metric-datatype-not-req is now a MUST NOT over NDATA and DDATA. 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.

NCMD and DCMD are no longer covered. A Command invocation is identified by a metric datatype of Command (the schema says the command field is "present when datatype == Command instead of 'value'"), so a prohibition there would make one unidentifiable. The previous revision covered CMD; that was wrong.

The rule names an encoding, because the field it governs only exists separately in one of them. In Protocol Buffers Metric.datatype and TypedValue.datatype are separate fields 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 needed the matching change: it 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 — worded against the permission rather than naming message types, so it also covers the BIRTH and REBIRTH prohibitions in the Topics chapter without this PR asserting anything about them.

Amending typedvalue-flat instead was the other option, but it would mean a JSON DATA message could not be read without its definition — a much larger change to the encoding than this issue warrants.

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. The spJv4.0 example keeps its "datatype": "Float", which is correct: that key is the flattened TypedValue's and is required.

Three TCK corrections

  • Scored through setShouldResult, which records a MAYBE rather than a failure. Now 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/DCMD to match the assertion, which leaves the call from checkCommandTopicPayload matching nothing — that call is removed rather than left as dead code.
  • The log text quoted the old SHOULD NOT wording.

What this deliberately leaves out

A review of the earlier, wider version found that the datatype rules have drifted apart across four chapters since the metadata separation. None of that is caused by this change and none of it is fixed here:

  • payloads-metric-datatype-req still says the datatype MUST be in NBIRTH and DBIRTH, which contradicts topics-nbirth-no-metadata and topics-dbirth-no-metadata.
  • SessionEstablishmentTest enforces that side of the contradiction, so a conforming Edge Node that omits the field from its BIRTH fails the TCK today, independently of this PR.
  • Sparkplug_1_Introduction.adoc:429 still states the pre-separation rule.
  • The BIRTH prohibition is stated in the Topics chapter and again in four per-message assertions in the Payloads chapter.

Those are one problem, not four, and they are the subject of #446. Filed separately so this change can be judged on its own.

Verification

Build successful, 10/10 unit tests pass. JSON Schema valid draft 2020-12, 22/22 chapter examples validate. Broken-anchor (11) and tck-id-anomaly (7) baselines unchanged; payloads-metric-datatype-req is untouched. git diff --check clean. 2 files, +13/-7.

@ckienle ckienle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Narrowing to NDATA/DDATA addresses the CMD and Rebirth points from #662, and handing the v4 metadata drift to #446 is reasonable. TCK side looks right: the check is still called from checkDataTopicPayload (SendComplexDataTest.java:299) and setResultIfNotFail keeps a failure from being erased.

Required (outside the diff, so here): this conflicts with the spJv4.0 encoding. tck-id-payloads-json-typedvalue-flat (Payloads.adoc:3745-3748) says a Metric's TypedValue is written flat and "its datatype MUST be carried by the 'datatype' key of the enclosing Metric". In JSON the Metric's datatype key is the TypedValue's datatype, so an spJ DDATA is currently required both to carry it (typedvalue-flat) and not to (this rule), and the non-normative comment's Metric-vs-TypedValue distinction does not exist in JSON. The DDATA examples also still carry it: "datatype": "Float" at :4072 (spPv4.0) and :4098 (spJv4.0) - #662 removed those, this PR does not. (They pass the schema check because the schema leaves datatype optional.)

Either exempt spJ here (the key there is the value's datatype), or amend typedvalue-flat so that in DATA a JSON value's datatype comes from the metric's definition - then fix both examples to match.

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.*#
datatype MUST NOT be included with a metric in NDATA or DDATA messages. A metric's datatype is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required: see the review body - in spJv4.0 payloads-json-typedvalue-flat (:3745) puts the TypedValue's datatype in this same Metric datatype key, so for JSON this MUST NOT and that MUST conflict, and the Metric-vs-TypedValue distinction in the comment below does not apply. Needs an spJ exemption here or an amendment there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, and it is the publisher-side form of a problem I had only noticed on the receiver side. Fixed in 4149b1a.

payloads-json-typedvalue-flat is unconditional — a Metric's TypedValue is written flat and "its datatype MUST be carried by the 'datatype' key of the enclosing Metric" — so an spJv4.0 DDATA carrying a value must have that key. My MUST NOT said it must not. Both could not hold.

The resolution is to name the encoding, because the field the rule governs only exists separately in one of them:

A Metric's own datatype field MUST NOT be included with a metric in NDATA or DDATA messages in the Google Protocol Buffers encoding.

In Protocol Buffers Metric.datatype and TypedValue.datatype are separate fields and only the Metric's is omitted. In JSON the flattening leaves a single key which is the TypedValue's, and typedvalue-flat requires it — so there is no separate Metric datatype field there for the rule to govern. The non-normative comment now says that rather than drawing a distinction that does not exist in JSON.

Amending typedvalue-flat instead was the other option, but it would mean a JSON DATA message could not be read without its definition, which is a much larger change to the encoding than this issue warrants.

On the examples. The spJv4.0 one at :4098 is correct as it stands: that key is the flattened TypedValue's and is required. #662 removed it, which was wrong, and this PR deliberately does not.

The spPv4.0 one at :4072 was the real ambiguity, since the illustration is written in JSON notation and flattens the same way, so a single datatype key could be read as either field. Rather than delete it — the value is unreadable without it — the introducing sentence now says which one it is:

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.

The TCK side needs no change: it decodes Protocol Buffers and m.hasDatatype() is the Metric's own field, so it was already scoped to the encoding the rule now names.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoping it to the Protocol Buffers encoding is the right call, and I agree on both examples.

One piece is still open: payloads-json-typedvalue-carries-both (:3766-3769) is unchanged. It says the single JSON datatype key "represents both", so a converter "MUST set the Metric field and the TypedValue field from it". For a DDATA that sets Metric.datatype, which the new rule forbids in Protocol Buffers, so a conforming spJv4.0 DDATA converts to a non-conforming spPv4.0 one. It also contradicts the new comment, which says that key is the TypedValue's.

You had the fix in #662's 533811d (set the Metric field only where a Metric datatype is permitted). Carrying that over here closes it, and I'll approve once it lands.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carried over in de0ab60. You're right that it was missing — I cut this branch fresh from develop rather than from #662, so the carries-both fix did not come with it.

an application converting a JSON payload to the Google Protocol Buffers encoding MUST set the Metric 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.

Worded against "where the encoding does not permit it" rather than naming NDATA and DDATA, so it also covers the BIRTH and REBIRTH prohibitions in the Topics chapter without this PR asserting anything about them — those are #665's business.

A non-normative comment says why the exception exists: without it, converting a conforming JSON payload produces 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.

Build green, 22/22 examples validate, tck-id anomaly (7) and broken-anchor (11) baselines unchanged.

…e 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.

@ckienle ckienle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three points resolved: the rule is scoped to the Protocol Buffers encoding (no conflict with typedvalue-flat), both examples are right as they stand, and typedvalue-carries-both now sets the TypedValue field only where the Metric datatype field is not permitted. typedvalue-datatype-agree is conditional on a Metric carrying both, so it is unaffected. Thanks for carrying the carries-both fix over.

@wes-johnson
wes-johnson merged commit 32abf59 into eclipse-sparkplug:develop Dec 2, 2026
3 checks passed
@wes-johnson
wes-johnson deleted the 449-pr-a branch December 2, 2026 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants