-
Notifications
You must be signed in to change notification settings - Fork 344
Revisit StructuredDatasetDecoder interface #865
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
Changes from all commits
eb1c75e
f08085a
d425dbe
2a3d5c5
c1accfa
44f2ce1
8292038
fe445a1
245bf78
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 | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,11 @@ | |||||||||||||||||||||||||||||||||||||||
| from flytekit import kwtypes, task, workflow | ||||||||||||||||||||||||||||||||||||||||
| from flytekit.types.schema import FlyteSchema | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| from typing import Annotated | ||||||||||||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import Annotated | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def test_wf1_with_spark(): | ||||||||||||||||||||||||||||||||||||||||
| @task(task_config=Spark()) | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,27 +58,6 @@ def my_wf() -> my_schema: | |||||||||||||||||||||||||||||||||||||||
| assert df2 is not None | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def test_ddwf1_with_spark(): | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. was this test bad for some reason?
Member
Author
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 have the same test here. flytekit/plugins/flytekit-spark/tests/test_wf.py Lines 15 to 33 in eb1c75e
|
||||||||||||||||||||||||||||||||||||||||
| @task(task_config=Spark()) | ||||||||||||||||||||||||||||||||||||||||
| def my_spark(a: int) -> (int, str): | ||||||||||||||||||||||||||||||||||||||||
| session = flytekit.current_context().spark_session | ||||||||||||||||||||||||||||||||||||||||
| assert session.sparkContext.appName == "FlyteSpark: ex:local:local:local" | ||||||||||||||||||||||||||||||||||||||||
| return a + 2, "world" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||||||||||||||||
| def t2(a: str, b: str) -> str: | ||||||||||||||||||||||||||||||||||||||||
| return b + a | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @workflow | ||||||||||||||||||||||||||||||||||||||||
| def my_wf(a: int, b: str) -> (int, str): | ||||||||||||||||||||||||||||||||||||||||
| x, y = my_spark(a=a) | ||||||||||||||||||||||||||||||||||||||||
| d = t2(a=y, b=b) | ||||||||||||||||||||||||||||||||||||||||
| return x, d | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| x = my_wf(a=5, b="hello ") | ||||||||||||||||||||||||||||||||||||||||
| assert x == (7, "hello world") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def test_fs_sd_compatibility(): | ||||||||||||||||||||||||||||||||||||||||
| my_schema = FlyteSchema[kwtypes(name=str, age=int)] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -108,7 +92,6 @@ def test_spark_dataframe_return(): | |||||||||||||||||||||||||||||||||||||||
| def my_spark(a: int) -> my_schema: | ||||||||||||||||||||||||||||||||||||||||
| session = flytekit.current_context().spark_session | ||||||||||||||||||||||||||||||||||||||||
| df = session.createDataFrame([("Alice", a)], my_schema.column_names()) | ||||||||||||||||||||||||||||||||||||||||
| print(type(df)) | ||||||||||||||||||||||||||||||||||||||||
| return df | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @workflow | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,3 +103,19 @@ def my_wf(a: int) -> my_schema: | |||||||||||||||||||||||||||||||||||||||
| df2 = reader.all() | ||||||||||||||||||||||||||||||||||||||||
| result_df = df2.reset_index(drop=True) == pd.DataFrame(data={"name": ["Alice"], "age": [5]}).reset_index(drop=True) | ||||||||||||||||||||||||||||||||||||||||
| assert result_df.all().all() | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def test_read_spark_subset_columns(): | ||||||||||||||||||||||||||||||||||||||||
| @task | ||||||||||||||||||||||||||||||||||||||||
| def t1() -> pd.DataFrame: | ||||||||||||||||||||||||||||||||||||||||
| return pd.DataFrame({"Name": ["Tom", "Joseph"], "Age": [20, 22]}) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @task(task_config=Spark()) | ||||||||||||||||||||||||||||||||||||||||
| def t2(df: Annotated[pyspark.sql.DataFrame, kwtypes(Name=str)]) -> int: | ||||||||||||||||||||||||||||||||||||||||
| return len(df.columns) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @workflow() | ||||||||||||||||||||||||||||||||||||||||
| def wf() -> int: | ||||||||||||||||||||||||||||||||||||||||
| return t2(df=t1()) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| assert wf() == 1 | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.