extractSimpleComparisons returns value: null when the right side of a comparison isn't a literal

未关闭 适合新手
#2,381 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
data

调研方向

回退到 null 的逻辑位于 packages/db/src/query/expression-helpers.ts 的第390行和第472行附近,抛出 'Found complex expression' 的 guard 紧随其后。首先,使用 extractSimpleComparisons 重现 issue 中的三个调用。完成标准是:这些调用在右侧操作数不是字面量时抛出错误,而 eq(row.a, null) 仍返回 value: null,并且有一个测试覆盖这两种情况。

由索引模型根据 Issue 内容生成。

描述

  • I've validated the bug against the latest version of DB packages

Describe the bug

extractSimpleComparisons is documented to throw on expressions it can't represent as a simple comparison, but a comparison whose right side is a column or a function doesn't throw. It returns value: null, so a queryFn built on it sends a filter against null to the backend with no error.

When the right side isn't a literal it falls back to null (expression-helpers.ts:390 and :472), and the guard after it only rejects undefined, so the "Found complex expression" error can't fire for this case.

To Reproduce

import { IR, extractSimpleComparisons } from "@tanstack/db"

const a = new IR.PropRef(["a"])
const b = new IR.PropRef(["b"])

console.log(extractSimpleComparisons(new IR.Func("eq", [a, b])))
console.log(extractSimpleComparisons(new IR.Func("eq", [a, new IR.Func("lower", [b])])))
console.log(extractSimpleComparisons(new IR.Func("not", [new IR.Func("gt", [a, b])])))

This prints:

[ { field: [ 'a' ], operator: 'eq', value: null } ]
[ { field: [ 'a' ], operator: 'eq', value: null } ]
[ { field: [ 'a' ], operator: 'not_gt', value: null } ]

The same happens through a live query. On an on-demand collection, .where(({ row }) => eq(row.a, lower(row.b))) passes loadSubset a where that extractSimpleComparisons reads as { field: ['a'], operator: 'eq', value: null }.

Expected behavior

These calls throw extractSimpleComparisons requires simple field-value comparisons. Found complex expression for 'eq' operator. (or 'not(gt)'), as they would for any other expression it can't represent. A literal null, such as eq(row.a, null), should keep returning value: null.

Additional context

@tanstack/db 1.0.0-rc.1.4, Node 24.12.0. The lines above are unchanged on main at 6ec538ecd.

Falling back to undefined instead of null at those two lines would let the existing guard throw. I can open a PR if that looks right to you.

主要语言
TypeScript
星标
4k
派生
286
平均合并
1 天 1 小时
30 天内合并 PR
104

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/db 的其他 Issue

查看 TanStack/db 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。