Skip to content

[Bug]: Data Branch SQL materialization cannot preserve NaN and infinity float values #26072

Description

@Ariznawlll

Describe the bug

Data Branch operations that materialize rows through generated SQL cannot write valid DOUBLE values representing NaN or positive/negative infinity.

Plain DATA BRANCH DIFF returns these values correctly, but DIFF ... OUTPUT AS, MERGE, and PICK convert them to bare NaN, +Inf, or -Inf tokens. Those tokens are parsed as column expressions rather than floating-point values.

Tested at commit 2eb7f523e5a10f352d3e258183ed8440510388de.

Steps to reproduce

drop database if exists g4d_float_branch;
create database g4d_float_branch;
use g4d_float_branch;

create table base_t(id int primary key, f double);
insert into base_t values (1,1.5);
data branch create table src_t from base_t;
data branch create table dst_t from base_t;

insert into src_t values
  (2,cast('NaN' as double)),
  (3,cast('Inf' as double)),
  (4,cast('-Inf' as double));

-- This returns all three rows correctly.
data branch diff src_t against dst_t;

-- These fail when the values are materialized through generated SQL.
data branch diff src_t against dst_t output as diff_out;
data branch merge src_t into dst_t;

PICK fails in the same way on a fresh source/destination pair:

insert into pick_src values (2,cast('NaN' as double));
data branch pick pick_src into pick_dst keys(2);

Actual behavior

  • Plain DIFF returns NaN, +Infinity, and -Infinity.
  • OUTPUT AS fails with an error such as ambiguous column reference 'Inf'; the incomplete result table is cleaned up.
  • MERGE fails with the same class of error and leaves the destination unchanged.
  • PICK fails on NaN and leaves the destination unchanged.

Expected behavior

Every Data Branch operation should preserve all floating-point values accepted by MatrixOne. Generated SQL should use a representation that round-trips NaN and both infinity values, such as an explicit cast from a quoted value.

Reproducibility

Reproduced in 3/3 runs for OUTPUT AS, MERGE, and PICK. Plain DIFF succeeded in all runs.

Code context

formatValIntoString in pkg/frontend/data_branch_helpers.go formats FLOAT and DOUBLE with strconv.AppendFloat. Finite values are valid numeric literals, but the special outputs NaN, +Inf, and -Inf are appended without quoting or an explicit cast. The same formatter feeds OUTPUT AS and the MERGE/PICK SQL appenders.

Activity

  1. added this to the MO-202607 milestone on Jul 23, 2026
  2. added
    kind/bug
    on Jul 23, 2026
  3. added theissue type on Jul 23, 2026
  4. added
    severity/s0
    ai-easy
    and removed on Jul 31, 2026
  5. gouhongshen commented on Jul 31, 2026

    @gouhongshen
    Contributor

    The verified fix is available in Draft PR #26504.

    The local branch, fork branch, and PR head currently resolve to the same commit.

  6. gouhongshen commented on Aug 4, 2026

    @gouhongshen
    Contributor

    fixed

  7. added and removed
    severity/s0
    on Aug 4, 2026
  8. Ariznawlll commented on Aug 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ab49099c0f487255df131f45c3aecf4a4650fed7
    • 部署方式:macOS arm64 本地 1 CN;Git4Data SQL 黑盒验证
    • 测试日期:2026-08-07

    原问题验证

    执行现有 branch_float_special_values.sql 的 DIFF OUTPUT AS、MERGE、PICK 场景:带主键表的 NaN、+Inf、-Inf 特殊浮点值均可正确保留,连续 3/3 通过;完整当前 BVT 也通过(仅出现用例定义的预期 conflict error)。

    Happy Path 覆盖

    1. 带主键表的 NaN、+Inf、-Inf 在 branch 的 DIFF OUTPUT AS、MERGE、PICK 路径均通过,连续 3/3 输出一致。
    2. 普通 -Inf 保留路径在扩展场景中也保持正确。

    Unhappy Path 覆盖

    1. 扩展为无主键表:base 中有 NaN(应删除)、+Inf(应更新)、-Inf(应保留);branch merge 后查询结果同时存在 NaN remove、+Inf update 和 +Inf updated。
    2. 预期是删除 NaN remove 并以 +Inf updated 替换 +Inf update;实际删除和更新均残留旧行,属于错误数据物化。
    3. 该场景连续 3/3 输出一致;带主键的原始控制路径通过,排除 NaN/Inf 基础表达与测试夹具问题。

    白盒验证

    不适用。本次失败可由 Git4Data 的公开 branch/merge SQL 稳定复现,已包含带主键的通过控制与无主键的失败对照。

    回归测试

    已执行现有 BVT(见上方链接)及本地无主键扩展 SQL,未新增回归用例:当前实现存在确定性错误。修复后建议在 branch_float_special_values.sql 增加无主键的 NaN/+Inf/-Inf merge,并断言旧行被删除而不是更新后并存。

    测试证据

    • 现有带主键 special-float BVT:3/3 通过;完整 BVT 通过。
    • 无主键扩展:3/3 保留 NaN remove 和 +Inf update 两条旧记录,同时新增 +Inf updated。
    • 测试提交是当时官方 main;发布评论时 current main 为 8824b6c7f4549dfdc6fce37fec4c0002ce703b3e,与测试提交相差 1 个不涉及 FILL/Git4Data 文件的 commit。

    测试结论

    测试不通过。

  9. added
    severity/s0
    and removed on Aug 8, 2026
  10. added a commit that references this issue on Aug 8, 2026
    54c6c9b
  11. added and removed
    severity/s0
    on Aug 11, 2026
  12. gouhongshen commented on Aug 11, 2026

    @gouhongshen
    Contributor

    fixed again

  13. Ariznawlll commented on Aug 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:1c292cf20e113b296a3db2cb6a65e00af2ea2327
    • 部署方式:本地 etc/launch-with-proxy/launch.toml,2 CN / 1 TN / 1 Log + Proxy;本用例直连 CN 16001
    • 测试日期:2026-08-13

    原问题验证

    分别创建带主键和不带主键的源/目标 DATA BRANCH 表,将 FLOAT、DOUBLE 的 NaN、+Inf、-Inf、有限值和 NULL 组合写入更新、插入和删除差异,再执行 DATA BRANCH DIFF ... OUTPUT AS、MERGE 和 PICK。原问题中的非有限浮点值均能被物化并写回:例如主键路径得到 nan/inf、inf/-inf、NULL/NULL 和 -inf/nan,未出现 SQL 拼接或转换错误。完整用例连续执行 3/3 次,结果一致。

    Happy Path 覆盖

    1. 带主键路径:DIFF OUTPUT AS 正确产生 3 条 UPDATE 和 1 条 INSERT;MERGE 后 5 行的有限值、NaN、正负无穷和 NULL 均与源表一致。
    2. 无主键路径:覆盖含特殊浮点值的更新前像、删除、更新和插入;MERGE 后只保留 keep、两条更新行及新插入行,已删除行没有残留。
    3. PICK ... KEYS(2,3,4) 使用全新分支独立验证,目标表最终包含未修改控制行和三条带 nan/inf、inf/-inf、-inf/nan 的指定行。

    Unhappy Path 覆盖

    1. 源、目标同时修改同一主键后执行 MERGE,稳定返回错误码 20101。
    2. 冲突失败后检查目标表,仍只有 (1,'keep',1.0,2.0) 和 (2,'destination',9.0,NULL);源中的 (3,'must_not_apply',-Inf,NaN) 未被部分写入,验证拒绝原子性。

    白盒验证

    不适用:该问题是 DATA BRANCH 通过公开 SQL 物化 FLOAT/DOUBLE 字面量的端到端行为,风险同时跨越 DIFF OUTPUT AS、MERGE、PICK 和无主键匹配;使用真实 SQL 引擎的 Git4Data 黑盒回归可以直接验证最终行值和冲突原子性。

    回归测试

    已加入 motr PR #106:issue_26072_special_float_materialization.test。聚焦用例重复 3 次均通过;完整 12_git4data 套件结果为 73 success / 0 failed / 1 expected opt-in skip。

    测试证据

    测试结论

    测试通过。

  14. added 3 commits that reference this issue on Sep 17, 2026
    0d5b916
    de932a0
    d22dbcd
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