Skip to content

[Bug]: Starlark procedures reject or lose SQL NULL on inbound conversion #29151

Closed

Description

@Ariznawlll

Description

Starlark stored procedures do not preserve SQL NULL consistently at the SQL/Starlark boundary:

  • Passing NULL to any IN parameter aborts CALL with type invalid is not a supported starlark type.
  • mo.getvar() on a SQL user variable containing NULL returns the same error.
  • mo.sql("select null") returns an empty string cell instead of Starlark None, so NULL and '' become indistinguishable.
  • The reverse direction already works: assigning Starlark None to an OUT parameter or through mo.setvar() produces SQL NULL.

This makes the conversion asymmetric and prevents procedures from handling nullable inputs without client-side sentinel values.

Environment

  • Branch: main
  • Commit: 56f7d1eae392b5f3de33e1ea43c916956c50b833
  • Deployment: isolated local one-LOG/one-TN/two-CN cluster

Steps to reproduce

create database slk_null_repro;
use slk_null_repro;

create procedure p_in(in i int, in s varchar, out o varchar) language 'starlark'
$$
out_o = "{}:{}".format(i, s)
$$;

call p_in(null, 'x', @o);
call p_in(1, null, @o);

create procedure p_get_null(out o varchar) language 'starlark'
$$
v, err = mo.getvar("x")
out_o = "ERR:" + err if err != None else str(v)
$$;

set @x = null;
call p_get_null(@o);
select @o;

create procedure p_sql_null(out o varchar) language 'starlark'
$$
rows, err = mo.sql("select null")
out_o = "ERR:" + err if err != None else str(rows)
$$;

call p_sql_null(@o);
select @o;

Actual behavior

  • Both nullable IN calls fail with invalid input: type invalid is not a supported starlark type.
  • mo.getvar("x") returns that error when @x is NULL.
  • mo.sql("select null") produces [("",)], which is identical to selecting an empty string.

Expected behavior

SQL NULL should map to Starlark None consistently for procedure arguments, mo.getvar, and cells returned by mo.sql. Existing reverse conversions from None to SQL NULL should remain unchanged.

Stability and controls

  • IN int NULL, IN varchar NULL, and both NULL: each reproduced 3/3 on CN1 and 3/3 on CN2.
  • Every connection remained usable immediately after the rejected call.
  • Non-NULL scalar arguments work on the same procedures.
  • OUT None and mo.setvar(..., None) both correctly produce SQL NULL, confirming that only the inbound conversion paths are incomplete.

Code analysis

convertToStarlarkValue switches on reflect.Value.Kind() but has no invalid/nil case, so SQL NULL reaches the default error path. mo.sql converts every cell through ExecResult.GetString, which loses the distinction between NULL and an empty string.

Regression coverage

Add a small procedure regression for nullable IN values of at least one numeric and one string type, mo.getvar(NULL), and mo.sql returning both NULL and '' in adjacent columns. This belongs in MOTR or the current Starlark procedure suite; no big-data coverage is needed.

