Skip to content

bug(arrow-odbc): SQL Server event store index guard never matches #816

Description

@cofin

The SQL Server event queue store in the arrow-odbc adapter wraps CREATE INDEX in an existence check that never matches. The index DDL runs again every time the store's DDL is applied, and fails if the index already exists.

Where

sqlspec/adapters/arrow_odbc/events/store.py: re.search(r"CREATE INDEX\s+(\S+)\s+ON\s+(\S+)", ...)

What happens

For CREATE INDEX idx_app_events_channel_status ON app_events(channel, status, available_at), the second \S+ captures app_events(channel, as the table name. The rendered guard is:

IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'idx_app_events_channel_status'
  AND object_id = OBJECT_ID(N'[dbo].[app_events(channel,]')) BEGIN CREATE INDEX ... END

OBJECT_ID(N'[dbo].[app_events(channel,]') is always NULL, so NOT EXISTS is always true.

Expected

OBJECT_ID(N'[dbo].[app_events]'). Stop the table-name capture at ( or whitespace, for example ON\s+([^\s(]+).

Note

tests/unit/adapters/test_arrow_odbc/test_tsql_stores.py currently asserts the rendered SQL as it is today, including OBJECT_ID(N'[dbo].[app_events(channel,]'). Update that assertion along with the fix.

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