Skip to content
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

[feature] Add dataclass for filter #8778

Closed
JakeSummers opened this issue Feb 1, 2023 · 3 comments
Closed

[feature] Add dataclass for filter #8778

JakeSummers opened this issue Feb 1, 2023 · 3 comments
Labels
area/samples area/sdk kind/feature lifecycle/stale The issue / pull request is stale, any activities remove this label.

Comments

@JakeSummers
Copy link

Feature Area

/area sdk
/area samples

What feature would you like to see?

#6748 added support for filters.

The suggested workflow, is to build the predicates like this (doc).:

filter = json.dumps(
	{
		'predicates': [
			{
				'key': 'name', 
				'op': 1,     # <-- NOTE: 1 means "EQUALS" - very hard to read.
				'string_value': '{}'.format(pipeline_name)
			}
		]
	})

It would be much nicer, if the sdk provided a dataclass that would help to build these predicates. Something like this:

from dataclasses import dataclass
from enum import Enum
from typing import List


# https://www.kubeflow.org/docs/components/pipelines/v1/tutorials/sdk-examples/#example-2-listing-pipelines-with-a-filter
# https://github.com/kubeflow/pipelines/blob/64bf95333ccc3a0411793c4a11325b71595ab150/backend/api/filter.proto#L25-L63

class Operation(Enum):
    # Operators on scalar values. Only applies to one of |int_value|,
    # |long_value|, |string_value| or |timestamp_value|.
    EQUALS = 1
    NOT_EQUALS = 2
    GREATER_THAN = 3
    GREATER_THAN_EQUALS = 5
    LESS_THAN = 6
    LESS_THAN_EQUALS = 7

    # Checks if the value is a member of a given array, which should be one of
    # |int_values|, |long_values| or |string_values|.
    IN = 8

    # Checks if the value contains |string_value| as a substring match. Only
    # applies to |string_value|.
    IS_SUBSTRING = 9


@dataclass()
class Predicate:
    key: str
    op: Operation
    string_value: str

@dataclass
class Filter:
    predicates: List[Predicate]

This could then be used like this:

my_filter = Filter([
    Predicate(
        key="name",
        op=Operation.EQUALS,
        string_value="my-experiment"
    )
])

As an aside, the inline doc is currently, broken:

image

What is the use case or pain point?

Needing to build json, particularly json that uses 'op': 1 where 1 means Equals is not very user friendly.

Is there a workaround currently?

Yes.


Love this idea? Give it a 👍.

@JakeSummers JakeSummers changed the title [feature] Add dataclass for [feature] Add dataclass for filter Feb 1, 2023
@chensun chensun added this to Needs triage in KFP SDK Triage via automation Feb 2, 2023
@chensun chensun moved this from Needs triage to Awaits Contributor in KFP SDK Triage Feb 2, 2023
@connor-mccarthy
Copy link
Member

@JakeSummers, I think this is a good idea. If you're interested in contributing this (including the docs fix) I would happy to review your PR.

@github-actions
Copy link

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

@github-actions github-actions bot added the lifecycle/stale The issue / pull request is stale, any activities remove this label. label Aug 26, 2023
Copy link

This issue has been automatically closed because it has not had recent activity. Please comment "/reopen" to reopen it.

KFP SDK Triage automation moved this from Awaits Contributor to Closed Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/samples area/sdk kind/feature lifecycle/stale The issue / pull request is stale, any activities remove this label.
Projects
Development

No branches or pull requests

2 participants