Repository navigation
Description
- I have checked the existing issues.
Problem
Today MongoDB data is pulled and aggregated by an external Java/Python worker, then written to MatrixOne through JDBC/MySQL protocol:
MongoDB -> Java/Python worker -> MatrixOne CN -> MO storage
This adds another process, another network/protocol hop, and prevents MongoDB reads from participating directly in the MatrixOne execution pipeline. We want users to query MongoDB as an external table and let normal MO operators perform filter, time-window aggregation, group aggregation, join, and INSERT/REPLACE ... SELECT.
Proposed feature
Add a read-only MongoDB external table engine. Users should not need to deploy a JDBC driver, Python worker, or sidecar. The MongoDB official Go Driver v2 is linked inside the CN process, so the data path is directly:
MongoDB socket -> MO CN MongoScan -> standard batch.Batch -> MO operators/storage
Proposed SQL surface (syntax is illustrative):
CREATE MONGODB CONNECTION nesr_mongo WITH (
'hosts' = 'mongo-1:27017,mongo-2:27017',
'credential_secret_ref' = 'secret://nesr/mongodb-reader',
'tls' = 'required',
'read_concern' = 'majority'
);
CREATE EXTERNAL TABLE mongo_sensor_readings (
mongo_id VARBINARY(12) MONGODB_PATH '_id',
pump VARCHAR(20) MONGODB_PATH 'pump',
crew VARCHAR(10) MONGODB_PATH 'crew',
ts DATETIME(3) MONGODB_PATH 'ts',
value DOUBLE MONGODB_PATH 'value'
) ENGINE = MONGODB WITH (
'connection' = 'nesr_mongo',
'database' = 'nesr_source',
'collection' = 'sensor_readings'
);Simple implementation design
-
SQL/catalog
- Add
ENGINE=MONGODB, column-levelMONGODB_PATH, and a versioned MongoDB connection/table mapping. - Store credential references only. URI credentials must never enter
rel_createsql, plan, pipeline protobuf, logs, trace, orEXPLAIN.
- Add
-
Logical plan
- Reuse
plan.Node_EXTERNAL_SCANwith a newExternType_MONGODB_TBandplan.MongoScanmetadata. - Keep connection/mapping ID and expected version in the plan; the execution CN reloads and validates the catalog entry before resolving secrets.
- Reuse
-
Physical operator
- Add
pkg/sql/colexec/mongoscan.MongoScanas a dedicated source operator. Do not model a Mongo cursor as anExternalFileReader. - Use the official MongoDB Go Driver v2 in-process for authentication, TLS, topology discovery, pooling, cancellation,
find, cursor, andgetMore. - Convert BSON directly into reusable MO vectors and emit normal
batch.Batchvalues. Call()emits at most one batch and never sends terminal pipeline signals. Cursor/client cleanup must be idempotent across partialPrepare, error, cancel,Reset, andFree.
- Add
-
Pushdown
- Push safe
$matchand$projectoperations only. - Initially retain all pushed predicates as MO residual filters.
- Disable scalar predicate elimination for mixed scalar/array paths because MongoDB equality/range predicates also match array elements.
- Missing and BSON null may share SQL NULL semantics in MVP; presence-aware mappings must gate NULL pushdown.
- Push safe
-
Execution and consistency
- MVP runs on one eligible CN with
max_parallelism=1, avoiding raw-row CN-to-CN shuffle and keeping the one-hop path. - Use fixed half-open bounds such as
[watermark-overlap, statement-high)with majority reads. - Do not reopen a failed cursor inside the operator.
getMoreis not retryable; abort and roll back the MO statement, then rerun the bounded ingestion. - The default bounded mode requires append-only/immutable source rows. Mutable collections require snapshot single-cursor mode or explicit
_iddeduplication.
- MVP runs on one eligible CN with
-
Downstream aggregation
- MongoScan contains no NESR-specific aggregation. Reuse MO Filter, Sort, TimeWin, Group/MergeGroup, and Insert/Replace operators.
- Add mergeable
max_by(value, order_key, tie_key)andmax_by_non_null(...)aggregates for deterministic last-value semantics. - Current
FILL(NULL)does not generate completely missing time buckets. Add an explicit generic per-partition gap-fill mode (for exampleGAPFILL(PARTITION)) if the Python empty-minute behavior must be replaced in MO.
Initial scope
- Read-only explicit-schema external tables.
SELECT, projection/filter pushdown, residual filtering, andINSERT/REPLACE ... SELECT.- Single-CN execution first; controlled multi-CN fanout later.
- No schema inference, writes to MongoDB, change streams/CDC, or Mongo
$grouppushdown in MVP.
NESR cutover gates
- Freeze deterministic equal-timestamp semantics: select the largest
(ts, _id); this intentionally differs from the current Python cursor-order behavior. - Implement and test per-
(pump, crew)gap fill between the observed first and last minute. - Align the target primary key with the result grain. The current
(pump, datetime)key can overwrite rows when one pump belongs to two crews in the same minute; use(pump, crew, datetime)or prove/enforce crew uniqueness. - Keep target rows and watermark/backfill progress in one MO transaction.
- Differential tests must classify intentional changes (tie order, overlap/late arrivals, bootstrap behavior) separately from regressions.
Acceptance criteria
- MongoDB external
SELECTproduces correctly typed standard MO batches. - Predicate fallback never loses rows and credentials never appear in plan/pipeline/log/
EXPLAIN. MongoScan -> TimeWin/Group -> Replaceworks without a business-specific scan operator.- Cancel, cursor error, CN failure, and retry do not advance the watermark or leave partial target data.
- NESR golden fixtures cover nulls, equal timestamps, missing minutes, multiple pump/crew partitions, late arrivals, float rounding, and target-key conflicts.
- The single-CN path has no external worker/sidecar and no worker-to-MO JDBC network hop.
Activity
iamlinjunhong commentedon Jul 31, 2026
matrixone_mongodb_external_table_user_guide.md
Ariznawlll commentedon Aug 17, 2026
https://github.com/Ariznawlll/mo-test-reports/blob/codex/mongodb-external-table-cross-coverage/mongodb-external-table-test-design/README.md
测试设计, @iamlinjunhong 帮我review一下
iamlinjunhong commentedon Aug 17, 2026
结论:需要补充,而且当前版本更适合作为“完整测试设计草案”,还不能直接作为可执行的 Release Gate。
计划的类型、DDL、NULL、下推、资源生命周期覆盖已经很扎实;主要缺口在于:目标版本基线没有锁死、部分验收方法实际上不可执行,以及 NESR 的真实四集合增量链路没有成为一等测试对象。
主要发现
[P0] 目标版本与恢复策略存在过期描述
计划仍要求“修复并验证 #26485”以及“冻结 Snapshot/PITR 策略”:
但计划指定的目标提交
177a149f...已经包含合并的 PR #26495,对应策略已经落到代码中:因此这里不应继续写“待确认”,而应改成确定的期望结果和回归用例,并检查恢复后不存在孤立 mapping。
另外,本地 MatrixOne 当前 HEAD 并不是计划指定 SHA;NESR 脚本还默认使用一个可变 worktree,且没有检查提交:
建议所有报告强制记录并校验:
SHA 不匹配时直接拒绝生成正式验收报告。
[P0] “下推 vs 禁止下推”的差分 Oracle 目前不可执行
计划多次要求比较:
见 [README.md (line 315)](/Users/linjunhong/Downloads/README.md:315) 和 [README.md (line 420)](/Users/linjunhong/Downloads/README.md:420)。
但目标实现中没有公开或测试专用的“关闭 MongoDB pushdown”开关。只写这种验收方法,执行者无法稳定构造对照组。
建议二选一:
pushed=0与pushed>0的等价 SQL,并用 EXPLAIN 校验确实走了不同路径。注意:把 external scan 结果先导入本地表再查询,只能验证谓词计算,不能独立验证 BSON→MO 转换,因为数据已经经过同一个 converter。
[P0,针对 NESR 上线] 大数据门槛明显低于客户峰值模型
计划最高只有 300 万行,而且时延、吞吐、内存阈值仍未冻结:
NESR 已有客户峰值模型:
18,032,280行/10 分钟;30,054 rows/s。定义见:
建议保留 300 万行作为 nightly smoke,另加一个 NESR-CUTOVER-PERF 阻塞门槛,直接运行现有客户峰值模型,并至少采集:
docsExamined/keysExamined;[P0/P1] 没有完整验证 NESR 实际事务状态机
NESR loader 实际上不仅是“bounded ingest”。它在一个事务内完成:
实现位于:
计划需要明确增加以下断言:
pending_low/high清空;batch_filter改变时必须要求 full rebuild;FOR UPDATE串行化相同 pipeline。现有深测已经覆盖其中一部分,如 late arrival、in-place correction、tie、幂等和失败回滚:
应在总计划中直接引用并映射这些资产,而不是再写一套抽象但不可定位的 HP/DML 用例。
[P1] 缺少四集合、嵌套字段和部分失败场景
通用计划的固定夹具是单 collection、扁平字段;NESR 实际路径却是四个 collection,通过
UNION ALL汇总,并读取类似:event_timemeta.crewmeta.subject_idmnemonic/value/uom/quality/seq实际 benchmark schema 见 [run_customer_mongodb_peak_benchmark.py (line 201)](/Users/linjunhong/workspace/nesr/scripts/run_customer_mongodb_peak_benchmark.py:201)。
至少补充:
[P1] 删除与 overlap 边界需要形成明确产品契约
NESR 当前契约已经说明:
REPLACE不会删除目标表旧行。见:
计划目前只把 mutable collection/物理删除留作风险项,不足以支撑上线。建议增加四类测试:
上线前必须明确选择:源端 append/update-only 约束,或者实现明确的 range-delete/rebuild 流程。
[P1] 当前 NESR 深测不能算租户验收
现有深测使用
root和 system-scoped secret:而真实部署约定使用租户账号及 account-scoped secret:
需要增加真实租户执行:
nesr_demo:accountadmin建对象;建议新增的 NESR 门槛
最后建议把当前文档拆成三个可独立判定的套件:
这样能避免“测试项很多,但上线判定仍依赖几十个待确认 GAP”的问题。总体评价是:覆盖广度优秀,执行闭环不足;补齐上述 P0 后才适合进入正式验收。
本次仅做静态审查,没有修改计划或 NESR 文件。
结论:**需要补充,而且当前版本更适合作为“完整测试设计草案”,还不能直接作为可执行的 Release Gate。** 计划的类型、DDL、NULL、下推、资源生命周期覆盖已经很扎实;主要缺口在于:目标版本基线没有锁死、部分验收方法实际上不可执行,以及 NESR 的真实四集合增量链路没有成为一等测试对象。主要发现
[P0] 目标版本与恢复策略存在过期描述
计划仍要求“修复并验证 #26485”以及“冻结 Snapshot/PITR 策略”:
但计划指定的目标提交
177a149f...已经包含合并的 [PR #26495](https://github.com/matrixorigin/matrixone/pull/26495),对应策略已经落到代码中:因此这里不应继续写“待确认”,而应改成确定的期望结果和回归用例,并检查恢复后不存在孤立 mapping。
另外,本地 MatrixOne 当前 HEAD 并不是计划指定 SHA;NESR 脚本还默认使用一个可变 worktree,且没有检查提交:
建议所有报告强制记录并校验:
SHA 不匹配时直接拒绝生成正式验收报告。
[P0] “下推 vs 禁止下推”的差分 Oracle 目前不可执行
计划多次要求比较:
见 README.md:315 和 README.md:420。
但目标实现中没有公开或测试专用的“关闭 MongoDB pushdown”开关。只写这种验收方法,执行者无法稳定构造对照组。
建议二选一:
pushed=0与pushed>0的等价 SQL,并用 EXPLAIN 校验确实走了不同路径。注意:把 external scan 结果先导入本地表再查询,只能验证谓词计算,不能独立验证 BSON→MO 转换,因为数据已经经过同一个 converter。
[P0,针对 NESR 上线] 大数据门槛明显低于客户峰值模型
计划最高只有 300 万行,而且时延、吞吐、内存阈值仍未冻结:
NESR 已有客户峰值模型:
18,032,280行/10 分钟;30,054 rows/s。定义见:
建议保留 300 万行作为 nightly smoke,另加一个 NESR-CUTOVER-PERF 阻塞门槛,直接运行现有客户峰值模型,并至少采集:
docsExamined/keysExamined;[P0/P1] 没有完整验证 NESR 实际事务状态机
NESR loader 实际上不仅是“bounded ingest”。它在一个事务内完成:
flowchart LR A["锁定 control row"] --> B["发现稳定 high watermark"] B --> C["读取 overlap 窗口"] C --> D["聚合并写目标表"] D --> E["更新 backfill progress"] E --> F["更新 ingestion watermark"] F --> G["记录成功 run"] G --> H["提交 control/fence"]实现位于:
计划需要明确增加以下断言:
pending_low/high清空;batch_filter改变时必须要求 full rebuild;FOR UPDATE串行化相同 pipeline。现有深测已经覆盖其中一部分,如 late arrival、in-place correction、tie、幂等和失败回滚:
应在总计划中直接引用并映射这些资产,而不是再写一套抽象但不可定位的 HP/DML 用例。
[P1] 缺少四集合、嵌套字段和部分失败场景
通用计划的固定夹具是单 collection、扁平字段;NESR 实际路径却是四个 collection,通过
UNION ALL汇总,并读取类似:event_timemeta.crewmeta.subject_idmnemonic/value/uom/quality/seq实际 benchmark schema 见 run_customer_mongodb_peak_benchmark.py:201。
至少补充:
[P1] 删除与 overlap 边界需要形成明确产品契约
NESR 当前契约已经说明:
REPLACE不会删除目标表旧行。见:
计划目前只把 mutable collection/物理删除留作风险项,不足以支撑上线。建议增加四类测试:
上线前必须明确选择:源端 append/update-only 约束,或者实现明确的 range-delete/rebuild 流程。
[P1] 当前 NESR 深测不能算租户验收
现有深测使用
root和 system-scoped secret:而真实部署约定使用租户账号及 account-scoped secret:
需要增加真实租户执行:
nesr_demo:accountadmin建对象;建议新增的 NESR 门槛
最后建议把当前文档拆成三个可独立判定的套件:
这样能避免“测试项很多,但上线判定仍依赖几十个待确认 GAP”的问题。总体评价是:覆盖广度优秀,执行闭环不足;补齐上述 P0 后才适合进入正式验收。
本次仅做静态审查,没有修改计划或 NESR 文件。
Ariznawlll commentedon Aug 17, 2026
按测试设计 README 已完成一轮完整可执行范围的覆盖执行,并新增测试报告:
https://github.com/Ariznawlll/mo-test-reports/blob/codex/mongodb-external-table-cross-coverage/mongodb-external-table-test-design/TEST-REPORT.md
执行基线:
已通过:
明确未冒充通过:
上述项目当前分别受 Docker/Podman runtime 不可用、专用 recovery/big-data 环境缺失、NESR 脚本 SHA/配置/fixture 缺失阻塞。另发现 frontend/compile 完整 race 批次中存在与 MongoDB 无关的 data-branch/ISCP 既有失败,已单独列出,没有计入 MongoDB Feature 失败。
测试报告提交:08e77ca。
Ariznawlll commentedon Aug 19, 2026
测试版本
main71031d0e9e45920821d71ce03f519181d346e6693 CN / 1 DN / 3 Log;MongoDB 8.0.12 三节点 ReplicaSet;显式 schema、SCRAM-SHA-256、majority、primary原问题验证
MongoDB connection、显式 MongoDB external table、四文档 fixture 均创建成功;全列读取连续 3 次结果为 4 行、
SUM(i)=70。ReplicaSet 主节点从 0 号切换到 1 号后,外表连续 3 次仍为 4 行、SUM(i)=70。Happy Path 覆盖
SELECT、NULL/try_null、NOT NULL、时间字段和嵌套路径:代表组合通过。INSERT/UPDATE/DELETE/REPLACE直接写 MongoDB external:均返回ERROR 20301,mapping 仍可查询。Unhappy Path 覆盖
TRUNCATE TABLE mongo_events_ext:连续 3/3 返回成功,但外表仍为 4 行;普通表对照会变为 0 行。见新 Bug [Bug]: TRUNCATE succeeds without effect on MongoDB external table #27346。AUTO_INCREMENT外表:DDL 连续 3/3 被接受,扫描时返回_id到 BIGINT 的转换错误。见新 Bug [Bug]: MongoDB external table accepts AUTO_INCREMENT and fails at scan time #27347。GENERATED ALWAYS外表:DDL 连续 3/3 被接受,GENERATED ALWAYS AS (1)扫描 4 行但结果全为 NULL。见新 Bug [Bug]: MongoDB external table accepts GENERATED column but returns NULL #27348。白盒验证
不适用;本轮验证目标是公开 SQL 行为,未修改源码或新增 UT。
回归测试
待产品修复后新增 distributed SQL 回归:MongoDB external 的
TRUNCATE拒绝、AUTO_INCREMENT/GENERATED fail-closed 以及无 catalog 残留。测试证据
mongodb-external-table-test-design/README.md。测试结论
测试不通过。
Ariznawlll commentedon Sep 7, 2026
测试版本
main8edac64737db2633c250a527cffdf04707cd8c21make test-mongodb-e2e-local随机端口和临时 Secret本评论是最新
main的阶段性本地复测记录,不覆盖尚未执行的 TKE、NESR cutover、big-data、recovery 和 Chaos 门槛。原问题验证
在固定 SHA 上独立执行
make test-mongodb-e2e-local3 次。三次均退出 0,每次生成status=passed、24 个场景,三份report.json内容一致,SHA-256 均为:本轮本地范围验证了 MongoDB external table 的 DDL、读取、BSON 转换、过滤/投影、显式查询、下游算子、写入普通目标表、取消/失败回滚、连接状态和凭据轮换。测试结束后检查临时容器、Volume、Network、MO 进程和临时凭据目录,残留为 0。
上一轮关联缺陷的最新状态:
TRUNCATE已通过黑盒 E2E 验证为只读拒绝,拒绝后 MongoDB 源数据保持不变。AUTO_INCREMENT;相关 UT 在本轮连续执行 3/3 成功。尚未在本轮单独执行黑盒 SQL DDL 复测。GENERATED;相关 UT 在本轮连续执行 3/3 成功。尚未在本轮单独执行黑盒 SQL DDL 复测。Happy Path 覆盖
SHOW CONNECTIONS、SHOW CREATE TABLE元数据脱敏及 round-trip。BINARY补齐、NULL/缺失字段转换。__mo_queryfilter、允许列表 aggregation pipeline 和减少型$grouppipeline。INSERT ... SELECT写普通主键目标表、日期格式化及排序。MongoScan -> TimeWin/GAPFILL、原子聚合与 watermark、bounded ingestion 幂等 replay。Unhappy Path 覆盖
__mo_query:fail-closed,不执行危险/跨 collection/写入/JavaScript stage。EXPLAIN显式查询:连接凭据和 URI 不泄露。TRUNCATE:返回拒绝,源 collection 行数和值保持不变。max_parallelism != 1、非法 conversion、重复 path/conversion、unsupported scalar type、SET、非 NULLDEFAULT、AUTO_INCREMENT、GENERATED。白盒验证
发布前 fresh verification:
此前同一 SHA 还执行了
pkg/sql/mongodb、pkg/sql/colexec/mongoscan和 Planner Mongo 专项-count=3,结果均成功。首次完整 Unit Target 因本机磁盘空间耗尽在链接阶段失败;清理本轮构建临时文件后,目标包使用仓库mo-cgo-test构建环境串行复跑成功。该次失败判定为基础设施问题,不计入产品失败。回归测试
本轮复用了当前
main已有的官方测试资产:test/mongodb/mongodb_e2e_local.go:24 个本地黑盒场景;pkg/sql/mongodb:类型转换、mapping、predicate、endpoint/client lifecycle;pkg/sql/colexec/mongoscan:Batch、cancel/deadline、预算、cursor/client cleanup;pkg/sql/plan:MongoDB DDL、scan plan 和约束拒绝。本轮未修改产品源码、未新增回归 PR。#27347/#27348 仍需要补充公开 SQL 黑盒 DDL 回归;完整 24 类型交叉矩阵、TLS/SRV、真实多租户、MongoDB 多成员/网络故障、Snapshot/PITR、NESR 四 collection、big-data、stability 和 Chaos 尚未执行。
测试证据
test/mongodboptools/mongodb_ci.bashci_20260907T104050Z、ci_20260907T104314Z、ci_20260907T104450Zstatus=passed、cases=24;三份report.jsonSHA-256 均为fbe0cd536e6660dad2435084b0d0767dafaf8cb2421a632a99695c841eeb0f43secret-backed-ddl、show-connections-admin-metadata-redaction、show-create-redaction-roundtrip、non-admin-marker-injection-boundary、json-relaxed-extended-conversion、fixed-binary-padding、truncate-read-only-source-preserved、scan-projection-pushdown-null-conversion、prepared-scan-binary-and-text-reuse-recovery-metadata、explicit-filter-and-query-column、explicit-reducing-aggregation-pipeline、explicit-query-explain-redaction、explicit-query-fail-closed、insert-select-primary-key-targets、date-format-order-by、low-precision-temporal-residual、decoded-vector-budget-enforced、multi-batch-cancel-recovery、mongoscan-timewin-gapfill、atomic-aggregate-watermark、conversion-error-atomic-rollback、bounded-idempotent-replay、credential-generation-rotation、connection-disable-enable。本轮已执行的本地 E2E 和白盒回归未发现新的产品缺陷,#27346 的黑盒回归符合预期,#27347/#27348 的白盒拒绝路径符合预期。但原 issue 的完整验收标准尚未全部执行,不能形成通过结论。
测试结论
测试不通过。
Ariznawlll commentedon Sep 8, 2026
2026-09-08 最新 main 本地扩展测试结果
测试版本:
f72ca9efbeb3a7c673701e4a135cc6670c33cfde(二进制 SHA-2569a1c4f6edd99fef19186141c9e9606e08072fdcd6174e38244ca7c7bb8735847)pkg/sql/mongodb、pkg/sql/colexec/mongoscan的 race 测试各重复 3/3 通过。13 个失败全部对应既有问题:
ColumnExpressionExecutor.Eval越界 panic。#28337 的
$sort/$unwind在当前 main 各 3/3 通过,32/33 sort fields、199/200 unwind path segments、16/17 stages 相邻边界也通过。完整结果与复现脚本:Ariznawlll/mo-test-reports#26(commit
c2152ec)。本地可执行范围已经完成;big-data、TLS/SRV/mongos、多成员/getMore 网络故障、Snapshot/PITR、stability/Chaos、NESR cutover 仍需专用环境。
Ariznawlll commentedon Sep 8, 2026
补充完成本地 UT race 准入门槛:在同一 SHA
f72ca9efbeb3a7c673701e4a135cc6670c33cfde上,pkg/sql/mongodb、pkg/sql/colexec/mongoscan、pkg/sql/colexec/aggexec、pkg/sql/colexec/timewin均以-race -count=10通过。报告 PR 已更新到 commitb6f279d。Ariznawlll commentedon Sep 16, 2026
测试版本
mainb347a62a30719cf3f2c8ca5a2da0dcfb11639f8c原问题验证
基于
test/mongodb/mongodb_e2e_local.go的完整 fixture 执行 MongoDB 外表接入。普通外表扫描、投影、NULL/缺失字段、时间、数值、二进制和 JSON 映射连续 3/3 通过;完整 E2E 共 26 项断言通过。读路径使用只读 MongoDB 用户,源端文档在成功、失败、取消和重试后均保持不变。Happy Path 覆盖
CREATE MONGODB CONNECTION和显式字段映射创建外表,5 条确定性文档的行数、字段值、NULL 状态和时间精度均符合预期。TimeWin/Gapfill -> REPLACE的来源;目标数据与 watermark 同事务提交,重复回放不产生重复结果。Unhappy Path 覆盖
SHOW CREATE不回显凭据。$out、$merge、跨集合及未允许的显式读取操作在发起 MongoDB 操作前被拒绝,源集合文档数保持为 5。白盒验证
不适用。上述场景均从公开 SQL 接口触发;本次不修改 MatrixOne 产品代码,也未使用白盒注入替代外部可观察的验收。
回归测试
复用 MongoDB connector E2E:
test/mongodb/mongodb_e2e_local.go。该场景覆盖连接、显式映射、读路径、转换、取消、watermark、重放和凭据轮换;本次未新增产品代码。测试证据
测试结论
测试通过。