Repository navigation
Description
Description
Starlark stored procedures do not preserve SQL NULL consistently at the SQL/Starlark boundary:
- Passing
NULLto anyINparameter abortsCALLwithtype invalid is not a supported starlark type. mo.getvar()on a SQL user variable containingNULLreturns the same error.mo.sql("select null")returns an empty string cell instead of StarlarkNone, soNULLand''become indistinguishable.- The reverse direction already works: assigning Starlark
Noneto anOUTparameter or throughmo.setvar()produces SQLNULL.
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
INcalls fail withinvalid input: type invalid is not a supported starlark type. mo.getvar("x")returns that error when@xisNULL.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 bothNULL: 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 Noneandmo.setvar(..., None)both correctly produce SQLNULL, 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
Preserve SQL NULL at the Starlark procedure boundary (#30131)
VioletQwQ-0 commentedon Oct 19, 2026
@Ariznawlll 请验证 SQL NULL / Starlark None 的原 issue 范围。Issue 保持 OPEN,等待明确的版本、环境及终态 PASS/FAIL。
修复 PR:#30131(已合并,非 Draft);最终 PR head
e588adb249c3571bd41c4dc7edf53cea80938efe,merge commit959d12d3b9e10d828e95876fce88b46511294c58。本轮查询到的 main 为e0314478159c80b062483c307180b02dc009dbc0;以下本地执行绑定 merge commit,不冒充在最新 main 或部署环境运行。已完成的开发侧自测:
TestConvertToStarlarkValueNull、TestStarlarkVariablesNull、TestStarlarkSQLNullCells实际执行 PASS;完整pkg/frontend一次 PASS。覆盖 NULL/空串/零值、None 反向转换、错误后恢复及 SQL cell 读取失败不泄露部分结果。test/distributed/cases/procedure/starlark_null.sql/.result。每个 CN 连续两次正常比较,四次均total=33, success=33, failed=0, ignored=0,每次执行后独立确认测试数据库已删除。fixture 已关闭;临时 harness 已从工作树移除,保留在维护证据中。mo.getvar(NULL)与空串、mo.sql多行多列 NULL/空串、OUT None 及mo.setvar(..., None)。SQL/result 内容哈希与源文件一致,未重新生成预期结果。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。边界与剩余验收:
test-verification-failed。QA Decision: required=yes;用户可见 SQL/Starlark 语义仍需实际部署/客户端验收。本地自动终态已覆盖,不据此宣称 QA PASS 或直接关闭。
Tester 依据:当前标签仅
kind/bug、severity/s1,无kind/compatibility/area/compatibility,按维护规则由 Ariznawlll 验证。Ariznawlll commentedon Oct 19, 2026
测试版本
mainc33b29529c20694811427bbcee10d40ba8e96081(本轮执行前读取并检出的官方 main)959d12d3b9e10d828e95876fce88b46511294c58;GitHub compare 为 ahead、behind=0,确认已进入上述 main。-race。原问题验证
本轮在上述完整 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 覆盖
int:0:string:与int:7:string:text,0、空串和普通值不被误映射为 None,均 3/3。OUT None、mo.setvar(..., None)反向映射仍为 SQL NULL;同场的空串仍非 NULL。六个布尔断言实际为1,0,1,1,0,1,两 CN 各 3/3。Unhappy Path 覆盖
CALL不存在的测试过程,收到错误后同连接SELECT 1仍返回1,各 3/3;没有因拒绝路径损坏连接状态。information_schema.schemata确认计数 0,各 3/3;没有跨轮残留。此语义缺陷不依赖外部故障注入。白盒验证
同 SHA 运行
TestConvertToStarlarkValueNull|TestStarlarkVariablesNull|TestStarlarkSQLNullCells,-race -count=3exit 0,包耗时 2.700s。测试断言 NULL/空串/0、None 反向转换及 SQL cell 读取错误不返回部分结果;本轮未观察到 race 报告或 panic。回归测试
测试证据
ok .../pkg/tests/sqlintegration/multicn 24.129s,两 CN 各 3/3;临时 QA 驱动在验证后移除,隔离工作树恢复干净。精确期望值另见上述仓库 SQL/result 对。测试结论
测试通过。