floe-python 0.8.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- floe/__init__.py +327 -0
- floe/__main__.py +5 -0
- floe/_cli.py +302 -0
- floe/_cli_output.py +187 -0
- floe/add_entity.py +516 -0
- floe/checks/cast.py +160 -0
- floe/checks/mismatch.py +137 -0
- floe/checks/normalize.py +118 -0
- floe/checks/rows.py +116 -0
- floe/checks/unique.py +247 -0
- floe/config/__init__.py +0 -0
- floe/config/entity.py +479 -0
- floe/config/include.py +122 -0
- floe/config/parse.py +140 -0
- floe/config/profile.py +381 -0
- floe/config/project.py +404 -0
- floe/config/storage.py +179 -0
- floe/config/types.py +195 -0
- floe/config/validate.py +803 -0
- floe/config/vars.py +127 -0
- floe/config/yaml.py +263 -0
- floe/errors.py +13 -0
- floe/glob.py +300 -0
- floe/iceberg/catalog.py +345 -0
- floe/iceberg/compact.py +139 -0
- floe/iceberg/merge.py +297 -0
- floe/iceberg/sink.py +208 -0
- floe/iceberg/unique.py +61 -0
- floe/iceberg/write.py +270 -0
- floe/lineage/events.py +163 -0
- floe/lineage/observer.py +261 -0
- floe/maintain.py +134 -0
- floe/manifest.py +503 -0
- floe/manifest_run.py +299 -0
- floe/pii.py +134 -0
- floe/py.typed +0 -0
- floe/read/__init__.py +0 -0
- floe/read/avro.py +40 -0
- floe/read/csv.py +138 -0
- floe/read/json.py +236 -0
- floe/read/orc.py +42 -0
- floe/read/parquet.py +43 -0
- floe/read/xlsx.py +75 -0
- floe/read/xml.py +227 -0
- floe/report/entity.py +245 -0
- floe/report/summary.py +114 -0
- floe/run/__init__.py +175 -0
- floe/run/entity.py +963 -0
- floe/run/events.py +42 -0
- floe/state.py +311 -0
- floe/storage/__init__.py +0 -0
- floe/storage/archive.py +31 -0
- floe/storage/inputs.py +302 -0
- floe/storage/local.py +175 -0
- floe/storage/partitioning.py +116 -0
- floe/storage/paths.py +69 -0
- floe/storage/resolve.py +55 -0
- floe/storage/s3.py +182 -0
- floe/storage/types.py +33 -0
- floe/write/__init__.py +0 -0
- floe/write/outputs.py +121 -0
- floe_python-0.8.0.dist-info/METADATA +15 -0
- floe_python-0.8.0.dist-info/RECORD +66 -0
- floe_python-0.8.0.dist-info/WHEEL +4 -0
- floe_python-0.8.0.dist-info/entry_points.txt +2 -0
- floe_python-0.8.0.dist-info/licenses/LICENSE +21 -0
floe/write/outputs.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Accepted Parquet and rejected CSV writers (Rust: `io/write/{parquet,csv,parts}.rs`); `base` is a `local://` or `s3://` URI."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
import uuid
|
|
7
|
+
from collections.abc import Generator, Iterator
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from itertools import count
|
|
11
|
+
|
|
12
|
+
import polars as pl
|
|
13
|
+
|
|
14
|
+
from floe.config.types import SinkOptions, WriteMode
|
|
15
|
+
from floe.errors import FloeError, FloeStorageError
|
|
16
|
+
from floe.storage.paths import parse_s3_uri
|
|
17
|
+
from floe.storage.types import StorageClient
|
|
18
|
+
|
|
19
|
+
DEFAULT_MAX_SIZE_PER_FILE = 256 * 1024 * 1024
|
|
20
|
+
MAX_REPORTED_PARTS = 50
|
|
21
|
+
_MIB = 1024 * 1024
|
|
22
|
+
_PART = re.compile(r"part-.+")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@contextmanager
|
|
26
|
+
def _os_errors() -> Generator[None]:
|
|
27
|
+
"""An `OSError` while writing becomes a bare `FloeError`: Rust surfaces a raw `io::Error` here, which logs with code `error`."""
|
|
28
|
+
try:
|
|
29
|
+
yield
|
|
30
|
+
except (
|
|
31
|
+
OSError,
|
|
32
|
+
FloeStorageError,
|
|
33
|
+
) as e: # the storage client wraps the OSError; Rust prints the bare io::Error
|
|
34
|
+
os = e if isinstance(e, OSError) else e.__cause__
|
|
35
|
+
if not isinstance(os, OSError):
|
|
36
|
+
raise
|
|
37
|
+
raise FloeError(f"{os.strerror} (os error {os.errno})" if os.errno is not None else str(os)) from os # fmt: skip
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class AcceptedWrite:
|
|
42
|
+
"""Rust's accepted write output; the byte metrics are recorded, not compared (G5)."""
|
|
43
|
+
|
|
44
|
+
files_written: int
|
|
45
|
+
part_files: list[str]
|
|
46
|
+
total_bytes_written: int
|
|
47
|
+
avg_file_size_mb: float | None
|
|
48
|
+
small_files_count: int
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def part_uris(client: StorageClient, base: str, ext: str) -> list[str]:
|
|
52
|
+
"""The `part-*.<ext>` files directly under `base`, sorted."""
|
|
53
|
+
key = parse_s3_uri(base)[1] if base.startswith("s3://") else None
|
|
54
|
+
prefix = (
|
|
55
|
+
base.removeprefix("local://") if key is None else key and f"{key}/"
|
|
56
|
+
) # a bucket root lists every key
|
|
57
|
+
uris = (r.uri for r in client.list(prefix))
|
|
58
|
+
return sorted(u for u in uris if u.rpartition("/")[0] == base and u.endswith(f".{ext}") and _PART.fullmatch(u.rpartition("/")[2].removesuffix(f".{ext}"))) # fmt: skip
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _part_names(client: StorageClient, base: str, mode: WriteMode, ext: str) -> Iterator[str]: # fmt: skip
|
|
62
|
+
"""Overwrite clears the old parts and numbers from 0 (`part-00000`); other modes use `part-<uuid>`."""
|
|
63
|
+
if mode != "overwrite":
|
|
64
|
+
while True:
|
|
65
|
+
yield f"part-{uuid.uuid4()}.{ext}"
|
|
66
|
+
for uri in part_uris(client, base, ext):
|
|
67
|
+
client.delete(uri)
|
|
68
|
+
for i in count():
|
|
69
|
+
yield f"part-{i:05}.{ext}"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def write_accepted(
|
|
73
|
+
df: pl.DataFrame,
|
|
74
|
+
client: StorageClient,
|
|
75
|
+
base: str,
|
|
76
|
+
mode: WriteMode = "overwrite",
|
|
77
|
+
options: SinkOptions | None = None,
|
|
78
|
+
) -> AcceptedWrite:
|
|
79
|
+
"""Write `df` as `part-*.parquet` files under `base`, split so each holds about `max_size_per_file`."""
|
|
80
|
+
base = base.rstrip("/")
|
|
81
|
+
names = _part_names(client, base, mode, "parquet")
|
|
82
|
+
max_size = (options and options.max_size_per_file) or DEFAULT_MAX_SIZE_PER_FILE
|
|
83
|
+
avg_row = max(1, math.ceil(df.estimated_size() / df.height)) if df.height else 1
|
|
84
|
+
rows = max(1, max_size // avg_row)
|
|
85
|
+
kwargs: dict[str, str | int] = {}
|
|
86
|
+
if options and options.compression:
|
|
87
|
+
kwargs["compression"] = options.compression
|
|
88
|
+
if options and options.row_group_size:
|
|
89
|
+
kwargs["row_group_size"] = options.row_group_size
|
|
90
|
+
files: list[str] = []
|
|
91
|
+
sizes: list[int] = []
|
|
92
|
+
with _os_errors():
|
|
93
|
+
for chunk in [df.slice(i, rows) for i in range(0, df.height, rows)] or [df]:
|
|
94
|
+
name = next(names)
|
|
95
|
+
# ponytail: a part is held in memory (≤ max_size_per_file) before the put; stream multipart uploads if that is too much
|
|
96
|
+
body = io.BytesIO()
|
|
97
|
+
chunk.write_parquet(body, **kwargs) # pyright: ignore[reportArgumentType] # ponytail: kwargs loses the compression Literal; validated by the config
|
|
98
|
+
client.write(f"{base}/{name}", body.getvalue())
|
|
99
|
+
files.append(name)
|
|
100
|
+
sizes.append(body.tell())
|
|
101
|
+
total = sum(sizes)
|
|
102
|
+
return AcceptedWrite(
|
|
103
|
+
len(files),
|
|
104
|
+
files[:MAX_REPORTED_PARTS],
|
|
105
|
+
total,
|
|
106
|
+
total / len(files) / _MIB,
|
|
107
|
+
sum(s < max(1, max_size // 2) for s in sizes),
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def write_rejected(df: pl.DataFrame, client: StorageClient, base: str, mode: WriteMode = "overwrite", key: str | None = None) -> str: # fmt: skip
|
|
112
|
+
"""Write the rejected frame from `split_rows` as one CSV part under `base`; returns its URI.
|
|
113
|
+
|
|
114
|
+
With a `key` (the run's input hash and the file) a non-overwrite part is named from it, so a retry rewrites the same part (S6, #919); Rust has no retry guard.
|
|
115
|
+
"""
|
|
116
|
+
with _os_errors():
|
|
117
|
+
base = base.rstrip("/")
|
|
118
|
+
name = f"part-{uuid.uuid5(uuid.NAMESPACE_URL, key)}.csv" if key and mode != "overwrite" else next(_part_names(client, base, mode, "csv")) # fmt: skip
|
|
119
|
+
uri = f"{base}/{name}"
|
|
120
|
+
client.write(uri, df.write_csv().encode())
|
|
121
|
+
return uri
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: floe-python
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Floe: a data-contract runtime for file ingestion
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: boto3>=1.43.118
|
|
8
|
+
Requires-Dist: duckdb==1.5.6
|
|
9
|
+
Requires-Dist: fastexcel>=0.21.0
|
|
10
|
+
Requires-Dist: polars>=2.0.0
|
|
11
|
+
Requires-Dist: pyarrow>=26.0.0
|
|
12
|
+
Requires-Dist: pydantic>=2.14.1
|
|
13
|
+
Requires-Dist: pyiceberg-core>=0.10.1
|
|
14
|
+
Requires-Dist: pyiceberg>=0.12.0
|
|
15
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
floe/__init__.py,sha256=VkSVWF7vzIICTkxaNI2SVXfD2JQmrHtV_NiTBCUwzaM,13221
|
|
2
|
+
floe/__main__.py,sha256=Nzz6wrGXRpJiO59qlX7WEJRTlb-XcRFswmP0TA2KjyM,57
|
|
3
|
+
floe/_cli.py,sha256=2ecJIMELxfXkm3ISzvQsS-CnnjUBj1Kqh9HANlUlMCM,13549
|
|
4
|
+
floe/_cli_output.py,sha256=fwUqMkBvUEojri8WnXGzTIHMZLcoOHQfByeOz5L6ugA,8792
|
|
5
|
+
floe/add_entity.py,sha256=42b7l8o55dzgaR_DDgpW7YWdnU2weYMf4U_rf7qCY6M,21986
|
|
6
|
+
floe/errors.py,sha256=hLSkgPQATBnjY1CAQqX4aB0oI0-WKoHW09bDXAgzC7k,186
|
|
7
|
+
floe/glob.py,sha256=A0HdePLXLGl1T6heJbgdrNHr8pZfdidG7pQ1QsXWOl8,10579
|
|
8
|
+
floe/maintain.py,sha256=CGSoZhO7p0u14o10FCKCO4FprzpVO548A71eq5FowF8,7343
|
|
9
|
+
floe/manifest.py,sha256=HV3y-WzZeorVpTAGrNU9LuZCbvX8ALfGC9J3Q2jtnYY,19425
|
|
10
|
+
floe/manifest_run.py,sha256=8m4LXaymkw3ZX706sTjZK5L1hOYDT231CWl9tjoBe1c,12700
|
|
11
|
+
floe/pii.py,sha256=uJjU-C4c7h45E7rEL9K3Zp1LTTLh-FNKfUV5av2QMO4,4351
|
|
12
|
+
floe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
floe/state.py,sha256=XFHF6zVxbdGg1bkONZDLryTD4noDF9IgaimaEI-3Nlg,11104
|
|
14
|
+
floe/checks/cast.py,sha256=lM40xtKEggWI8FW3jijM3T2JFQtaXs8FhsFXo3vy5oM,6788
|
|
15
|
+
floe/checks/mismatch.py,sha256=2Gz-tiWKxy-iehSjAlsGzPLtYeNIfBWvi4yQPlASVYQ,5309
|
|
16
|
+
floe/checks/normalize.py,sha256=INYh3NO3JkdgDjTXDi7pylr79nzrJmDuBlrIrm_8LRc,4326
|
|
17
|
+
floe/checks/rows.py,sha256=E-YUZUvBUyOB7zat2dtbPWFM-0T1-01lYKuQU1A6wto,4156
|
|
18
|
+
floe/checks/unique.py,sha256=BUu6ezLtQKj8_9_SybGND6rxbUbzlmqh_WJomTHRfGw,9782
|
|
19
|
+
floe/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
floe/config/entity.py,sha256=CLXLXzkUbQhxenD_LwjBt0eoPreaYaxiBVEsdmnFIco,15883
|
|
21
|
+
floe/config/include.py,sha256=XKYhp2QK_VUmAODAXJ35Wl4FCpQEMQm24m-WKlpI_og,5033
|
|
22
|
+
floe/config/parse.py,sha256=B3gOi80-M0y9Y4OyNjM4MYmM2mFHKGVpqipX1JqaLjM,5290
|
|
23
|
+
floe/config/profile.py,sha256=xlLbrMbD_prJ0UteoSUNwbmjOq5NMm6XmQvxQNg4WxI,14035
|
|
24
|
+
floe/config/project.py,sha256=zgTOhTDlbMr1chViMEZyv0drozZdumTaIoKDL0vv9sw,14141
|
|
25
|
+
floe/config/storage.py,sha256=Yjia1mfxWvIq7DpS24AFSCQDeJ4aqxY9s76WDDrqMv4,5452
|
|
26
|
+
floe/config/types.py,sha256=4eveoOlyGmNxyZpI1PSjli9lnXLPc1-jYj4fL8qHN_8,5038
|
|
27
|
+
floe/config/validate.py,sha256=4m71oZgvKFH61Ts6TASlLZ_JDnPEjWo4cfGcoJOLGQY,34963
|
|
28
|
+
floe/config/vars.py,sha256=7Bq0IU0KrFeRlyA8W9-F0gDSDKfXCfFpBrX08H8Flvw,4577
|
|
29
|
+
floe/config/yaml.py,sha256=HeFGhKFxYkiqQOwljYOgUD5naJyxL_ZIX6hUIS36tzU,10071
|
|
30
|
+
floe/iceberg/catalog.py,sha256=nRRC4VyjKEXATlifmlE2394e8b5vAO_HiIp0LugS5tI,13819
|
|
31
|
+
floe/iceberg/compact.py,sha256=5O372vAIsvgRc2PGihryAsrQ0otn0F30AQu-cetRCP0,7123
|
|
32
|
+
floe/iceberg/merge.py,sha256=VE1Odf2B34Gxj7ZcuhbrfbgTGM9AdiDz6_2BbcQ-kSQ,12448
|
|
33
|
+
floe/iceberg/sink.py,sha256=2pWrixvqC9_ZNKvGAJju4-TfKOqFoYR28agllUt9AXA,10804
|
|
34
|
+
floe/iceberg/unique.py,sha256=PKUFEcCkU71k66__KfUE7NTos73ZYlZbb8GJPn0yFoo,2958
|
|
35
|
+
floe/iceberg/write.py,sha256=zrFeeJu-YT4Pxo9u-fRujUtFb1Epx1KFoq2qFyP1iGs,11036
|
|
36
|
+
floe/lineage/events.py,sha256=4txd8bGUwKBZd-8Aw_ebTurhlxAYk8SVMgH8vSjC3bs,6682
|
|
37
|
+
floe/lineage/observer.py,sha256=dDYfWvPpFGjdqvFqQDZ2pTjj7uDfqji2-BTID9hzg90,10075
|
|
38
|
+
floe/read/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
|
+
floe/read/avro.py,sha256=rhGYlrWGFnqt_tyLIph57qV2TH91ULjoJ5qUlpW_6jI,1419
|
|
40
|
+
floe/read/csv.py,sha256=5nXUGBa2s2Tt790UvOcrvfDym906JYjyhgunV6xPzr4,5153
|
|
41
|
+
floe/read/json.py,sha256=dPUXNlQUmMeYId3lef8ssEQeHi0tIOoEblvMQDmNVt4,8284
|
|
42
|
+
floe/read/orc.py,sha256=TWgdlLBR2NF_oVZ5zEmRKNXoTkq5QfF2BOFzKyzSjhY,1553
|
|
43
|
+
floe/read/parquet.py,sha256=JwfuWaHj2TxBKJeaKignq8p0Op_pUfsOdVh7dDC3wcE,1491
|
|
44
|
+
floe/read/xlsx.py,sha256=dengSY8HuNh9ahyR_LR8beqXTZQubqQ1Jx8qEak5jrY,3009
|
|
45
|
+
floe/read/xml.py,sha256=7m6DtoU8iExuLROavyojysqOUE_Bd_N0uwFaLAzjI_Y,8004
|
|
46
|
+
floe/report/entity.py,sha256=ekuB-1JDATvxIFnBTCQpku8uXtrSQNwvryjdTidXk6I,9707
|
|
47
|
+
floe/report/summary.py,sha256=tb547VRkM5WGWHQ-4vZB2DUW4VTWgv9FUoym-NpuWE4,4452
|
|
48
|
+
floe/run/__init__.py,sha256=PON2NYpvsRej6cXBPP8GDRZMcinVTtnKpwLT93Vzg0c,7687
|
|
49
|
+
floe/run/entity.py,sha256=4UGhUtjYR84MOe3jjwFmLGWAaDln1z5KOHC0MOvDLpQ,45204
|
|
50
|
+
floe/run/events.py,sha256=OE7zYkt0Dz2xrvgNavT1nHfZJ-97IIJ8LpHcameUJZU,2859
|
|
51
|
+
floe/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
|
+
floe/storage/archive.py,sha256=1gPImm9PDSJFCpWjg37ax4ubb0wwc6FZm38quQXhORg,1101
|
|
53
|
+
floe/storage/inputs.py,sha256=nmgEo2ub3hPUghLUXHU1wnKzpL4aYZbHb6S0XPYvMew,10410
|
|
54
|
+
floe/storage/local.py,sha256=NKjBf_-PkDnbZ3FzXWE7KZ1xY0G_o3tRy0_7nxW7FLs,6307
|
|
55
|
+
floe/storage/partitioning.py,sha256=MG8RJDrwgZhucTswlXC2RwCmzrYIoOE6SH_aBM11KW8,6178
|
|
56
|
+
floe/storage/paths.py,sha256=Z0fry3Gp0Tu2DpUeKqNXdqYP6n_KcKzK2llGx0TGHB8,2343
|
|
57
|
+
floe/storage/resolve.py,sha256=pFAuVytTfnSEcTAVlJjFTj7S_Vipjry1ormWZP3Egmc,2593
|
|
58
|
+
floe/storage/s3.py,sha256=iWLDr3-qFH-Of3HKUiaKFD-1HQRip4FSQ-q9xxv7VNI,7212
|
|
59
|
+
floe/storage/types.py,sha256=FvAEXWMdVdopRK276JyETRYGOva2-uR8pZvsWj6Xvy0,993
|
|
60
|
+
floe/write/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
61
|
+
floe/write/outputs.py,sha256=5LgN_8PMPPOgkRVZw_KvxYXmc02-meL7iZLeMKVtufQ,4932
|
|
62
|
+
floe_python-0.8.0.dist-info/METADATA,sha256=jQyy8j3vSQ6Qs047OQASPHOEnq5UV02wpXavZ3MHf7U,444
|
|
63
|
+
floe_python-0.8.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
64
|
+
floe_python-0.8.0.dist-info/entry_points.txt,sha256=DU75r-E3zcK0quvwg5iT5DeWbUJck_Tz80bEj1IIzHA,40
|
|
65
|
+
floe_python-0.8.0.dist-info/licenses/LICENSE,sha256=dUhuoK-TCRQMpuLEAdfme-qPSJI0TlcH9jlNxeg9_EQ,1056
|
|
66
|
+
floe_python-0.8.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|