Skip to content

Empty nested filter group produces invalid SQL in the SQLite and Postgres online stores #7051

Open

Description

@RaphaelFakhri

A CompoundFilter that contains an empty nested group, for example an or group with no filters, applies the remaining filters. The Milvus online store already skips empty groups this way.

Current behavior

SqliteFilterTranslator and PostgresFilterTranslator join every sub-clause, including the empty string returned for an empty group. The generated WHERE fragment ends in AND ), and the query fails:

from feast.filter_models import ComparisonFilter, CompoundFilter
from feast.infra.online_stores.sqlite import SqliteFilterTranslator

f = CompoundFilter(
    type="and",
    filters=[
        ComparisonFilter(type="eq", key="title", value="Title 1"),
        CompoundFilter(type="or", filters=[]),
    ],
)
print(SqliteFilterTranslator("t", alias="fv").translate(f)[0])
# (fv.entity_key IN (SELECT ... WHERE feature_name = ? AND value_text = ?) AND )

Running that clause in SQLite raises sqlite3.OperationalError: near ")": syntax error. The Postgres translator generates the same trailing AND ). A group that contains only empty groups becomes ( AND ) in SQLite and () in Postgres.

These filters come from retrieve_online_documents_v2(filters=...) and from the OpenAI-compatible openai_search endpoint, where clients build filter JSON programmatically and can send an empty group.

Steps to reproduce

Run the snippet above, then execute the clause against a table with entity_key, feature_name, value_text and value_num columns.

Specifications

  • Version: master as of 2026-10-20
  • Platform: Linux
  • Subsystem: SQLite and Postgres online stores, metadata filters

Possible solution

Skip empty sub-clauses in translate_compound, and return an empty clause when no sub-clause remains, as MilvusFilterTranslator.translate_compound does.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions