Skip to content

[Bug]: Python FulltextFilter projection converts relevance scores to booleans #32027

Closed

Description

@Ariznawlll

Description

Selecting a Python SDK FulltextFilter expression through SQLAlchemy converts the numeric relevance score into a Python bool. Distinct non-zero scores therefore become True, losing the value applications need for ranking and scoring. This occurs even without calling .label().

Environment

  • Official main at analysis time: f0a6ed145e07c84ecc80566ac659212c4a20debd.
  • Python 3.12; SQLAlchemy 1.4.54 and 2.1.6.
  • The SDK was executed from clean d24f446e1e94a58c329d422519f7aad621cdcd05; its entire clients/python/matrixone package is byte-identical to the official main commit above.
  • The live MO control used an isolated service built from older main ea184ad90624ae3dba8ced628ac019271a6c309c, reporting 8.0.30-MatrixOne-v1.3.0; live latest-main server behavior was not tested.

Steps to reproduce

With a docs(id, content) table containing a classic FULLTEXT index and a matching document:

from sqlalchemy import MetaData, Table, select
from matrixone.sqlalchemy_ext.fulltext_search import boolean_match

docs = Table('docs', MetaData(), autoload_with=engine)
match = boolean_match(docs.c.content).must('needle')
print(engine.connect().execute(select(docs.c.id, match).where(match)).all())

On the same connection/database, compare the numeric value produced by SELECT id, MATCH(content) AGAINST('+needle' IN BOOLEAN MODE) FROM docs WHERE MATCH(content) AGAINST('+needle' IN BOOLEAN MODE) using the raw driver.

Actual behavior

In three independent existing test databases, raw SQL returned (1, 0.09061906) with Python type float; SQLAlchemy returned (1, True) with type bool for the same match and row. The selected expression does not use .label().

Expected behavior

When selected as a score, the expression should preserve the numeric result and type returned by the driver while remaining usable as a WHERE predicate.

Stability and controls

  • Live older-MO comparison: 3/3 databases, numeric driver result versus boolean SDK/SQLAlchemy result.
  • Independent client-side isolation: on both SQLAlchemy versions, replace only the SQLite compiler's MATCH rendering with the numeric constant 0.09061906. Selecting literal(0.09061906) and boolean_match('content').must('needle') in one statement returned (0.09061906, True) 3/3 times. This control isolates SQLAlchemy result processing; it does not execute MO fulltext SQL or claim latest-MO server validation.
  • Read-only queries; no data mutations in these checks.

Code analysis

clients/python/matrixone/sqlalchemy_ext/fulltext_search.py:FulltextFilter.__init__ declares self.type = Boolean(). SQLAlchemy consequently applies a boolean result processor to the MATCH relevance value. Predicate use and numeric projection have different result-type requirements.

Regression coverage

Add SDK regression checks for an unlabelled projected score, multiple different nonzero scores and zero, asserting numerical type/value; retain a WHERE predicate control. Also verify against a live current-main MO service.

Related

#32026 is a separate failure: the overridden .label() returns an object rejected during statement construction. This report uses an unlabelled FulltextFilter and demonstrates loss of score after a query executes. The query-composition investigation was prompted by #32018.

Activity

  1. added this to the MO-202611 milestone on Nov 2, 2026
  2. added
    kind/bug
    on Nov 2, 2026
  3. added theissue type on Nov 2, 2026
  4. Ariznawlll commented on Nov 2, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试不通过。本问题不只影响直接投影:SUM/MIN/MAX 继承全文表达式的布尔结果类型,分数也被读取为 True;子查询和 UNION ALL 会继续传播该类型。这些是同根扩展,不另提 issue。

    关键证据

    • SDK 来自干净提交 d24f446e1e94a58c329d422519f7aad621cdcd05,已核对其 clients/python/matrixone 与 f0a6ed145e07c84ecc80566ac659212c4a20debd 完全一致。SQLAlchemy 2.1.6。实测数据库仍为隔离的旧版 ea184ad90624ae3dba8ced628ac019271a6c309c,不是最新 MO 服务验证。
    • 三轮独立表,每表六行,包含不同词频、非匹配、空串和 NULL;分别连接两个 CN,以 BOOLEAN、NATURAL LANGUAGE 两种模式比较同一条 SQL 的原始驱动结果和 SDK 结果,共 96 组对照。projection/sort_page/SUM/MIN/MAX 均出现分数变布尔值;CAST(... AS FLOAT)、AVG、COUNT 保持正确数值和类型。连接到两个 CN 是两个入口的对照,不代表这些小查询执行了分布式计划。
    • 一组自然语言模式数据中:原始 SUM=0.07804843969643116、MIN=0.015609688、MAX=0.046829063,SDK 三者均为 True;AVG=0.026016146565477054 和 COUNT=3 两条路径一致。按原始分数排序分页的行 ID 与顺序保持一致,但结果中的分数仍丢失。
    • 可用下面的表达式扩展原复现,随后将 stmt 编译出的同一 SQL 交给原始驱动比较:
    match = boolean_match(docs.c.body).must('needle')
    stmt = select(func.sum(match), func.min(match), func.max(match)).select_from(docs).where(match)
    • 另做一轮两 CN、两模式的子查询/UNION ALL 与空结果对照:前两者的外层分数仍变为 bool;空投影仍为空、空 SUM 仍为 None。所有检查之后完整读取六行源数据正常。没有对服务做重启或故障注入。

    待解决点

    • 修复分数结果类型时同时覆盖直接投影、聚合及子查询/UNION ALL 传播,并保留 WHERE 和空结果语义;需要在最新 MO 服务补齐端到端验证。本轮未新增仓库用例或 PR。
  5. added a commit that references this issue on Nov 3, 2026
    da62af3
  6. XuPeng-SH commented on Nov 3, 2026

    @XuPeng-SH
    Contributor

    QA 交接(已合并修复,非验收通过)

    修复 PR #32042 已于 2026-11-03 00:32:23 UTC 合入 main,merge SHA da62af35f615824a3987ce9f6eac4c9bc5e7b541。FulltextFilter 的结果类型由 Boolean 改为 Float,修复相关表达式的分数布尔化。

    已核对本 issue 全部评论及两文件修复范围。原评论的聚合、子查询和 UNION ALL 反例针对旧 SDK;该 PR 的冻结 head 审查 报告基线重现、候选聚合/子查询/UNION ALL/空值与空结果/谓词/dialect processor/Client.execute 对照通过,并有 101 项 focused tests 通过。作者报告 SQLAlchemy 1.4.54、2.0.43、2.1.6 的完整 offline suite 及九项新增回归通过。以上为远端作者/审查证据,本轮未进行本地实测;未发现适用于新修复的已验证反例或未完开发 follow-up,因此交 QA 复测。

    验证限制与建议:未验证最新 main 的 live MatrixOne 全文评分、多 CN、在线 CI、SQL BVT 或性能;请在当前 main 对照原始驱动和 SDK 的直接投影、排序分页、SUM/MIN/MAX、子查询/UNION ALL,并覆盖不同正分数、零、负值、NULL/空结果、BOOLEAN/NATURAL LANGUAGE/QUERY EXPANSION、裸 WHERE 与数值阈值。旧双 CN 结果不等同分布式执行验证。独立 .label() 问题 #32026 不在本修复范围。转测不代表验收通过。

  7. Ariznawlll commented on Nov 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。全文表达式作为投影和聚合结果时保留数值分数,不再把非零分数转换成 Python 布尔值。

    关键证据

    • 基于官方 main@d61a7206c16b30baa4efc525eb6067c4364035aa、隔离 MO、Python 3.12;覆盖 SQLAlchemy 1.4.54、2.0.55、2.1.6。修复 #32042 的 SDK 离线矩阵及 CI Required 通过;online CI 跳过,下述真实服务测试是本次补充执行。
    • **Happy case:**在真实 FULLTEXT 表上比较同一 SQL 的原始驱动结果和 SDK/SQLAlchemy 结果,BOOLEAN、NATURAL LANGUAGE 模式各通过三轮;直接投影、裸 WHERE、数值阈值、排序分页以及 SUM/MIN/MAX 均保留数值类型和相同结果。自然语言示例的两条匹配行得到不同分数 0.062016264、0.031008132,而不是两个 True。直接投影和聚合在三个 SQLAlchemy 版本均执行;排序、阈值、子查询和 UNION 使用 2.1.6。第二个 CN 入口也复测三轮。
    • **Unhappy case:**空结果、空集合 SUM 为 NULL,子查询和 UNION ALL 的结果与原始驱动相同;没有依赖未指定的 UNION 行顺序。非法全文单词输入被 SDK 拒绝,三轮通过。测试后删除临时表。
    • 白盒及回归:主库 clients/python/tests/offline/test_fulltext_score_type.py 覆盖表达式类型、裸 WHERE 和阈值,并以模拟服务分数覆盖正值、零、负值、NULL 及三种表达式模式;本地相关离线选择每版本 37 passed + 20 subtests。零、负分及 QUERY EXPANSION 属于离线结果处理覆盖,本次不宣称真实 MO 产生了这些分数或支持该搜索模式。此问题在 SDK 结果处理,回归应位于 SDK 测试,不适合纯 SQL MOTR。

    待解决点

    无本 issue 范围内待解决项。第二个 CN 是独立入口复测,并不证明查询采用分布式计划;单独的 .label() 问题不属于此修复。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions