Skip to content

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

Description

@Ariznawlll

问题

SELECT ... INTO OUTFILE ... FORMAT 'jsonline' 遇到两个相同的列别名时返回成功,但生成的每行 JSON 只保留后一列,前一列的值被静默丢弃。普通 SELECT 与 CSV 导出都保留两列;唯一别名的 JSONLINE 导出也正常。

环境

MatrixOne main commit 3a1e42b4308bd0098e055ddb9360a07f85201d9c,隔离本地单 TN、双 CN;2026-10-21。

最小复现

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

SELECT a AS x,b AS x FROM t ORDER BY id;
-- 两行分别是 (11,22)、(33,44)

SELECT a AS x,b AS x FROM t ORDER BY id
  INTO OUTFILE '/tmp/duplicate.jsonl' FORMAT 'jsonline';
-- 返回成功,文件却只有:
-- {"x":22}
-- {"x":44}

对照:SELECT a AS x,b AS y ... FORMAT 'jsonline' 导出 {"x":11,"y":22}、{"x":33,"y":44};相同重复别名导出 CSV 仍保留 11,22 和 33,44。基表本身始终是 2 行,SUM(a)=44, SUM(b)=66。

期望

JSONLINE 格式不能保留同名的两个对象字段时,应在导出前明确拒绝,不能返回成功并静默丢值;或者采用明确、可逆的唯一列名策略。

复核与定位

3 个全新数据库、每库 2 行,重复别名丢第一列 3/3;唯一别名 JSONLINE、重复别名 CSV 及原表结果对照均通过,共 27 项检查。精确命令和文件内容:/private/tmp/mo-sequence-run2-20261020/ten-bugs-1021/jsonline-duplicate-alias-repeat.jsonl。

白盒:pkg/frontend/export.go 的 constructJSONLine 按 ep.mrs.Columns 取得列名,再使用 map[string]interface{} 组装每行;相同别名写入同一个 key,后一列覆盖前一列,然后 json.Marshal 输出。与已关闭的 #29785 表现类似,但那个问题限定 Parquet 导出且代码在 export_parquet.go;当前 JSONLINE 路径仍独立复现。已检查 open/closed issue 和兼容性文档,未发现此 JSONLINE 场景的现有问题。

Activity

  1. added this to the MO-202610 milestone on Oct 21, 2026
  2. added
    kind/bug
    on Oct 21, 2026
  3. added theissue type on Oct 21, 2026
  4. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30807 at head dca0d807b3a3f382aaa8635716bc23216de18046:

    The duplicate-name guard still has a silent-data-loss edge for an empty result column name. duplicatedJSONLineColumn returns "" both when no duplicate exists and when the duplicate name itself is empty, while constructJSONLine only rejects dup != "". Thus duplicate empty headings (reachable with NAME_CONST('', ...)) pass the guard and the per-row map overwrites one value. The current unit tests cover repeated "x" but not repeated empty names.

    Please return an explicit found flag/error (or otherwise distinguish absence from an empty name) and add regression coverage for ["", ""] and an empty duplicate alongside another name, including the export error/no-bytes behavior. This is a static source review; I did not run the frontend or SQL repro locally. The submitted PR review also records an isolated helper probe for this boundary.

  5. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    QA follow-up for PR #30807, current head 3c384538553c24f63b525dd6fff7db4e6b3eee7b:

    The previously reported empty-name sentinel bug is addressed in the current source: duplicatedJSONLineColumn now returns (name, found), and the writer rejects repeated empty names before serializing rows. Regression cases cover repeated empty names, an empty duplicate followed by another duplicate, a single empty name, no output on rejection, and memory-pool balance. I reviewed the current commit diff and it contains this fix.

    Validation caveat: the PR author reports the frontend tests and live SQL/export cases passing on the branch. I did not execute those tests. The local checkout is on main at 460b96365a381e74916b044a99fc9423c33ad3fd, not the PR head, and Go is unavailable in this workspace. Commit status has no checks; the two PR-triggered E2E runs currently listed are Iceberg Connector and Connector/J pool-reset, both in progress and not targeted coverage. Existing issue assignee is already Ariznawlll; no assignment change needed. Next verification: obtain exact-head frontend package/required checks and run the regression plus live JSONLINE/CSV controls.

  6. slyunnn commented on Oct 23, 2026

    @slyunnn

    Regression and extended verification for #30703 (2026-10-23)

    Verification Environment

    • MatrixOne origin/main: bc84bd142600b745503e225cb89cb1526df8d35e — fix(plan): eliminate unobserved sorts below scalar COUNT (#30828). I fetched origin/main; the running mo-service reports this exact VCS revision, and both CN process binaries match the freshly built binary hash.
    • Topology: 2 CN / 1 TN / 1 Log service / 1 Proxy. Proxy 6001, CN1 16001, and CN2 16002 were reachable. The SQL below was executed through the real MySQL text protocol, not just connectivity-checked.
    • Associated fix: MatrixOne PR #30807, merged as 52af980b20893c59f72063c37db115bd766bb0d1 — fix(export): reject JSONLINE export with duplicate column names instead of silently dropping values (#30703).

    What Was Covered

    • OK — The original 2-row SELECT a AS x,b AS x ... INTO OUTFILE ... FORMAT 'jsonline' failed with explicit 20301 on Proxy, CN1, and CN2. No rejected output file was created. Plain SELECT retained both values; the source still had 2 rows, SUM(a)=44, and SUM(b)=66.
    • OK — Repeated empty headings produced with NAME_CONST('',...) failed with 20301 on all three endpoints and created no file.
    • OK — Unique-alias JSONLINE produced both fields and both rows on all three endpoints. A single empty heading with a distinct y heading remained valid. Duplicate-alias CSV retained both columns and values. A JSONLINE export/load and a CSV export/load control also recovered the expected (11,22) and (33,44) rows.
    • Failed — With the same duplicate x headings but 0 source rows, JSONLINE OUTFILE returned success on all three endpoints and created a 0-byte file each time. This does not lose a row, but it violates the fix's stated unconditional duplicate-name rejection and its “fail before output” behavior.

    Findings

    • The original nonempty-row silent-data-loss path is fixed on the tested main.
    • The zero-row boundary remains open. The duplicate check is currently inside constructJSONLine, which receives a batch; the current frontend unit tests construct 1-row batches and do not prove the no-batch path. The observed SQL/file behavior is direct runtime evidence; the missed-batch explanation is a source-based inference. Please validate duplicate output names before opening/writing the export, including when no result batch arrives, and add a zero-row regression.
    • Large-data regression: not needed. The contract depends on output column names and whether any result batch arrives, not row count beyond the 0/1 boundary, block size, spill, or concurrency.

    MOTR / BVT Coverage

    • A draft SQL case was prepared on an independent MOTR branch, but --record correctly failed at the zero-row assertion (13 statements reached; 12 succeeded, 1 failed). No golden result, commit, push, or PR was produced. The failing expectation was not changed to make the case pass.
    • The newly created databases, stages, and output files were cleaned up and their absence was checked. The frontend Go tests were not independently rerun here: the macOS checkout lacks its native CGo test artifact, and the available Linux container has Go 1.27.0 while this main requires 1.27.1.

    Final Conclusion

    Partially fixed. The original 2-row reproduction is fixed on the exact tested main, but duplicate-name JSONLINE export still succeeds for a 0-row result and creates an empty file. Do not treat the complete duplicate-name rejection contract as verified until that boundary is corrected and the MOTR case records and replays successfully.

  7. XuPeng-SH commented on Oct 24, 2026

    @XuPeng-SH
    Contributor

    Current-main SQL follow-up (2026-10-24)

    Tested the merged #30807 fix on isolated current main 6f773c556d4f3177f5373eb193cd576e080b662f (contains merge 52af980b20893c59f72063c37db115bd766bb0d1), using the local MySQL protocol service and a fresh QA database.

    • Plain SELECT on rows (1,11,22),(2,33,44) returned both duplicate-name values.
    • Nonempty SELECT a AS x,b AS x ... INTO OUTFILE ... FORMAT 'jsonline' was rejected with 20301 and created no file.
    • The same duplicate aliases with WHERE id > 999 returned success and created a zero-byte JSONLINE file. This reproduces the open zero-row boundary in the previous report; it does not lose row data, but it violates the unconditional duplicate-name rejection / fail-before-output contract.
    • A unique-alias zero-row export succeeded with a zero-byte file; source stayed at 2 rows, SUM(a)=44, SUM(b)=66, and the session remained usable.
    • A separate NAME_CONST('',...) probe was rejected earlier by this build with 20203, so I do not claim a current-main result for duplicate empty headings.

    Source inspection at the tested SHA finds duplicate validation in per-batch constructJSONLine; the zero-row SQL result has no batch to enter that function. This is a source-path explanation consistent with the runtime result.

    Reproducer command: timeout 90s env PYTHONPATH=/tmp/qa30766/python-deps python /workspace/qa-challenge/fixtures/current_main_6f773_30807_jsonline_duplicate_zero.py (exit 0; output log is in the local QA workspace). The issue remains open and assigned to daviszhen; assignment was not changed.

  8. XuPeng-SH commented on Oct 25, 2026

    @XuPeng-SH
    Contributor

    Fresh-round live SQL follow-up (2026-10-25)

    Runtime: fresh isolated local MatrixOne service built from main aeaa273daf588a9988ba423915d3ae6b8c82124a; executable SHA-256 450363d5ec5e693bdd7ded44565b3b0ab1addcb807d3f9569c5d5eedeb1486e4. SQL ran over the local MySQL protocol endpoint with the QA-only runner.

    Observed:

    • With two source rows, duplicate aliases in SELECT id AS repeated, payload AS repeated ... INTO OUTFILE ... FORMAT 'jsonline' failed with error 20301. No output file was created; the source rows were unchanged.
    • Unique aliases wrote both rows and both values to JSONLINE.
    • With an empty source table, the same duplicate aliases returned success and created a zero-byte file. No row value was lost, but the previously reported zero-row rejection gap remains.
    • Case-distinct aliases CaseKey and casekey produced separate JSON keys.

    The zero-row case and current source/runtime identity are newly rechecked on the pinned 2026-10-25 main. The issue remains open; its existing assignee is unchanged.

    Reproducer and logs are retained locally:

    • /workspace/qa-challenge/fixtures/round2-30807-jsonline-rows.sql
    • /workspace/qa-challenge/fixtures/round2-30807-jsonline-empty-boundary.sql
    • /workspace/qa-challenge/logs/round2-aeaa273-30807-jsonline-rows.log
    • /workspace/qa-challenge/logs/round2-aeaa273-30807-jsonline-empty-boundary.log
    • Output controls under /workspace/qa-challenge/evidence/round2-30807-*.jsonl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions