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

Use AntlrAssetSelectionParser in AssetSelection.from_string #25916

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ def resolve_checks_inner(

@classmethod
def from_string(cls, string: str) -> "AssetSelection":
from dagster._core.definitions.antlr_asset_selection.antlr_asset_selection import (
AntlrAssetSelectionParser,
)

try:
return AntlrAssetSelectionParser(string).asset_selection
except:
pass
if string == "*":
return cls.all()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from dagster._core.definitions.assets import AssetsDefinition
from dagster._core.definitions.base_asset_graph import BaseAssetGraph
from dagster._core.definitions.events import AssetKey
from dagster._core.selector.subset_selector import MAX_NUM
from dagster._serdes import deserialize_value
from dagster._serdes.serdes import _WHITELIST_MAP
from typing_extensions import TypeAlias
Expand Down Expand Up @@ -804,7 +805,33 @@ def test_deserialize_old_all_asset_selection():
assert not new_unserialized_value.include_sources


def test_from_string_tag():
def test_from_string():
assert AssetSelection.from_string("*") == AssetSelection.all(include_sources=True)
assert AssetSelection.from_string("my_asset") == AssetSelection.assets("my_asset")
assert AssetSelection.from_string("*my_asset") == AssetSelection.assets("my_asset").upstream(
depth=MAX_NUM, include_self=True
)
assert AssetSelection.from_string("+my_asset") == AssetSelection.assets("my_asset").upstream(
depth=1, include_self=True
)
assert AssetSelection.from_string("++my_asset") == AssetSelection.assets("my_asset").upstream(
depth=2, include_self=True
)
assert AssetSelection.from_string("my_asset*") == AssetSelection.assets("my_asset").downstream(
depth=MAX_NUM, include_self=True
)
assert AssetSelection.from_string("my_asset+") == AssetSelection.assets("my_asset").downstream(
depth=1, include_self=True
)
assert AssetSelection.from_string("my_asset++") == AssetSelection.assets("my_asset").downstream(
depth=2, include_self=True
)
assert AssetSelection.from_string("+my_asset+") == AssetSelection.assets("my_asset").downstream(
depth=1, include_self=True
) | AssetSelection.assets("my_asset").upstream(depth=1, include_self=True)
assert AssetSelection.from_string("*my_asset*") == AssetSelection.assets("my_asset").downstream(
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also test `"my_asset some_other_asset*"

depth=MAX_NUM, include_self=True
) | AssetSelection.assets("my_asset").upstream(depth=MAX_NUM, include_self=True)
assert AssetSelection.from_string("tag:foo=bar") == AssetSelection.tag("foo", "bar")
assert AssetSelection.from_string("tag:foo") == AssetSelection.tag("foo", "")

Expand Down