Skip to content

fix(ducklake): data_extra double-encoded JSON broke Aleg correlation (#790) - #791

Merged
adubovikov merged 2 commits into
homer11from
fix/790-data-extra-double-encoded-json
Jun 11, 2026
Merged

fix(ducklake): data_extra double-encoded JSON broke Aleg correlation (#790)#791
adubovikov merged 2 commits into
homer11from
fix/790-data-extra-double-encoded-json

Conversation

@adubovikov

@adubovikov adubovikov commented Jun 11, 2026

Copy link
Copy Markdown
Member

Fixes #790.

Root cause

This is a regression introduced in v11.0.236 by the DuckDB 1.5.3 / upstream duckdb-go/v2 migration. As part of that bump, the HEP write path started passing the data_extra cell to the DuckDB Appender as a plain Go string. The upstream Appender runs json.Marshal() on values destined for JSON columns, so the JSON object text got re-encoded into a JSON string scalar:

expected: {"x_call_id":"aleg-call-id"}
stored:   "{\"x_call_id\":\"aleg-call-id\"}"

The correlation script looks up peer legs with json_extract_string(data_extra, '$.x_call_id'), which returns NULL for a string scalar, so the query succeeds but matches nothing. That's why the reporter saw no errors and no timeouts: the engine ran fine, correlated 0 rows, and correlation: reloaded scripts count=1 was the only relevant log line. Increasing HOMER_COORDINATOR_CORRELATION_* had no effect for the same reason.

Fix

  • data_extra is now handed to the Appender as json.RawMessage, which is stored verbatim as a JSON object (pooled SIP buffers and the cached simple/version-only cells).
  • BuildInsertMultiValues (Line Protocol ingest, PCAP import) accepts json.RawMessage and pooled *[]byte data_extra cells.
  • Bundled sip_call.lua now extracts x_call_id from inside the data_extra JSON (and falls back to the cid column when it differs from session_id), so opening the B-leg also pulls in the A-leg; previously only A to B worked.
  • Unmodified copies of the bundled script in the settings DB are upgraded automatically on startup via SHA256 fingerprint, preserving status; operator-edited scripts are never touched.

Tests

  • New regression test TestAppenderJSONColumnNotDoubleEncoded: writes through a real DuckDB Appender into a JSON column and asserts json_type(data_extra) = 'OBJECT' plus x_call_id extraction (fails on the old code).
  • New TestSeedDefaultCorrelationScript_UpgradesLegacyTemplate for the in-place seed upgrade.
  • Full go test over storage/..., coordinator/..., scripting/..., lineprotoreceiver, decoder, writer is green; go vet clean.
  • Verified end-to-end: all-in-one instance, two HEP legs ingested with X-CID, transaction view returns both session_ids in both directions.

Caveat for existing data

Rows ingested on 11.0.236-11.0.241 remain double-encoded on disk; the fix applies to new writes. They can age out with retention or be repaired once with:

UPDATE homer_lake.hep_proto_1_call
SET data_extra = json_extract(data_extra, '$')::JSON
WHERE json_type(data_extra) = 'VARCHAR';

Bumps VERSION_APPLICATION to 11.0.242.

Since the upstream duckdb-go/v2 bump (11.0.236), the Appender json.Marshal()s
values for JSON columns, so passing data_extra as a Go string stored it as a
JSON string scalar instead of an object. json_extract_string(data_extra,
'$.x_call_id') then returned NULL and Lua call correlation silently found no
peer legs (github.com//issues/790).

- pass pooled and cached data_extra cells to the Appender as json.RawMessage
- accept RawMessage/*[]byte data_extra in BuildInsertMultiValues (LP, PCAP import)
- sip_call.lua: extract x_call_id from the data_extra JSON string and use the
  cid column when it differs from session_id, fixing B-leg -> A-leg lookup
- upgrade unmodified legacy seed scripts in place (SHA256 fingerprint),
  preserving status; operator-edited scripts stay untouched
- regression tests: Appender JSON round-trip (json_type must be OBJECT) and
  legacy seed upgrade
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Alexandr Dubovikov seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@adubovikov adubovikov changed the title Fix/790 data extra double encoded json fix(ducklake): data_extra double-encoded JSON broke Aleg correlation (#790) Jun 11, 2026
@adubovikov
adubovikov merged commit c1029dc into homer11 Jun 11, 2026
9 of 10 checks passed
@adubovikov
adubovikov deleted the fix/790-data-extra-double-encoded-json branch June 11, 2026 07:48
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.

Aleg correlation stopped working

2 participants