Skip to content

[Bug]: Parquet export marks BINARY/VARBINARY as UTF-8 strings and emits unreadable files #31495

Open

Description

@Ariznawlll

Description

Parquet export labels BINARY and VARBINARY bytes as a UTF-8 string instead of unannotated binary. A legal binary value containing 0xFF makes the exported file unreadable by PyArrow even though SELECT ... INTO OUTFILE / MODUMP QUERY_RESULT report success. BLOB from the same row is correctly exported as binary.

Environment

  • Branch: main
  • Commit: f847803802289b2b2d0df4f0a2f842c2804b823a (git_version() = f847803802)
  • Deployment: isolated local standalone, one CN, MySQL port 49301, 2026-10-28. PyArrow 24.0.0 and PyMySQL 1.4.6 used only to validate exported bytes/readback. Synthetic data only.

Steps to reproduce

The output paths must be writable by the MO service and readable by the verification client.

CREATE DATABASE pq_binary_repro;
USE pq_binary_repro;
CREATE TABLE t(id INT PRIMARY KEY, b BINARY(4), v VARBINARY(4), x BLOB);
INSERT INTO t VALUES (1, X'78FF79', X'78FF79', X'78FF79');
SELECT HEX(b),HEX(v),HEX(x) FROM t;
-- 78FF7900, 78FF79, 78FF79
SELECT id,b,v FROM t INTO OUTFILE '/tmp/pq_binary_repro.parquet' FORMAT 'parquet';
SELECT id,x FROM t INTO OUTFILE '/tmp/pq_blob_control.parquet' FORMAT 'parquet';
import pyarrow.parquet as pq
print(pq.read_schema('/tmp/pq_binary_repro.parquet'))
print(pq.read_table('/tmp/pq_binary_repro.parquet').to_pylist())
print(pq.read_schema('/tmp/pq_blob_control.parquet'))
print(pq.read_table('/tmp/pq_blob_control.parquet').to_pylist())

The same failure is reachable through the new MODUMP QUERY_RESULT Parquet route: enable save_query_result, run /* save_result */ SELECT id,v FROM t ORDER BY id, capture last_query_id(), then MODUMP QUERY_RESULT '<id>' INTO '/tmp/modump_binary.parquet' and read it with PyArrow.

Actual behavior

  • SELECT INTO OUTFILE and MODUMP QUERY_RESULT both succeed.
  • Both Parquet schemas mark the VARBINARY column as v: string; the BINARY column is likewise b: string.
  • pq.read_table(...) fails with UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 1: invalid start byte.
  • Control: BLOB is x: binary and reads as b'x\xffy'; ASCII-only VARBINARY reads normally, showing that invalid UTF-8 bytes trigger the false string annotation.
  • MO's own LOAD DATA INFILE ... FORMAT 'parquet' restores HEX(v)=78FF79, so this is an interoperability/schema defect rather than a demonstrated MO-internal data-loss bug.

Expected behavior

BINARY/VARBINARY Parquet fields should be represented as binary byte arrays without the UTF-8 string logical annotation, preserving arbitrary bytes and remaining readable by standard Parquet clients. If a value cannot be exported in a chosen format, the export should fail rather than report success with a file that its declared schema cannot decode.

Stability and controls

  • Reproducer: 3/3 independent fresh databases (qmodfail_06, _07, _08) on the pinned SHA. Each run reproduced both MODUMP and ordinary SELECT INTO OUTFILE with VARBINARY X'78FF79'.
  • Control: the same runs successfully read ASCII-only VARBINARY Parquet; a separate BLOB control read as real binary. MODUMP ... .jsonl represents the same VARBINARY as {"$binary":"eP95"}.
  • Failure atomicity/data check: the exports reported success, so no SQL rollback occurred; source rows remained HEX(v)=78FF79. MO Parquet LOAD restored the same bytes, while PyArrow failed at UTF-8 decoding.

Evidence

Saved local reproducer and exact output: /private/tmp/mo-explore-run-20261028/modump_failure_file.py (rounds 6–8) and /private/tmp/mo-explore-run-20261028/parquet_binary_schema.py (BINARY/BLOB control). The runnable SQL/PyArrow snippet above is the portable reproducer. Pinned-source evidence: buildParquetNode maps MySQL VARCHAR/VAR_STRING/STRING to parquet.String() without checking BINARY_FLAG, whereas the BLOB branch does; getValueFromVector supplies raw bytes for T_binary/T_varbinary.

Code analysis

Confirmed: the writer advertises a UTF-8 string logical type for the binary-family columns in the reproducer, then writes raw non-UTF-8 bytes. The buildParquetNode type switch above explains the contrast with the correctly typed BLOB control. The exact MySQL-type/flag mapping from MO's result metadata to this switch is an implementation detail to verify in the fix; the observed Parquet schema is direct evidence of the wrong output contract.

Regression coverage

Add Parquet export/readback tests for BINARY(4), VARBINARY(4) and BLOB containing 00, FF, padding and NULL, through both SELECT INTO OUTFILE and MODUMP QUERY_RESULT; verify with an independent Parquet reader and MO LOAD, not only row counts. Include an ASCII-only control and ensure the declared logical/physical schema matches the bytes.

Related

  • #30570 added suffix-aware MODUMP Parquet output, but this bug also affects the pre-existing SELECT INTO OUTFILE path.
  • #29845 requests broader Arrow/Parquet conversion profiles for other extended types; this issue is a concrete malformed Parquet file for supported BINARY/VARBINARY export, not an unsupported conversion request.
  • #30635 concerns JSONLINE binary round-trip and is a separate format/path.

Activity

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

    @XuPeng-SH
    Contributor

    QA status for merged main f73b4e93aafd0ec75b4766b03777811233a1f0c6 (#31100): the merged change explicitly addresses binary-flagged Parquet columns using unannotated BYTE_ARRAY and includes serialized-footer/library-reader tests, according to the PR. Those are author-reported results, not independently executed in this environment.

    Resource headroom under the existing guard is insufficient here for the affected frontend test link or a current-head service. The original BINARY/VARBINARY FF cases through both OUTFILE and MODUMP, independent PyArrow schema/byte readback, MO LOAD, NULL/padding and BLOB/ASCII controls remain unverified locally. Handing off to QA for acceptance.

  5. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。普通 SELECT INTO OUTFILE 的 binary schema 和回读已修复;但 MODUMP QUERY_RESULT 对合法 ASCII 的 VARBINARY 仍成功导出为 Parquet string,不符合本 issue 要求的未标 UTF-8 的 binary 类型。非 UTF-8 数据现已报错且未生成文件,不再复现原来的成功生成不可读文件。

    关键证据

    • 研发交接中相关的 fix(outfile): accept FIELDS ESCAPED BY/LINES STARTING BY and reject non-UTF-8 Parquet exports (#30710) #31100 已合入,merge commit f73b4e93aafd0ec75b4766b03777811233a1f0c6 在测试时官方 main 9e29011e7313a57962adc00963baa659d1e81e37 的祖先链;实际服务 git_version() 为 9e29011e73。fix(outfile): accept FIELDS ESCAPED BY/LINES STARTING BY and reject non-UTF-8 Parquet exports (#30710) #31100 主要修复 OUTFILE,未明确声称覆盖本 issue 的 MODUMP 整条路径。
    • 隔离本机单 CN/TN/Log,PyArrow 24.0.0:普通 OUTFILE 对 BINARY(4)、VARBINARY(4)、BLOB 的 78FF79、610062、NULL,3/3 得到 binary schema 和正确字节;MO LOAD DATA ... format='parquet' 回读 3/3,分别得到定长填充 78FF7900、变长 78FF79 和对应 NULL。MOTR Dev/api updates #287 中普通 OUTFILE + 回读回归定向 3/3,最新 PR 的离线 CI 检查通过。
    • 按原 issue 的 save_query_result / last_query_id() / MODUMP QUERY_RESULT 路径,VARBINARY 行 X'76616C6964' 加 NULL,导出成功但独立 PyArrow 3/3 读到 schema v: string,值为 Python 字符串 'valid' 而不是 binary / b'valid'。每轮使用独立临时库和文件并清理。
    • 同一路径对合法 X'78FF79' 3/3 返回 20301 invalid UTF-8 value for VARBINARY,目标文件不存在且源数据不变;这符合 issue 的失败原子性兜底,但仍不能证明 MODUMP 的 binary schema 已修复。上述失败没有被写成 MOTR 成功 golden。

    待解决点

    请核对 MODUMP 保存及重建结果元数据时的 binary 类型/flag 保留,补齐合法 ASCII 和任意字节的 Parquet binary schema 与独立客户端回读;普通 OUTFILE 回归已单独覆盖,完整 MOTR suite 和完整产品 CI 未运行。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions