Skip to content

[Bug]: read_json silently ignores lines= and unknown orient values #31395

Closed

Description

@Ariznawlll

DRAFT 18 (SDK, 2026-10-27) — to be filed

Title: [Bug]: read_json accepts lines=/orient= but ignores lines and maps unsupported orients silently

Description

LoadDataManager.read_json (load_data.py) is documented as pandas-compatible (the parameter names come straight from pandas.read_json: lines, orient, compression). The actual handling:

def read_json(self, filepath_or_buffer, table, lines: bool = True, orient='records', compression=None, inline=False, **kwargs):
    ...
    if inline:
        return self.read_json_inline(data=filepath_or_buffer, table=table, orient=orient, **kwargs)
    if orient == 'records':
        structure_str = 'object'
    elif orient == 'values':
        structure_str = 'array'
    else:
        structure_str = 'object'   # silently default every other orient
    return self.from_file(..., format=LoadDataFormat.JSONLINE.value, jsondata=structure_str, ...)

Two contract breaks:

  1. lines is never referenced in the body — it is silently discarded. In pandas, lines=True means JSON-Lines, lines=False (with orient='records') means a standard JSON array file ([{"a":1},{"a":2}]). The SDK always loads as JSONLINE/jsondata=object, so a plain records-array file (the most common single-file export shape from json.dump and from other databases' export tools) fails or misparses while the caller explicitly said lines=False — the parameter that would have selected the right format does nothing.
  2. Every orient besides 'records'/'values' silently becomes 'object' — pandas' orient='split' ([columns/data shape]), 'index', 'columns', 'table' each have well-defined layouts; users passing them get the default mapping with no warning, so a split-oriented export loads as garbage/errors with zero hint at the cause. (pandas would honor or at least error on unknown combos.)

Also read_json_inline mirrors the same mapping (orient → jsontype_str with the same silent else-branch), and neither path validates that orient='values'-loaded arrays actually pair with a table whose column order matches — secondary, but part of the same "pandas-flavored but not pandas-semantics" gap.

Reproduction

# standard JSON array file (written by json.dump(records_list, f))
client.load_data.read_json('events.json', table='events', lines=False)
# treated identically to lines=True: JSONLINE format, jsondata=object
# → parse error / truncated load, despite lines=False explicitly requesting array semantics

client.load_data.read_json('split.json', table='t', orient='split')
# silently loaded with jsondata=object — no error naming the unsupported orient

Impact

  • pandas users porting ingestion code (a stated goal of the API naming) get wrong behavior exactly when they've read the docs and set the right flag (lines=False). Failures surface as server-side parse errors (or partial data) far from the misleading parameter.
  • orient values that could be supported by mapping (split → array-of-rows after transpose is not even attempted) are silently misinterpreted rather than raising.
  • Silent-parameter-drop is the recurring SDK disease (see also stage enable dropped — filed today); this instance blocks a primary ingest format.

Expected behavior

  1. Honor lines=False + orient='records' by loading as a standard JSON array (server JSONLINE format with jsondata=object expects line-delimited objects; array files need either jsondata='array' or a pre-pass — either the server's array mode or a documented, raised NotImplementedError).
  2. Raise ValueError(f"unsupported orient={orient!r}") for orients with no defined mapping instead of defaulting.
  3. Either implement the remaining pandas orients or strike them from the docstring.
  4. Tests: lines=False loads [{...}] file correctly; orient='split' raises; lines=True (JSONL) unchanged.

Activity

  1. added
    kind/bug
    on Oct 27, 2026
  2. added this to the MO-202610 milestone on Oct 27, 2026
  3. added theissue type on Oct 27, 2026
  4. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。当前 main 的实际服务验证确认 lines=False 仍未生效,标准 JSON 数组无法通过该入口导入;这是本 issue 的原有问题,不重复提单。

    关键证据

    • 版本:main@c6683bd2f531dcaa80e153c0924dac619c49dc9d,同提交构建的隔离双 CN,仓库 Python SDK;3 个新建库,分别测试同步和异步入口。
    • 输入文件是合法 JSON 数组 [{"id":1,"v":"alpha"},{"id":2,"v":"beta"}],目标为 id INT PRIMARY KEY, v VARCHAR(20)。调用 read_json(path, table=..., lines=False, orient='records'),6/6 报 20301 invalid input: not a object;目标均保持空表,随后 SELECT 1 正常。
    • 同内容转成逐行对象并使用 lines=True, orient='records',同步/异步 6/6 精确导入两行;逐行数组加 orient='values' 也 6/6 正确。对象文件误指定 orient='values' 时 6/6 拒绝且目标空表。
    • 当前生成的 SQL 仍固定指定 format='jsonline', jsondata='object';本次结果支持原 issue 中 lines 未生效的判断,不宣称其他 orient 或半途失败场景也已验证。精确记录为本地 sdk_json4_probe.json 与 sdk_json4_probe_2.log,代码入口见 load_data.py。

    待解决点

    • 明确支持非逐行 JSON 或在 SDK 层对不支持的 lines=False 给出清晰拒绝,并分别覆盖同步、异步、正常 JSON Lines 与失败后目标状态。
  5. added a commit that references this issue on Oct 30, 2026
    bbfe556
  6. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31774 (main bbfe55669a1440424914d45a283a1d0e36f722fa): please verify JSON lines/orient handling, unsupported inputs and target-table atomicity. This isolated QA run inspected the issue and merged source but did not run tests or a live MatrixOne service at this SHA because resource headroom under the existing guard was insufficient. Earlier QA counterexamples and PR author-reported validation remain scoped to their recorded versions and are not results of this QA run.

  7. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。read_json 对不支持的非 JSON Lines 输入和 orient 明确拒绝,支持的 JSON Lines 导入仍正常;这次验收的是明确拒绝方案,不表示已支持普通 JSON 数组文件。

    关键证据

    • 官方 main@d39d8a40343ccd40bf665036388df7a40ee867f8;修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 合并提交 bbfe55669a1440424914d45a283a1d0e36f722fa 位于其祖先链;实际运行二进制和 SDK 源码与完整 SHA 一致。本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12,客户端与 CN 共用测试文件目录。
    • 三个独立库,合法数组文件配 lines=False,以及 orient='split'、orient='unknown',同步和异步接口均在写入前抛 ValueError;每次拒绝后目标表仍为空。
    • 同步和异步分别从真实 JSON Lines 文件导入 records 对象和 values 数组,均得到精确两行 (1,'alpha'),(2,'beta'),SELECT 1 正常;每轮测试文件和库均清理。
    • 回归已加入 MOTR #295,定向 3/3 通过、0 skipped。

    待解决点

    • 不支持的 orient 未实现转换;本轮未覆盖远端 stage、压缩和中途 I/O 故障,也未运行完整 MOTR suite。Add build constraint to assembly source files #295 尚未合入;SDK 回归需显式启用、匹配源码和客户端/CN 共享目录,默认 SKIP 不计通过。
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