Skip to content

[Bug] JSONLine external-table projection fails beyond the second column #26264

Closed

Description

@Ariznawlll

Description

JSONLine external tables with object-shaped records cannot read projected columns from the third declared column onward. The first two columns can be queried normally, but reading the third or later column, or using COUNT(*), returns an internal index out of range error.

The same behavior occurs for a writable external table after inserting rows and for a read-only external table created over the emitted files.

Version

Reproduced three times on origin/main at cd8e175349932ccf4be8d388080a0c3310e538ac.

Steps to reproduce

Use a local stage directory and create a writable JSONLine external table:

CREATE STAGE jsonline_audit_stage URL = 'file:///tmp/jsonline-audit';

CREATE EXTERNAL TABLE ext_rows (
  a INT,
  b VARCHAR(20),
  c TEXT,
  d DECIMAL(10,2),
  e JSON,
  f BOOL
)
INFILE {
  'filepath' = 'stage://jsonline_audit_stage/rows_*.jsonl',
  'format' = 'jsonline',
  'jsondata' = 'object',
  'write_file_pattern' = 'stage://jsonline_audit_stage/rows_%U.jsonl'
};

INSERT INTO ext_rows VALUES
  (1, 'one', 'alpha', 1.25, '{"n":1}', true),
  (2, 'two', 'beta', 2.50, '{"n":2}', false);

-- Both queries complete normally.
SELECT a, b FROM ext_rows ORDER BY a;

-- Each of the following fails.
SELECT c FROM ext_rows ORDER BY a;
SELECT d FROM ext_rows ORDER BY a;
SELECT e FROM ext_rows ORDER BY a;
SELECT f FROM ext_rows ORDER BY a;
SELECT COUNT(*) FROM ext_rows;

To check the read-only form, recreate ext_rows without write_file_pattern, pointing its filepath at the same rows_*.jsonl files. The projected-column and aggregate queries fail in the same way.

Actual behavior

SELECT a, b returns the two expected rows. Queries that access c or a later column, and COUNT(*), return error 20101 with an internal index out of range stack rooted in pkg/sql/colexec/external.getFieldFromLine.

Expected behavior

All declared JSONLine columns should be independently selectable, and aggregates should complete normally for both writable and read-only external tables.

Impact

Queries over a valid JSONLine external table can become unavailable solely because the selected projection changes. This affects existing files as well as files emitted through the writable external-table path.

Activity

  1. added this to the MO-202607 milestone on Jul 27, 2026
  2. added
    kind/bug
    on Jul 27, 2026
  3. added theissue type on Jul 27, 2026
  4. added
    severity/s0
    and removed on Jul 27, 2026
  5. added
    ai-easy
    on Jul 29, 2026
  6. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    创建 6 列 JSONLine object 外表,写入普通值与 NULL 行;第三列以后 c/d/e/f 的投影、稀疏重排投影以及 COUNT(*) 均返回正确结果。将同一批文件改为只读外表后重复验证,完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. 可写外表中 a,b 和第三列以后的 c,d,f 均可独立读取。
    2. select f,c,a,e ... order by a desc 的稀疏、逆序投影保持物理列映射正确。
    3. 只读外表复用已生成文件,后段列投影和 COUNT(*)=3 均正确。

    Unhappy Path 覆盖

    1. NULL/缺失值行在后段列投影中保持 NULL,没有越界或错列。
    2. 白盒覆盖非法 physical field index 与缺失列定义,均返回受控错误,不发生 panic。

    白盒验证

    TestJSONLineObjectProjection* 连续 3 轮通过;external 定向 -race 通过。

    回归测试

    修复提交 6ffb9b524 已扩展 test/distributed/cases/stage/writable_external_table.sql,并加入 reader_csv_projection_test.go。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugphase/testingseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions