Skip to content

fix(export): reject JSONLINE export with duplicate column names instead of silently dropping values (#30703) - #30807

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
daviszhen:fix-30703-jsonline-dup-alias
Oct 23, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
daviszhen:fix-30703-jsonline-dup-alias

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #30703

What this PR does / why we need it:

SELECT ... INTO OUTFILE ... FORMAT 'jsonline' built each row as a
map[string]interface{} keyed by the output column names. When two SELECT
aliases collide, the later column overwrote the earlier one on every row and
the export still returned success — silently dropping data (issue's example:
SELECT a AS x, b AS x produced only {"x":22} / {"x":44}).

A JSON object cannot carry duplicate member names, so the export now fails
fast before any row is written: constructJSONLine checks the resolved column
names up front and rejects duplicates with
invalid input: jsonline export cannot write duplicate column names ('x'); give every output column a unique alias.
CSV and parquet exports are untouched (they are positional, both duplicated
aliases keep both columns).

Validation

  • New regressions in pkg/frontend/export_test.go: helper-level
    TestDuplicatedJSONLineColumn and end-to-end
    TestJSONLineExportRejectsDuplicateAliases (batch through
    constructJSONLine, asserts an error carrying duplicate column names
    reaches the batch channel and no bytes are emitted).
  • Live end-to-end on the branch binary (docker, single-process):
    • duplicate aliases: statement fails with ERROR 20301 carrying the duplicate
      name and a fix hint; no output file is created;
    • unique-alias control: exports {"x":11,"x2":22} / {"x":33,"x2":44};
    • duplicated-alias CSV export keeps both columns (i.e. this change is
      JSONLINE-only), matching pre-change CSV behavior.

@daviszhen
daviszhen requested a review from XuPeng-SH as a code owner October 22, 2026 05:37
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Exact-head evidence for fix-30703-jsonline-dup-alias:

Live end-to-end on the branch binary (docker single-process instance built from this head):

CREATE TABLE t(id INT PRIMARY KEY, a INT, b INT);
INSERT INTO t VALUES (1,11,22),(2,33,44);

-- unique aliases export normally:
SELECT a AS x, b AS x2 FROM t ORDER BY id INTO OUTFILE '/tmp/pr2_ok.jsonl' FORMAT 'jsonline';
-- > {"x":11,"x2":22}  /  {"x":33,"x2":44}

-- duplicate aliases now fail explicitly and write nothing:
SELECT a AS x, b AS x FROM t ORDER BY id INTO OUTFILE '/tmp/pr2_dup.jsonl' FORMAT 'jsonline';
-- ERROR 20301 (HY000): invalid input: jsonline export cannot write duplicate
--      column names ('x'); give every output column a unique alias
-- /tmp/pr2_dup.jsonl does not exist

Duplicated-alias CSV export keeps both columns (positional writer untouched by this change).
Unit regressions: TestDuplicatedJSONLineColumn, TestJSONLineExportRejectsDuplicateAliases (green on this head).

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: dca0d807b3a3f382aaa8635716bc23216de18046

"interrupted"

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dca0d807b3a3f382aaa8635716bc23216de18046

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: dca0d807b3a3f382aaa8635716bc23216de18046

Assessment: request_changes

Reviewed the complete two-file delta and export lifecycle. Rejecting duplicates in the shared JSON writer is reasonable, but the empty-string sentinel leaves a reachable silent-data-loss case unresolved.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/frontend/export.go:1387: Export SELECT NAME_CONST('', 11), NAME_CONST('', 22) INTO OUTFILE '/tmp/duplicate_empty.jsonl' FORMAT 'jsonline'. Both resolved column names are empty strings.
    Impact: The helper returns the repeated empty name, which this condition interprets as no duplicate. Serialization therefore discards 11 and retains only {"":22}. An empty duplicate also hides later nonempty duplicates. Return an explicit found boolean or error, and cover these cases in regression tests.
    Evidence: NameConstHeading and the result-metadata path preserve empty names; NAME_CONST validation accepts them. A verbatim-helper probe passed the ordinary-name control but failed both empty-name rejection tests, reproducing the overwrite. See duplicate-probe.log and checks/1792657183717105357-3.json (exit 1).

Validation:

  • Isolation preflight passed. The standard-library-only helper probe ran through the supplied test-exec with the assigned caches.

  • git diff --check passed; receipt checks/1792657257900381834-3.json matches the assigned clean HEAD and diff-check.log.

  • Frozen exact-head CI records successful UT, SCA, build and substantive BVT jobs. Existing tests omit the demonstrated boundary.

  • Full review and probe provenance retained under /home/xupeng/.local/state/mo-bot/jobs/f36284542f4b3bb8b3db1a37/attempt-1/review-evidence.json.

Limitations:

  • The probe executes the extracted helper, not the frontend. SQL reachability was established by source tracing; no live SQL or native package tests were rerun.

  • local_validation was empty; raw CI and author-reported live-test logs were unavailable.

  • No benchmark was run. Added work is one temporary map and column scan per JSON batch; other export formats and ordinary SQL paths are unchanged.

@daviszhen

Copy link
Copy Markdown
Contributor Author

CI follow-up note: the first attempt of SCA Test on Linux/arm64 failed without preserving logs (the log artifact returned BlobNotFound — an Actions log-storage drop on attempt 1), and its only reported annotation was the generic failure marker with no finding attached. A rerun of the failed jobs (attempt 2) completed the full static analysis cleanly on the same head dca0d807: SCA, UT, both BVT legs, coverage and CI Required are all green. No code change was needed for that leg — the local lint pass over the changed pkg/frontend package showed only pre-existing environment-side typecheck noise (stock cdc_test/computation_wrapper_test composite-literal patterns plus a host cgo probe quirk), none related to this diff.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed the empty-name P2 from review 5611254397 in commit 885313c570.

duplicatedJSONLineColumn now returns (name, found). The JSONLINE writer uses the explicit boolean, so a repeated empty name cannot be confused with the absence of a duplicate. A single empty name remains valid.

The writer regression exercises ordinary duplicates, two empty names, empty duplicates before later nonempty duplicates, unique nonempty names, and a single empty name. It checks that rejected batches emit no output bytes, accepted batches retain all values, and the memory pool is balanced on both paths. Both empty-duplicate cases failed against the original production code before the fix.

Local validation on the final source:

  • Complete pkg/frontend suite with -vet=all -count=1: PASS (15.120s).
  • Configured incremental golangci-lint over pkg/frontend: 0 issues.
  • git diff --check: PASS.

The previous head's required CI was green. This push starts a separate CI run; these local results do not claim that the new CI has finished. Please re-review the correction.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed head 885313c570ecf55b6d0b6aef55388d19791d50d2, including the complete two-file delta and the export error-consumer path. No new blocking finding from source review.

The empty-name P2 in review 5611254397 is addressed: duplicate detection now returns an explicit found boolean, so two empty names cannot be mistaken for no duplicate or hide subsequent duplicate names. A single empty name remains accepted. The writer rejects before serializing any rows, reports the error through the existing batch channel, and retains deferred batch cleanup. The consumer checks the error before attempting index ordering, so this error result does not need a batch index to propagate correctly. CSV/Parquet dispatch is unchanged.

The added writer tests cover ordinary duplicates, repeated empty names, empty duplicates preceding other duplicates, unique names and a single empty name; they check error/no emitted bytes or exact retained values, plus balanced memory-pool usage.

Validation: git diff --check passed. This pass was source/test review, not an independent runtime rerun. The author's complete frontend suite and lint results are reported evidence, not tests I executed. The new head's build, UT, SCA, coverage and Connector/J checks were not all complete at the final status check; previous-head green checks should not substitute for them. No remaining source-level request-changes finding from this review; wait for required checks before merging. Discussion comment only, not formal approval.

@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Oct 23, 2026
@daviszhen
daviszhen requested a review from XuPeng-SH October 23, 2026 03:54
@XuPeng-SH

XuPeng-SH commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dd8c208144f83bfc2a329f1081e1aae80b85d531

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: dd8c208144f83bfc2a329f1081e1aae80b85d531

Assessment: approve

Reviewed the complete three-file delta and affected callers. The JSONLINE encoder correctly rejects duplicate names, including empty names, through existing error and cleanup paths. Rejecting ambiguous output avoids silently renaming columns or changing the format. Account cleanup now closes tenant sessions before deletion while preserving the admin connection. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Frozen exact-head evidence reports successful Linux UT, SCA, coverage and BVT checks.

  • Isolation preflight passed; native build provenance matched 194 current inputs and 63 retained artifacts.

  • Eight public SQL diagnostic cases passed under -race: duplicate and empty names return error 20301 without publishing a file; valid names, inferred format, CSV preservation and session reuse behaved correctly.

  • TestPrivilegeCacheTracksRemoteCatalogChanges passed under -race once, then twice in one process, including account-removal assertions and shared-cluster reuse.

  • Reconciled command, clean-source fingerprint, exit receipts and terminal logs. Evidence manifest: /home/xupeng/.local/state/mo-bot/jobs/89fe3bb83ca09b37b9a03ecc/attempt-1/review-evidence.json. Source remained unchanged.

Limitations:

  • Public SQL diagnostics used a test-only overlay; full CI was not rerun locally.

  • The historical slow cleanup failure was not reproduced locally.

  • No throughput benchmark was run. Added work is one O(column-count) temporary set per JSONLINE batch; ordinary SQL, CSV and parquet execution paths are unchanged.

@mergify mergify Bot added the queued label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-23 04:18 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-10-23 05:34 UTC · at f6d919fd091dafdec9b8faf627252bad38ff1b64

This pull request spent 1 hour 15 minutes 32 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: JSONLINE OUTFILE silently drops a column when SELECT aliases are duplicated

3 participants