|
| 1 | +import tempfile |
1 | 2 | import typing |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 |
|
5 | 6 | import flytekit.configuration |
6 | 7 | from flytekit.configuration import Image, ImageConfig |
7 | 8 | from flytekit.core.context_manager import FlyteContext, FlyteContextManager |
| 9 | +from flytekit.core.data_persistence import FileAccessProvider |
8 | 10 | from flytekit.core.type_engine import TypeEngine |
9 | 11 | from flytekit.models import literals |
10 | 12 | from flytekit.models.literals import StructuredDatasetMetadata |
|
20 | 22 |
|
21 | 23 | from flytekit import kwtypes, task |
22 | 24 | from flytekit.types.structured.structured_dataset import ( |
| 25 | + LOCAL, |
23 | 26 | PARQUET, |
24 | | - S3, |
25 | 27 | StructuredDataset, |
26 | 28 | StructuredDatasetDecoder, |
27 | 29 | StructuredDatasetEncoder, |
@@ -336,7 +338,7 @@ def test_to_python_value_without_incoming_columns(): |
336 | 338 | def test_format_correct(): |
337 | 339 | class TempEncoder(StructuredDatasetEncoder): |
338 | 340 | def __init__(self): |
339 | | - super().__init__(pd.DataFrame, S3, "avro") |
| 341 | + super().__init__(pd.DataFrame, LOCAL, "avro") |
340 | 342 |
|
341 | 343 | def encode( |
342 | 344 | self, |
@@ -375,3 +377,21 @@ def t1() -> Annotated[StructuredDataset, "avro"]: |
375 | 377 | return StructuredDataset(dataframe=df) |
376 | 378 |
|
377 | 379 | assert t1().file_format == "avro" |
| 380 | + |
| 381 | + |
| 382 | +def test_protocol_detection(): |
| 383 | + # We've don't register defaults to the transformer engine |
| 384 | + assert pd.DataFrame not in StructuredDatasetTransformerEngine.DEFAULT_PROTOCOLS |
| 385 | + e = StructuredDatasetTransformerEngine() |
| 386 | + ctx = FlyteContextManager.current_context() |
| 387 | + protocol = e._protocol_from_type_or_prefix(ctx, pd.DataFrame) |
| 388 | + assert protocol == "/" |
| 389 | + |
| 390 | + with tempfile.TemporaryDirectory() as tmp_dir: |
| 391 | + fs = FileAccessProvider(local_sandbox_dir=tmp_dir, raw_output_prefix="s3://fdsa") |
| 392 | + ctx2 = ctx.with_file_access(fs).build() |
| 393 | + protocol = e._protocol_from_type_or_prefix(ctx2, pd.DataFrame) |
| 394 | + assert protocol == "s3" |
| 395 | + |
| 396 | + protocol = e._protocol_from_type_or_prefix(ctx2, pd.DataFrame, "bq://foo") |
| 397 | + assert protocol == "bq" |
0 commit comments