-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Add exact-match uri filter to GET /assets endpoint #69489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add an indexed exact-match ``uri`` query parameter to ``GET /api/v2/assets`` for fast single-asset lookup by URI (much faster than ``uri_pattern``, which uses an unindexed ``ILIKE '%...%'``). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be removed. (I know doc mentions that user facing change should have a fragment, but that's only true for significant / behavior change that needs a user warning basically). |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1578,6 +1578,22 @@ def _transform_ti_states(states: list[str] | None) -> list[TaskInstanceState | N | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QueryUriPrefixPatternSearch = Annotated[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _PrefixSearchParam, Depends(prefix_search_param_factory(AssetModel.uri, "uri_prefix_pattern")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QueryUriExactMatch = Annotated[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FilterParam[str | None], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Depends( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter_param_factory( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AssetModel.uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| str | None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter_name="uri", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description=( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Exact-match filter on the full asset URI. Compiles to an indexed equality " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1581
to
+1589
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could make this filter accept multiple values. To allow It's really a simple change, as an exemple for implementation: QueryTIStateFilter = Annotated[
FilterParam[list[str]],
Depends(
filter_param_factory(
TaskInstance.state,
list[str],
FilterOptionEnum.ANY_EQUAL,
default_factory=list,
transform_callable=_transform_ti_states,
)
),
] |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "comparison (``uri = ...``), so it is far faster than ``uri_pattern`` (which uses " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "``ILIKE '%...%'`` and cannot use an index) for resolving a single asset by its " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "known URI." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1581
to
+1596
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove the piece that compares to search params. They have their own doc explaining the performance pitfalls, this can stay about 'exact match'.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| QueryAssetAliasNamePatternSearch = Annotated[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _SearchParam, Depends(search_param_factory(AssetAliasModel.name, "name_pattern")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| """ | ||
| Add index on asset.uri. | ||
|
|
||
| Revision ID: c4e7a1f9b2d0 | ||
| Revises: d2f4e1b3c5a7 | ||
| Create Date: 2026-07-06 00:00:00.000000 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "c4e7a1f9b2d0" | ||
| down_revision = "d2f4e1b3c5a7" | ||
| branch_labels = None | ||
| depends_on = None | ||
| airflow_version = "3.3.0" | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """Apply Add index on asset.uri.""" | ||
| with op.batch_alter_table("asset", schema=None) as batch_op: | ||
| batch_op.create_index("idx_asset_uri", ["uri"], unique=False) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| """Unapply Add index on asset.uri.""" | ||
| with op.batch_alter_table("asset", schema=None) as batch_op: | ||
| batch_op.drop_index("idx_asset_uri") | ||
|
Comment on lines
+37
to
+47
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just checked, in 2.x there was an index indeed, so the table was worth indexing. Disregard my previous comment, this makes sense. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,6 +333,9 @@ class AssetModel(Base): | |
| __tablename__ = "asset" | ||
| __table_args__ = ( | ||
| Index("idx_asset_name_uri_unique", name, uri, unique=True), | ||
| # Single-column index so exact-match lookups by URI (GET /assets?uri=...) can use an | ||
| # index; the composite index above leads with ``name`` and cannot serve uri-only queries. | ||
|
Comment on lines
+336
to
+337
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this, to not mention the API layer in ORM models. |
||
| Index("idx_asset_uri", uri), | ||
| {"sqlite_autoincrement": True}, # ensures PK values not reused | ||
| ) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target version needs to be updated, 3.3.0 was just released, that would be for 3.4.0