Activity

  1. added this to the MO-202609 milestone on Sep 20, 2026
  2. added
    kind/bug
    on Sep 20, 2026
  3. added theissue type on Sep 20, 2026
  4. self-assigned this
    on Sep 20, 2026
  5. added
    severity/s1
    and removed on Oct 13, 2026
  6. VioletQwQ-0 commented on Oct 19, 2026

    @VioletQwQ-0
    Collaborator

    @Ariznawlll 请验证 SQL NULL / Starlark None 的原 issue 范围。Issue 保持 OPEN,等待明确的版本、环境及终态 PASS/FAIL。

    修复 PR:#30131(已合并,非 Draft);最终 PR head e588adb249c3571bd41c4dc7edf53cea80938efe,merge commit 959d12d3b9e10d828e95876fce88b46511294c58。本轮查询到的 main 为 e0314478159c80b062483c307180b02dc009dbc0;以下本地执行绑定 merge commit,不冒充在最新 main 或部署环境运行。

    已完成的开发侧自测:

    • Darwin/arm64、Go 1.27.1、GOMAXPROCS=4,使用仓库 CGo wrapper 和校验通过的 native 产物。三个命名测试 TestConvertToStarlarkValueNull、TestStarlarkVariablesNull、TestStarlarkSQLNullCells 实际执行 PASS;完整 pkg/frontend 一次 PASS。覆盖 NULL/空串/零值、None 反向转换、错误后恢复及 SQL cell 读取失败不泄露部分结果。
    • 同一 merge tree,复用仓库隔离的 1 LOG / 1 TN / 2 CN fixture;服务及 ISCP readiness 后,通过真实 MySQL 入口运行未修改的 test/distributed/cases/procedure/starlark_null.sql/.result。每个 CN 连续两次正常比较,四次均 total=33, success=33, failed=0, ignored=0,每次执行后独立确认测试数据库已删除。fixture 已关闭;临时 harness 已从工作树移除,保留在维护证据中。
    • canonical BVT 覆盖 nullable INT/VARCHAR IN、0/空串/普通值对照、INOUT、mo.getvar(NULL) 与空串、mo.sql 多行多列 NULL/空串、OUT None 及 mo.setvar(..., None)。SQL/result 内容哈希与源文件一致,未重新生成预期结果。
    • 可复核的历史 CI BVT:run 38440669730 / artifact 11838377527,同一用例 33/33。ZIP SHA256 2a4232e69cf6ef9a25d31d0877317b65ec4d88a7a5b4f4fce62fceb236ae244f;其测试 head 与最终 merge 的五个 PR 变更文件 blob 全部一致,仅复用该 NULL contract 证据。

    执行入口:仓库 mo-cgo-test -v -count=1 -p=1 -timeout=180s -run '^(TestConvertToStarlarkValueNull|TestStarlarkVariablesNull|TestStarlarkSQLNullCells)$' ./pkg/frontend;完整包使用 -count=1 -p=1 -timeout=240s ./pkg/frontend。本地 BVT harness 用同树 pkg/embed 双 CN fixture,直接调用 mo-tester 正常 run / ignore / nometa / pprof(对应 -n -g -o -p),未使用 genrs。

    边界与剩余验收:

    • 最终 head 的 required CI run 38517242283 不是全绿:依赖 job 取消导致 CI Required 失败;TKE run 38517617354 在镜像构建网络超时失败,TKE BVT skipped。以上不算产品 SQL FAIL,也不算部署 PASS;本轮未 rerun。
    • 请在包含上述 merge 的实际待验收构建和目标客户端/双 CN 部署中复核原 nullable IN、getvar、相邻 NULL/空串 SQL cell;保留原 issue 的逐 CN 重复和同连接后续可用性检查,并确认既有 OUT/setvar None 与非 NULL 对照不回归。无需扩展大数据或性能矩阵。
    • PASS:NULL 一致映射 None,空串/0/普通值不混淆,反向 None→SQL NULL 不回归,CALL 后连接可用;请附构建 SHA/版本、环境、执行结果。FAIL:任一原症状仍可复现或同 scope 回归,请保留 SQL/结果和环境,并保持 OPEN 标记 test-verification-failed。

    QA Decision: required=yes;用户可见 SQL/Starlark 语义仍需实际部署/客户端验收。本地自动终态已覆盖,不据此宣称 QA PASS 或直接关闭。

    Tester 依据:当前标签仅 kind/bug、severity/s1,无 kind/compatibility / area/compatibility,按维护规则由 Ariznawlll 验证。

  7. Ariznawlll commented on Oct 19, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:c33b29529c20694811427bbcee10d40ba8e96081(本轮执行前读取并检出的官方 main)
    • 修复:PR #30131 已 MERGED,merge commit 959d12d3b9e10d828e95876fce88b46511294c58;GitHub compare 为 ahead、behind=0,确认已进入上述 main。
    • 部署方式:隔离本地 1 LogService / 1 TN / 2 CN;两个 CN 分别经真实 MySQL TCP 客户端连接,Go 1.27.1、macOS/arm64,定向执行启用 -race。
    • 测试日期:2026-10-20(北京时间)。

    原问题验证

    本轮在上述完整 SHA 启动双 CN 夹具,分别在 CN0、CN1 的真实 MySQL 连接中重放原始 NULL 入参、mo.getvar 和 mo.sql 行为。定向命令为 MO_TEST_CLUSTER_TCP_ONLY=1 .agents/skills/mo-dev/scripts/mo-cgo-test -race -p 1 -count=3 -timeout=12m -run '^TestIssue29151QATwoCN$' ./pkg/tests/sqlintegration/multicn,exit 0,包耗时 24.129s;每个 CN 3/3:

    • CALL p_in(NULL,'x',@v) 得 NoneType:None:string:x;CALL p_in(1,NULL,@v) 得 int:1:NoneType:None;双 NULL 得 NoneType:None:NoneType:None,不再报 type invalid。
    • @qa_x=NULL 经 mo.getvar 得 NoneType:None:True,与 @qa_x='' 的 string::True 明确区分。
    • mo.sql("select null, '', 0, 'text'") 得 [(None, "", "0", "text")],NULL 与空串相邻但未混淆。

    Happy Path 覆盖

    1. 每个 CN 的非 NULL 数值/字符串对照分别返回 int:0:string: 与 int:7:string:text,0、空串和普通值不被误映射为 None,均 3/3。
    2. Starlark OUT None、mo.setvar(..., None) 反向映射仍为 SQL NULL;同场的空串仍非 NULL。六个布尔断言实际为 1,0,1,1,0,1,两 CN 各 3/3。
    3. 同仓库已有完整 Starlark NULL SQL 用例 还覆盖 INOUT、用户变量 NULL、双行多列 NULL/空串,配对 预期结果 保留精确 oracle;本轮未将该 BVT 整文件另行启动。

    Unhappy Path 覆盖

    1. 每个 CN 故意 CALL 不存在的测试过程,收到错误后同连接 SELECT 1 仍返回 1,各 3/3;没有因拒绝路径损坏连接状态。
    2. 每个 CN 的临时数据库在测试后删除,并查询 information_schema.schemata 确认计数 0,各 3/3;没有跨轮残留。此语义缺陷不依赖外部故障注入。

    白盒验证

    同 SHA 运行 TestConvertToStarlarkValueNull|TestStarlarkVariablesNull|TestStarlarkSQLNullCells,-race -count=3 exit 0,包耗时 2.700s。测试断言 NULL/空串/0、None 反向转换及 SQL cell 读取错误不返回部分结果;本轮未观察到 race 报告或 panic。

    回归测试

    测试证据

    • 本轮双 CN 真实 MySQL TCP 定向测试:ok .../pkg/tests/sqlintegration/multicn 24.129s,两 CN 各 3/3;临时 QA 驱动在验证后移除,隔离工作树恢复干净。精确期望值另见上述仓库 SQL/result 对。
    • PR #30131 的改动及 CI 状态。本轮结论只针对 main,不声称未执行的生产部署或其他发布线已经通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions