Repository navigation
Description
Description
FulltextFilter.label() returns a custom FulltextLabel object which SQLAlchemy does not accept as a selectable column. Consequently applications cannot project the relevance score using the advertised label in a standard SQLAlchemy select() query; construction fails before a query reaches MatrixOne.
Environment
- Official MatrixOne
main:f0a6ed145e07c84ecc80566ac659212c4a20debd. - Python 3.12, SQLAlchemy 1.4.54 and 2.1.6; offline, no MO service needed.
- The SDK was run from clean commit
d24f446e1e94a58c329d422519f7aad621cdcd05; the entireclients/python/matrixonepackage is byte-identical to the official main commit above (git diffis empty).
Steps to reproduce
from sqlalchemy import Column, Integer, MetaData, Table, Text, select
from matrixone.sqlalchemy_ext.fulltext_search import boolean_match
docs = Table('docs', MetaData(), Column('id', Integer), Column('body', Text))
score = boolean_match(docs.c.body).must('needle').label('score')
print(select(docs.c.id, score))Actual behavior
sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got ... FulltextLabel ... (SQLAlchemy 2.1.6; 1.4.54 reports the same kind of ArgumentError).
Expected behavior
The expression should be selectable and compile to a score projection such as SELECT docs.id, MATCH(...) AGAINST(...) AS score FROM docs.
Stability and controls
- Fresh expressions reproduced the exception 3/3 times under each SQLAlchemy version.
select(docs.c.id).where(boolean_match(docs.c.body).must('needle'))compiles normally.- Calling SQLAlchemy's
ColumnElement.labelon the same filter compiles a projection withAS score; this is a compilation control, not a claim of a live server result. - The failure occurs during client-side statement construction; no database operation or data mutation occurs.
Code analysis
clients/python/matrixone/sqlalchemy_ext/fulltext_search.py: FulltextFilter subclasses ColumnElement, but its overridden label returns an ad-hoc object rather than a SQLAlchemy selectable expression. The existing offline label tests check .compile() on the ad-hoc object and do not insert it into a SQLAlchemy select().
Regression coverage
Add a client offline regression that uses the public .label() in select(), verifies the rendered label and exercises supported SQLAlchemy versions; add an online relevance-score check separately when an environment is available.
Related
Related exploration of SDK query composition: #32018. This is distinct from its additional WHERE predicate grouping defect.
Activity
fix(python-sdk): preserve numeric fulltext relevance scores (#32042)
fix(python): keep fulltext scores numeric and labels selectable
test(python): reproduce non-selectable fulltext score label
fix(python): make fulltext score labels SQLAlchemy selectable