Skip to content

[Bug]: JSONLINE INTO OUTFILE round-trip silently stores Base64 text in binary columns #30635

Closed

Description

@Ariznawlll

Description

SELECT ... INTO OUTFILE FORMAT 'jsonline' exports VARBINARY/BLOB as Base64 JSON strings, but MatrixOne's LOAD DATA INFILE ... format='jsonline', jsondata='object' loads those strings literally into the original binary columns. The export and import both report success while bytes change. This is an internal export→import data-correctness failure, not a MySQL compatibility claim.

Environment

  • Branch: official main
  • MatrixOne commit: 7c146f4adbf068dd0c06b377157cfb7d7698b1eb
  • mo-dump commit (independent control only): 324c33dbdc7075cd5d7beaafd1e15c76709dd442
  • Deployment: isolated local standalone, 1 CN / 1 TN / 1 LOG, SQL on 127.0.0.1:6001; 2026-10-20

Steps to reproduce

Use a fresh, writable local file path for every run (replace the /tmp/... paths if needed):

CREATE DATABASE qa_outfile_binary;
CREATE TABLE qa_outfile_binary.src (id INT PRIMARY KEY, raw VARBINARY(16));
INSERT INTO qa_outfile_binary.src VALUES (1, X'00FF'), (2, X'AB00'), (3, NULL);
SELECT id, HEX(raw) FROM qa_outfile_binary.src ORDER BY id;

SELECT id, raw FROM qa_outfile_binary.src ORDER BY id
  INTO OUTFILE '/tmp/qa_outfile_binary_1.jsonl' FORMAT 'jsonline';

CREATE TABLE qa_outfile_binary.dst LIKE qa_outfile_binary.src;
LOAD DATA INFILE {
  'filepath'='/tmp/qa_outfile_binary_1.jsonl',
  'format'='jsonline',
  'jsondata'='object'
} INTO TABLE qa_outfile_binary.dst;
SELECT id, HEX(raw) FROM qa_outfile_binary.dst ORDER BY id;

The generated JSONL lines for the non-NULL rows contain "raw":"AP8=" and "raw":"qwA=".

Actual behavior

Both statements succeed. Source bytes are 00FF, AB00, NULL; restored bytes are 4150383D (AP8=), 7177413D (qwA=), NULL. Row count and IDs remain 3 and 1/2/3, so count-only validation misses the corruption. A BLOB control changes 00FF to 4150383D as well.

Expected behavior

MatrixOne's own JSONLINE export and JSONLINE load should round-trip binary columns exactly, or reject the incompatible load/export path explicitly before reporting successful restoration. It must not silently replace binary payloads with their Base64 text representation.

Stability and controls

  • Reproducer: 3/3 independent JSONL export files and fresh destination tables, each with exact wrong bytes above.
  • Controls: the same source VARBINARY rows round-trip exactly through SELECT ... INTO OUTFILE FORMAT 'csv' + LOAD DATA LOCAL INFILE (00FF, AB00, NULL), and through FORMAT 'parquet' + Parquet LOAD DATA INFILE with the same exact values. A separate scalar/JSON/NULL table round-tripped exactly through JSONLINE.
  • Source remained 00FF/AB00/NULL after all runs; connection SELECT 1 succeeded. This is not an exporter setup, file-path, or general loader failure.

Evidence

The minimal SQL and exact output above are independently reproducible. Local test artifacts and a run checkpoint are under /private/tmp/mo-dump-cont-20261020.o75VwQ/outfile_1020 and /private/tmp/mo-dump-cont-20261020.o75VwQ/continuation.md; these are local evidence locations, not public download links.

Code analysis

  • pkg/frontend/export.go:1386-1388: vectorValueToJSON explicitly Base64-encodes BINARY, VARBINARY, and BLOB.
  • pkg/sql/plan/build_ddl.go:8463-8471: the writable-external-table binder already rejects these types for JSONLINE and comments that the JSONLINE reader does not decode Base64. The SELECT INTO OUTFILE path does not apply an equivalent compatibility guard.
  • This code explains the observed mismatch; the direct SQL reproducer, not the source comment alone, establishes the user-visible bug.

Regression coverage

Add a SQL-level export→load round-trip for BINARY/VARBINARY/BLOB with NUL and non-UTF-8 bytes, plus NULL and text/Parquet controls; assert exact HEX values and explicit failure if the path remains unsupported. No repository regression test or PR was added in this exploration turn.

Related

Activity

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

    @XuPeng-SH
    Contributor

    合入后 QA 复核发现一个旧文件兼容缺口(静态代码路径,当前容器缺 Go/mo-service,未能本地启动集群复跑):这个 issue 记录的旧版 OUTFILE 行是 {"raw":"AP8="},对应原始字节 X'00FF'。新 jsonLineScalarText 只解码 {"$binary":"AP8="};裸 JSON 字符串会直接 fmt.Sprint(node) 并作为文本写入,合入的回归测试也明确断言 {"raw":"AP8="} 仍得到字节 AP8=。因此升级后再 LOAD 旧版 MatrixOne JSONL 归档仍会把 00FF 还原为 ASCII AP8=(HEX 4150383D),原 issue 的数据往返失败对历史文件仍成立。建议补一个可识别的旧版导出兼容策略(例如显式格式版本/加载选项),同时继续保留手写纯文本的无损导入;请在确认策略后补历史文件回归。

  5. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:c232b6d2a1b5a94ac624c4954586569841c1e153(执行前与 GitHub 官方 main 核对)
    • 修复:fix(external): decode base64 on jsonline load for binary columns (#30635) #30663 已合入,merge commit 9a7ea39bd4a432c454960c9e7296482fec818382 已包含在上述 main
    • 部署方式:隔离本地嵌入集群,1 CN / 1 TN / 1 LogService;真实 MySQL TCP/SQL;每轮新建文件及目标表
    • 测试日期:2026-10-22

    原问题验证

    在同一版本上用原始二进制值 X'00FF'、X'AB00'、NULL 比较两条路径,每条重复 3 轮:

    1. 当前版本 SELECT id,raw ... INTO OUTFILE ... FORMAT 'jsonline' 生成 {"raw":{"$binary":"AP8="}} 等包装对象,再 LOAD DATA INFILE ... format='jsonline', jsondata='object':3/3 轮均恢复 HEX(raw)=00FF, AB00, NULL,与源表逐值一致。
    2. 将此 issue 报告时 MatrixOne 自己生成的旧版 JSONL 行({"id":1,"raw":"AP8="}、{"id":2,"raw":"qwA="}、{"id":3,"raw":null})在同一最新版 main 上加载:3/3 轮 SQL 均报告成功,但实际 HEX(raw)=4150383D, 7177413D, NULL,前两项是 Base64 文本的 ASCII 字节,不是原字节 00FF, AB00。因此新版导出往返已修复,历史 MatrixOne JSONL 归档路径仍会静默损坏;这与 issue 中的原始旧文件复现一致,不能据新版路径通过而关闭整个问题。

    执行命令:go test ./pkg/tests/issues -run '^TestIssue30635PublicSQLCurrentAndLegacyJSONL$' -count=1 -v -timeout=10m。该独立 QA 探针内部对原始/当前路径各运行 3 轮,使用隔离 worktree 的临时测试文件,未提交产品仓库。三轮实际输出均为:

    source=[{00FF true} {AB00 true} { false}]
    current=[{00FF true} {AB00 true} { false}]
    legacy=[{4150383D true} {7177413D true} { false}]
    

    Happy Path 覆盖

    1. 当前 JSONLINE 二进制包装格式→导入,VARBINARY 两种含 NUL/非 UTF-8 字节及 NULL:3/3 精确一致;源表保持不变,三轮后清理表和数据库成功。
    2. pkg/sql/colexec/external 中的包装 BINARY/VARBINARY/BLOB、对象/数组、普通文本透传、非二进制列等定向 Go 测试在该 SHA 上 -count=3 通过。

    Unhappy Path 覆盖

    1. 旧版 MatrixOne 裸 Base64 JSONL 文件:3/3 静默写入错误字节,行数/ID/NULL 均正常,说明只检查条数无法发现问题;源表与当前格式目标表未受影响。
    2. 定向 Go 用例对非法 $binary Base64 对象/数组均要求报错,不将其静默解释为文本;-count=3 通过。
    3. 包装内容解码后恰好是 \\N 的边界按非 NULL 保留,原始 \\N 和 JSON null 按 NULL 处理;定向 Go 用例 -count=3 通过。

    白盒验证

    pkg/sql/colexec/external/reader_csv_projection_test.go 中 TestJsonLineBinaryBase64Roundtrip 明确将旧版裸 "AP8=" 的期望设为字符串 AP8=,因此现有测试证明新格式设计选择,但不能证明旧 MatrixOne 归档恢复正确。本轮没有运行 -race;该问题是确定性的值错误,不是并发竞态。

    回归测试

    测试证据

    • 上述 SQL 探针命令与三轮完整 HEX 实际输出;源码回归、PR 和 CI 链接见上,可用报告中的两条 JSONL 行独立重放。
    • 既有 静态路径提示 与本轮实际 SQL 结果一致;本评论提供的是当前官方 main 的独立动态验收,不重复宣称它已通过。

    测试结论

    测试不通过。

  6. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    合并后 QA 跟进 — PR #30832

    PR #30832 已于 2026-10-23 合并,merge commit 5fe68a88e48ae115856b18deaeecc4953101a0be(head 6bd96852121915fd2a03e0b1c85bbfb4f46b72cb)。其变更在 JSONLINE 读取端新增显式 json_binary='legacy_base64',仅对 BINARY/VARBINARY/BLOB 的裸 Base64 字符串解码;默认文本语义不变,包装格式仍可读。PR review 报告了 reader/planner 定向测试及 JSONLINE SQL 用例通过;这是 review 的测试记录,本轮没有在本地独立运行。

    该实现覆盖了本 issue 记录的旧版裸 Base64 归档恢复路径,建议由 Ariznawlll 在合并后的 main 上复核该选项端到端恢复 00FF/AB00、NULL 和默认纯文本控制。Issue 保持 open,待独立验收后再决定关闭。

  7. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    QA follow-up on PR #29554 head 9cf7b6922192ea4d3158d1954a9af2c36fd2fca8 (2026-10-23), with a baseline correction: the pre-merge first-parent head 9d4e8b3130 has isJsonNullSentinel(valN) in both JSONLINE object and array paths; base 5fb586e1 does not. The merge resolution drops this first-parent behavior. Current head returns csvparser.Field{Val: val} without setting IsNull, and getColData uses field.IsNull to append SQL NULL, so a raw JSON string equal to "\\N" is no longer marked NULL after LOAD. This is static code comparison only; I did not run local Go tests or a MatrixOne server.

    I submitted REQUEST_CHANGES on PR #29554 for this first-parent regression and added a PR comment correcting my earlier baseline wording. Please restore the raw-node sentinel decision for both object and array paths and cover JSON NULL plus a $binary payload decoding to bytes 5C4E (which must remain non-NULL).

  8. Ariznawlll commented on Oct 24, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;commit:6fb6531432aaec8c1fbd98a30364941559e0e1d6。执行前核对官方 main;运行二进制的 Go 构建元数据 vcs.revision 为相同完整 SHA,隔离 worktree 已跟踪源码无改动。
    • 历史文件兼容补丁:PR #30832 已合入,merge commit 5fe68a88e48ae115856b18deaeecc4953101a0be 是上述 main 的祖先。
    • 部署方式:隔离本地 macOS arm64,1 LogService / 1 TN / 1 CN,真实 MySQL TCP/SQL(本地 6001),DISK-V2;独立数据库及文件。测试日期:2026-10-24。

    原问题验证

    原始 VARBINARY/BLOB 数据两行分别为 00FF/AB00、AB00/00FF,另有 NULL 行。当前版本 SELECT ... INTO OUTFILE FORMAT 'jsonline' 再默认 LOAD DATA INFILE,3/3 轮目标逐值等于源表:00FF/AB00、AB00/00FF、NULL/NULL,不是 Base64 文本的 ASCII 字节。

    旧版 MatrixOne 裸 Base64 JSONLINE 形状也独立复核:对 "AP8="/"qwA="、"qwA="/"AP8="、NULL 使用显式 json_binary='legacy_base64' 读取,3/3 轮恢复为相同的原始字节和 NULL;源表保持 3 行不变。

    Happy Path 覆盖

    1. 当前包装格式导出→导入,VARBINARY、BLOB、NUL/非 UTF-8 字节、NULL;源/目标逐值比对,3/3 均 0 差异。
    2. 旧裸 Base64 文件使用显式兼容选项导入,3/3 均得 00FF/AB00、AB00/00FF、NULL/NULL;MOTR 阶段还用 SQL 生成相同旧文件形状,并在每轮清除 stage 文件和数据库。
    3. 默认模式不猜测裸字符串是 Base64:旧文件中的 AP8=、qwA= 仍作为普通文本写入,实际 HEX 为 4150383D、7177413D;这是明确选项的正常文本对照,不是把这些错字节写成历史恢复成功 golden。

    Unhappy Path 覆盖

    1. 显式 legacy 模式遇到非法 Base64 !!,3/3 均返回 ERROR 20301;拒绝后的目标表计数为 0,源表仍为 3 行,无部分导入。
    2. 不涉及并发竞态、故障注入或大规模阈值,本轮未宣称相应覆盖。

    白盒验证

    本次以公开 SQL 和实际文件/stage 验收字节值,未新增 Go UT/-race;没有以只检查行数或 Go 单元测试替代二进制值比较。

    回归测试

    已在 MOTR PR #278 head 4f5a55f9199bba02d27973f52d45341747f2b293 增加 issue_30635_jsonline_binary_legacy_roundtrip.test/.result;定向 3/3、99/99 条语句通过,完整 suite 中本用例也通过。完整 14_issue_regression suite 为 669 成功、22 失败、34 跳过(725 总计);失败是其他具名用例,不宣称全绿。PR 离线检查 四项通过;本 head 的线上 MatrixOne 集成 CI 未运行。

    测试证据

    • 隔离 SQL 探针:/private/tmp/mo-qa-30681-30650-30635-DafFfy/validate_three.py,三轮输出含准确 HEX、默认文本对照与非法载荷拒绝。
    • MOTR PR #278 的 SQL/result 配对及 离线 CI。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions