-
Notifications
You must be signed in to change notification settings - Fork 344
Gate new Structured Dataset feature #831
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f45d135
remove old configs first
wild-endeavor f9e9279
add feature flag
wild-endeavor cbe8fe0
enable in all dockerfiles
wild-endeavor 57fa31e
nit
wild-endeavor 24b6fdf
nit
wild-endeavor 1fb1b7e
add sessionend hook, add new test without the flag, gate spark
wild-endeavor cd9c6e7
makefile changes, reload structured dataset
wild-endeavor c8b8ab4
reload
wild-endeavor 9526c76
remove all conftest files, use env var
wild-endeavor 6ba6c34
rename test file
wild-endeavor 561d614
restore spark init file
wild-endeavor e9dafde
lint and comment
wild-endeavor 019a99e
move structured dataset stuff for spark init, copy in tests into comp…
wild-endeavor 10871ad
nit
wild-endeavor 9746f9a
can't have spark i guess
wild-endeavor b138cfe
nit
wild-endeavor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| from flytekit.configuration.sdk import USE_STRUCTURED_DATASET | ||
| from flytekit.loggers import logger | ||
|
|
||
| from .basic_dfs import ( | ||
| ArrowToParquetEncodingHandler, | ||
| PandasToParquetEncodingHandler, | ||
| ParquetToArrowDecodingHandler, | ||
| ParquetToPandasDecodingHandler, | ||
| ) | ||
|
|
||
| try: | ||
| from .bigquery import ( | ||
| ArrowToBQEncodingHandlers, | ||
| BQToArrowDecodingHandler, | ||
| BQToPandasDecodingHandler, | ||
| PandasToBQEncodingHandlers, | ||
| ) | ||
| except ImportError: | ||
| logger.info( | ||
| "We won't register bigquery handler for structured dataset because " | ||
| "we can't find the packages google-cloud-bigquery-storage and google-cloud-bigquery" | ||
| if USE_STRUCTURED_DATASET.get(): | ||
| from .basic_dfs import ( | ||
| ArrowToParquetEncodingHandler, | ||
| PandasToParquetEncodingHandler, | ||
| ParquetToArrowDecodingHandler, | ||
| ParquetToPandasDecodingHandler, | ||
| ) | ||
|
|
||
| try: | ||
| from .bigquery import ( | ||
| ArrowToBQEncodingHandlers, | ||
| BQToArrowDecodingHandler, | ||
| BQToPandasDecodingHandler, | ||
| PandasToBQEncodingHandlers, | ||
| ) | ||
| except ImportError: | ||
| logger.info( | ||
| "We won't register bigquery handler for structured dataset because " | ||
| "we can't find the packages google-cloud-bigquery-storage and google-cloud-bigquery" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| from .schema import ParquetToSparkDecodingHandler, SparkToParquetEncodingHandler | ||
| from flytekit.configuration.sdk import USE_STRUCTURED_DATASET | ||
|
|
||
| from .schema import SparkDataFrameSchemaReader, SparkDataFrameSchemaWriter, SparkDataFrameTransformer # noqa | ||
| from .task import Spark, new_spark_session | ||
|
|
||
| if USE_STRUCTURED_DATASET.get(): | ||
| from .sd_transformers import ParquetToSparkDecodingHandler, SparkToParquetEncodingHandler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
plugins/flytekit-spark/flytekitplugins/spark/sd_transformers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import typing | ||
|
|
||
| from pyspark.sql.dataframe import DataFrame | ||
|
|
||
| from flytekit import FlyteContext | ||
| from flytekit.models import literals | ||
| from flytekit.models.literals import StructuredDatasetMetadata | ||
| from flytekit.models.types import StructuredDatasetType | ||
| from flytekit.types.structured.structured_dataset import ( | ||
| FLYTE_DATASET_TRANSFORMER, | ||
| PARQUET, | ||
| StructuredDataset, | ||
| StructuredDatasetDecoder, | ||
| StructuredDatasetEncoder, | ||
| ) | ||
|
|
||
|
|
||
| class SparkToParquetEncodingHandler(StructuredDatasetEncoder): | ||
| def __init__(self, protocol: str): | ||
| super().__init__(DataFrame, protocol, PARQUET) | ||
|
|
||
| def encode( | ||
| self, | ||
| ctx: FlyteContext, | ||
| structured_dataset: StructuredDataset, | ||
| structured_dataset_type: StructuredDatasetType, | ||
| ) -> literals.StructuredDataset: | ||
| path = typing.cast(str, structured_dataset.uri) or ctx.file_access.get_random_remote_directory() | ||
| df = typing.cast(DataFrame, structured_dataset.dataframe) | ||
| df.write.mode("overwrite").parquet(path) | ||
| return literals.StructuredDataset(uri=path, metadata=StructuredDatasetMetadata(structured_dataset_type)) | ||
|
|
||
|
|
||
| class ParquetToSparkDecodingHandler(StructuredDatasetDecoder): | ||
| def __init__(self, protocol: str): | ||
| super().__init__(DataFrame, protocol, PARQUET) | ||
|
|
||
| def decode( | ||
| self, | ||
| ctx: FlyteContext, | ||
| flyte_value: literals.StructuredDataset, | ||
| ) -> DataFrame: | ||
| user_ctx = FlyteContext.current_context().user_space_params | ||
| return user_ctx.spark_session.read.parquet(flyte_value.uri) | ||
|
|
||
|
|
||
| for protocol in ["/", "s3"]: | ||
| FLYTE_DATASET_TRANSFORMER.register_handler(SparkToParquetEncodingHandler(protocol), default_for_type=True) | ||
| FLYTE_DATASET_TRANSFORMER.register_handler(ParquetToSparkDecodingHandler(protocol), default_for_type=True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.