Skip to content

Conversation

@shubhamraj-git
Copy link
Contributor

@shubhamraj-git shubhamraj-git commented Nov 30, 2024

Add the filter variables support

Request:
image

Response:
image


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Nov 30, 2024
@shubhamraj-git shubhamraj-git changed the title Add the filter variables support Added Advance Search Support and Integrated with Get Variables Dec 7, 2024
@shubhamraj-git shubhamraj-git marked this pull request as ready for review December 7, 2024 18:48
@shubhamraj-git shubhamraj-git changed the title Added Advance Search Support and Integrated with Get Variables Add Advance Search Support and Integrated with Get Variables Dec 7, 2024
@shubhamraj-git shubhamraj-git changed the title Add Advance Search Support and Integrated with Get Variables Add Advance Search Support and Integrate with Get Variables Dec 7, 2024
Comment on lines +163 to +169
STARTS_WITH = "starts_with"
ENDS_WITH = "ends_with"
CONTAINS = "contains"
EQUALS = "equals"
NOT_STARTS_WITH = "not_starts_with"
NOT_ENDS_WITH = "not_ends_with"
NOT_CONTAINS = "not_contains"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what's the best way to pass all these filter options to the UI so we can build the proper form for it.

Copy link
Contributor Author

@shubhamraj-git shubhamraj-git Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can have a dropdown and multiple lines of search can be given from user with add and delete functionality for each search options.
Similar behaviour from legacy UI

const filters = [
    { key: "STARTS_WITH", label: "Starts With", value: "starts_with" },
    { key: "ENDS_WITH", label: "Ends With", value: "ends_with" },
    { key: "CONTAINS", label: "Contains", value: "contains" },
    { key: "EQUALS", label: "Equals", value: "equals" },
    { key: "NOT_STARTS_WITH", label: "Does Not Start With", value: "not_starts_with" },
    { key: "NOT_ENDS_WITH", label: "Does Not End With", value: "not_ends_with" },
    { key: "NOT_CONTAINS", label: "Does Not Contain", value: "not_contains" }
];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a private endpoint for that ?

Copy link
Member

@pierrejeambrun pierrejeambrun Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also an endpoint to list resource fields, and their types, so we can appropriately display the UI form.

For instance DAGModel has a field called is_active which is a boolean etc.. etc.... (So we can basically list fields, operators, and then compos fields + operators do construct a dynamic query)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by private, do you mean ui endpoint?

Yes, I completely agree we should have a endpoint to list the applicable columns.

Copy link
Member

@pierrejeambrun pierrejeambrun Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need an endpoint to list possible operations (in, or, and, >= etc...) and the columns that can be used and maybe the 'type' as well. (boolean, number, etc.)

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

return depends_search


class SearchPatternEnum(Enum):
Copy link
Member

@pierrejeambrun pierrejeambrun Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should reuse FilterOptionEnum and rename it to a more generic name. Maybe move it to the DB package with something like ORMOperatorEnum or something else.

DB operations supported by the query parameters and the one from advanced search will basically be very close. (and this will avoid duplication).

As we do for states task_states dag_run_states, etc.. we can split FilterOperator AdvancedSearchOperator, etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilterOptionEnum have bit different types of support, such as numeric, etc.
Mixing both could create confusion?
Maybe i can differentiate this with filter, such that it should actually look like advance search, like chnaging filter param to advance_search in APIs.

Also do you mean something like:
Parent : child?
ORMOperator -> FilterOperator, AdvancedSearchOperator ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the enumeration of all ORM operation could live in the db module of FastAPI.

Then other enums FilterOperator, AdvancedSearchOperator can use that, but basically Filter and Search are just query params, the difference is the db operator that is used airflow/utils/states.py combines enums as well, could be interesting to take a look.

That's not of big importance at this stage I think

Comment on lines +163 to +169
STARTS_WITH = "starts_with"
ENDS_WITH = "ends_with"
CONTAINS = "contains"
EQUALS = "equals"
NOT_STARTS_WITH = "not_starts_with"
NOT_ENDS_WITH = "not_ends_with"
NOT_CONTAINS = "not_contains"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a private endpoint for that ?

Comment on lines +192 to +200
pattern_map = {
SearchPatternEnum.STARTS_WITH: f"{self.value}%",
SearchPatternEnum.ENDS_WITH: f"%{self.value}",
SearchPatternEnum.CONTAINS: f"%{self.value}%",
SearchPatternEnum.EQUALS: self.value,
SearchPatternEnum.NOT_STARTS_WITH: f"{self.value}%",
SearchPatternEnum.NOT_ENDS_WITH: f"%{self.value}",
SearchPatternEnum.NOT_CONTAINS: f"%{self.value}%",
}
Copy link
Member

@pierrejeambrun pierrejeambrun Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that is really focused around search (text search) while I imagined advanced search to actually be on any field and any db operation.

For instance I want a custom query to display dags with the specific status that is SUCCESS and with the dag_id that ends with something and is_paused True.

Basically serializing and deserializing via a query parameter &query='xxxxx'&query='' dyanamic Filters.

Copy link
Contributor Author

@shubhamraj-git shubhamraj-git Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that,
Maybe I might be wrong, I would need some clarity about the differences between filter and advance_search operations.
If advance_search starts taking for booleans or special types, wouldn't it contradict the work of filters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we eventually want is the ability to create a full custom query such as:

I want dags that are in success or running state, and that have a dag_id that starts with dag_id_prefix and with at least 1 tag among [tag1, tag2].

Its basically being able to create a custom query.

Also I think we need to be able to support 'AND' and 'OR' and maybe composition (cd1 | cd2) & (cd3).

Comment on lines +163 to +169
STARTS_WITH = "starts_with"
ENDS_WITH = "ends_with"
CONTAINS = "contains"
EQUALS = "equals"
NOT_STARTS_WITH = "not_starts_with"
NOT_ENDS_WITH = "not_ends_with"
NOT_CONTAINS = "not_contains"
Copy link
Member

@pierrejeambrun pierrejeambrun Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also an endpoint to list resource fields, and their types, so we can appropriately display the UI form.

For instance DAGModel has a field called is_active which is a boolean etc.. etc.... (So we can basically list fields, operators, and then compos fields + operators do construct a dynamic query)

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to extend this to 'any' column of the resource and 'any' operation. (>=, text contains start with end with etc.., IN, array contain etc..)

Maybe the serialization form should be something like

?query="((key, START_WITH, 'something') or (value, EQUAL, 'some_value')) and (value, END_WITH, 'suffix')" 

Maybe we don't need OR | AND support and expressions (nested boolean operators). Maybe we don't need full flexibility about fields and filters used. Because if it's just some predetermined filters, we can just develop them as we do currently and add an endpoint to retrieve them (types, possible values etc...) and display that directly in the UI, constructing the current query normaly with in the front-end ?state=success&active=true.

Maybe @bbovenzi can confirm the use case.

Comment on lines +163 to +169
STARTS_WITH = "starts_with"
ENDS_WITH = "ends_with"
CONTAINS = "contains"
EQUALS = "equals"
NOT_STARTS_WITH = "not_starts_with"
NOT_ENDS_WITH = "not_ends_with"
NOT_CONTAINS = "not_contains"
Copy link
Member

@pierrejeambrun pierrejeambrun Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need an endpoint to list possible operations (in, or, and, >= etc...) and the columns that can be used and maybe the 'type' as well. (boolean, number, etc.)

Comment on lines +192 to +200
pattern_map = {
SearchPatternEnum.STARTS_WITH: f"{self.value}%",
SearchPatternEnum.ENDS_WITH: f"%{self.value}",
SearchPatternEnum.CONTAINS: f"%{self.value}%",
SearchPatternEnum.EQUALS: self.value,
SearchPatternEnum.NOT_STARTS_WITH: f"{self.value}%",
SearchPatternEnum.NOT_ENDS_WITH: f"%{self.value}",
SearchPatternEnum.NOT_CONTAINS: f"%{self.value}%",
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we eventually want is the ability to create a full custom query such as:

I want dags that are in success or running state, and that have a dag_id that starts with dag_id_prefix and with at least 1 tag among [tag1, tag2].

Its basically being able to create a custom query.

Also I think we need to be able to support 'AND' and 'OR' and maybe composition (cd1 | cd2) & (cd3).

# Variables
VARIABLE_COLUMN_MAP = {
"key": Variable.key,
"value": Variable._val,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to use the val proxy not directly _val

@jscheffl
Copy link
Contributor

jscheffl commented Jan 1, 2025

Note: As PR #45312 has been merged, the code formatting rules have changed for new UI. Please rebase and re-run pre-commit checks to ensure that formatting in folder airflow/ui is adjusted.

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Feb 15, 2025
@github-actions github-actions bot closed this Feb 20, 2025
@shubhamraj-git shubhamraj-git deleted the filter-variables-support branch September 7, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers. stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants