Skip to content

[Bug]: MongoDB external table accepts GENERATED column but returns NULL #27348

Closed

Description

@Ariznawlll

Description

MongoDB external-table DDL accepts GENERATED ALWAYS, but the generated expression is not evaluated during the external scan. A generated column defined as a constant is returned as NULL for every row.

Environment

Steps to reproduce

With a valid MongoDB connection and a collection containing four documents, execute:

CREATE EXTERNAL TABLE ext_bad_gen (
  id VARCHAR(8) MONGODB_PATH '_id',
  x INT GENERATED ALWAYS AS (1) STORED
) ENGINE=MONGODB WITH (
  'connection'='valid_connection',
  'database'='test_db',
  'collection'='events',
  'schema_mode'='explicit'
);
SELECT COUNT(*), MIN(x), MAX(x) FROM ext_bad_gen;

Actual behavior

The DDL succeeds. The query returns four rows, but MIN(x) and MAX(x) are both NULL; SHOW CREATE TABLE also shows a MongoDB path for the generated column.

Expected behavior

Until generated-column semantics are explicitly supported for MongoDB external tables, the DDL must be rejected atomically. If accepted in a future contract, the expression must evaluate to 1 for every row and must not be treated as a remote MongoDB field.

Stability and controls

  • DDL acceptance and incorrect result reproduced 3/3.
  • A normal explicit-schema MongoDB external table scans four rows with correct mapped values.
  • No partial catalog object was observed after the successful but invalid definition.

Evidence

TKE terminal output and the test design report record three rounds returning 4, -999, -999 after NULL normalization.

Code analysis

The external-table schema builder appears to retain generated metadata while also assigning a MongoDB path, causing the scan to read a missing remote field instead of evaluating the generated expression; exact implementation location requires maintainer confirmation.

Regression coverage

Add a DDL regression asserting that GENERATED ALWAYS on a MongoDB external table is rejected and no mapping remains.

Related

Source feature issue: #26229.

Activity

  1. added
    kind/bug
    on Aug 19, 2026
  2. added this to the MO-202608 milestone on Aug 19, 2026
  3. added theissue type on Aug 19, 2026
  4. removed theissue type on Aug 19, 2026
  5. added theissue type on Aug 19, 2026
  6. added
    ai-easy
    on Aug 21, 2026
  7. Ariznawlll commented on Aug 21, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:853fb9bf9b1d0ea1aa09b3cc7443ad3828ffab4a
    • 部署方式:本地 1 CN/1 TN/1 Log,MySQL 127.0.0.1:6003;MongoDB 8.0.12 ReplicaSet rs0
    • 测试日期:2026-08-21

    原问题验证

    配置真实 MongoDB connection,并在 test_db.events 中保留 4 条源数据。连续 3 轮执行 issue 原始 CREATE EXTERNAL TABLE,包含 x INT GENERATED ALWAYS AS (1) STORED。每轮均返回 ERROR 20105: not supported: MongoDB external table does not support generated column 'x',不再创建后返回 NULL。

    Happy Path 覆盖

    1. MongoDB connection 创建成功,SHOW MONGODB CONNECTIONS 可见 source。
    2. 每轮拒绝后普通 parent table 保持可用,行数为 2。
    3. MongoDB 源 collection 仍为 4 行,未被 DDL 修改。

    Unhappy Path 覆盖

    1. MongoDB external table 的 STORED generated column 连续 3/3 被拒绝。
    2. 拒绝后 mo_catalog.mo_tables 中目标表数量为 0。
    3. mo_catalog.mo_mongodb_tables 中目标映射数量为 0,未产生部分 catalog 状态。

    白盒验证

    planner focused test TestBuildMongoDBExternalTableRejectsGeneratedColumns 连续 3 次通过。

    回归测试

    已加入 MOTR PR #116,case:14_issue_regression.issue_27348_mongodb_generated_rejection。

    测试证据

    MOTR PR #116,提交 bc1126e5;真实 MongoDB 3 轮输出均为 20105 且 catalog 计数为 0。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions