df-etl-cli 0.1.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.
- df_etl_cli-0.1.0.dist-info/METADATA +249 -0
- df_etl_cli-0.1.0.dist-info/RECORD +25 -0
- df_etl_cli-0.1.0.dist-info/WHEEL +4 -0
- df_etl_cli-0.1.0.dist-info/entry_points.txt +2 -0
- df_etl_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
- dfio/__init__.py +6 -0
- dfio/base.py +58 -0
- dfio/cli.py +70 -0
- dfio/engine.py +36 -0
- dfio/etl.py +116 -0
- dfio/graph.py +174 -0
- dfio/node.py +81 -0
- dfio/registry.py +84 -0
- dfio/runner.py +48 -0
- dfio/sources/__init__.py +0 -0
- dfio/sources/console.py +32 -0
- dfio/sources/parquet.py +34 -0
- dfio/sources/text.py +109 -0
- dfio/sources/values.py +47 -0
- dfio/transforms/__init__.py +0 -0
- dfio/transforms/flatten.py +77 -0
- dfio/transforms/identity.py +15 -0
- dfio/transforms/sql.py +51 -0
- dfio/types.py +36 -0
- dfio/uri.py +110 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: df-etl-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: URI-based, engine-agnostic ETL (Python port of dataframe-io, built on Ibis)
|
|
5
|
+
Project-URL: Homepage, https://github.com/nightscape/df-etl-cli
|
|
6
|
+
Project-URL: Repository, https://github.com/nightscape/df-etl-cli
|
|
7
|
+
Project-URL: Issues, https://github.com/nightscape/df-etl-cli/issues
|
|
8
|
+
Author-email: Martin Mauch <martin.mauch@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: data-engineering,dataframe,duckdb,etl,ibis,polars
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: ibis-framework[duckdb]>=9.0
|
|
23
|
+
Requires-Dist: pyyaml>=6
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: hypothesis>=6.100; extra == 'dev'
|
|
26
|
+
Requires-Dist: ibis-framework[polars]>=9.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
30
|
+
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
31
|
+
Provides-Extra: polars
|
|
32
|
+
Requires-Dist: ibis-framework[polars]>=9.0; extra == 'polars'
|
|
33
|
+
Provides-Extra: pyspark
|
|
34
|
+
Requires-Dist: ibis-framework[pyspark]>=9.0; extra == 'pyspark'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# DataFrame IO (Python)
|
|
38
|
+
|
|
39
|
+
A Python port of the Scala [`dataframe-io`](../README.md) library. DataFrame IO
|
|
40
|
+
allows you to
|
|
41
|
+
|
|
42
|
+
* read data from various **sources**
|
|
43
|
+
* transform it using various **transformers**
|
|
44
|
+
* write data to various **sinks**
|
|
45
|
+
|
|
46
|
+
by specifying source, transform and sink URIs.
|
|
47
|
+
|
|
48
|
+
Unlike the original, which is built on Apache Spark, this port is built on
|
|
49
|
+
[Ibis](https://ibis-project.org/) — a portable dataframe API. Ibis is the
|
|
50
|
+
dataframe abstraction: the same pipeline runs on any Ibis backend (duckdb,
|
|
51
|
+
polars, pyspark, postgres, …) by changing a single `--engine` flag, with no
|
|
52
|
+
change to the pipeline itself. The default backend is duckdb.
|
|
53
|
+
|
|
54
|
+
The URI schema is
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
protocol://host/path?queryParam1=value1&queryParam2=value2
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The protocol decides which source or sink is actually used. Currently, the
|
|
61
|
+
following options for sources and sinks are available:
|
|
62
|
+
|
|
63
|
+
* [Console](#console) (`console://`)
|
|
64
|
+
* [Values](#values) (`values://`)
|
|
65
|
+
* [Text](#text) (CSV, TSV) (`text://`)
|
|
66
|
+
* [Parquet](#parquet) (`parquet://`)
|
|
67
|
+
|
|
68
|
+
For transformations, the following options are available:
|
|
69
|
+
|
|
70
|
+
* [Identity](#identity) (`identity://`)
|
|
71
|
+
* [SQL](#sql) (`sql://`)
|
|
72
|
+
* [SQL-file](#sql-file) (`sql-file://`)
|
|
73
|
+
* [Flatten](#flatten) (`flatten://`)
|
|
74
|
+
* [Flatten and explode](#flatten-and-explode) (`flatten-explode://`)
|
|
75
|
+
|
|
76
|
+
> Delta, Excel, Hive, Kafka, Solr, Avro and streaming sources from the Scala
|
|
77
|
+
> version are **not yet ported**.
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
uv venv --python 3.12
|
|
83
|
+
uv pip install -e '.[dev]' # add ,polars or ,pyspark for those engines
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Running
|
|
87
|
+
|
|
88
|
+
### CLI
|
|
89
|
+
|
|
90
|
+
The package installs a `dfio` console script that wires `--source`,
|
|
91
|
+
`--transform`, and `--sink` URIs into a pipeline. Each option may be repeated.
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
dfio --source 'data+text:///path/to/in.csv' \
|
|
95
|
+
--transform 'data+out+sql:///SELECT%20*%20FROM%20data%20WHERE%20n%3E1' \
|
|
96
|
+
--sink 'out+parquet:///path/to/out.parquet'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Select a different engine — the rest of the pipeline is unchanged:
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
dfio --engine polars --source ... --sink ...
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`dfio --help` lists the available schemes.
|
|
106
|
+
|
|
107
|
+
### Python API
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from dfio import ETL, Source, Transformation, Sink
|
|
111
|
+
|
|
112
|
+
ETL(
|
|
113
|
+
sources=[Source.parse("data+text:///path/to/in.csv")],
|
|
114
|
+
transforms=[Transformation.parse("data+out+sql:///SELECT * FROM data WHERE n > 1")],
|
|
115
|
+
sinks=[Sink.parse("out+parquet:///path/to/out.parquet")],
|
|
116
|
+
backend="duckdb",
|
|
117
|
+
).run()
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Source and Sink URI schemas
|
|
121
|
+
|
|
122
|
+
The URI schema for sources and sinks generally looks like this
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
dfToReadInto+sourceType://some-host/some-path?additional=parameters
|
|
126
|
+
sourceType://some-host/some-path?additional=parameters
|
|
127
|
+
|
|
128
|
+
dfToPersist+sinkType://some-host/some-path?additional=parameters
|
|
129
|
+
sinkType://some-host/some-path?additional=parameters
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The possible options for `sourceType` and `sinkType` are listed below.
|
|
133
|
+
The `dfToReadInto` is used to save the result of reading the source. If not
|
|
134
|
+
specified, it defaults to `"source"`.
|
|
135
|
+
The `dfToPersist` is the name of the DataFrame that should be persisted to the
|
|
136
|
+
sink. If not specified, it defaults to `"sink"`.
|
|
137
|
+
|
|
138
|
+
Both `dfToReadInto` and `dfToPersist` are optional. Because they live in the URI
|
|
139
|
+
*scheme*, they must be valid scheme characters: use hyphens, not underscores
|
|
140
|
+
(hyphens are normalized to underscores internally so names are valid SQL
|
|
141
|
+
identifiers, e.g. `my-data` becomes the table `my_data`).
|
|
142
|
+
|
|
143
|
+
### Console
|
|
144
|
+
```
|
|
145
|
+
console://anything
|
|
146
|
+
```
|
|
147
|
+
The source returns an empty DataFrame.
|
|
148
|
+
The sink prints an excerpt of the DataFrame to the console.
|
|
149
|
+
|
|
150
|
+
### Values
|
|
151
|
+
```
|
|
152
|
+
values:///?header=foo:int,bar:string&values=1,a;2,b
|
|
153
|
+
```
|
|
154
|
+
The source returns a DataFrame with column names and types specified in `header`
|
|
155
|
+
and values specified in `values` (rows separated by `;`, cells by `,`).
|
|
156
|
+
Supported types are `int`, `long`, `double`; anything else is `string`.
|
|
157
|
+
The sink prints an excerpt of the DataFrame to the console.
|
|
158
|
+
|
|
159
|
+
### Text
|
|
160
|
+
```
|
|
161
|
+
text:///path/to/some.csv
|
|
162
|
+
```
|
|
163
|
+
Reads/writes CSV or TSV files, with the delimiter determined by file extension
|
|
164
|
+
(`.csv` → `,`, `.tsv` → tab). `?header=` defaults to `true`. CSV IO is routed
|
|
165
|
+
through Apache Arrow so behaviour is identical across every engine.
|
|
166
|
+
|
|
167
|
+
### Parquet
|
|
168
|
+
```
|
|
169
|
+
parquet:///path/to/file.parquet
|
|
170
|
+
```
|
|
171
|
+
Reads/writes Parquet at the given path.
|
|
172
|
+
|
|
173
|
+
## Transformation URI Schemas
|
|
174
|
+
|
|
175
|
+
The URI schema for transformations generally looks like this
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
sourceName+sinkName+transformationType://some-host/some-path?additional=parameters
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The `sourceName` is the previously named intermediate DataFrame used as input.
|
|
182
|
+
By default it is `"source"`. The `sinkName` registers the result under a name;
|
|
183
|
+
by default `"sink"`. Both can be specified or omitted:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
transformationType:// # both default to "source"/"sink"
|
|
187
|
+
sourceName+transformationType:// # only sourceName given
|
|
188
|
+
sourceName+sinkName+transformationType:// # both given
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Identity
|
|
192
|
+
```
|
|
193
|
+
sourceName+sinkName+identity:///
|
|
194
|
+
```
|
|
195
|
+
Renames a DataFrame from `sourceName` to `sinkName` (passthrough).
|
|
196
|
+
|
|
197
|
+
### SQL
|
|
198
|
+
```
|
|
199
|
+
sql:///SELECT%20foo%20AS%20bar%20FROM%20sourceName
|
|
200
|
+
```
|
|
201
|
+
Applies inline SQL to its input. The SQL must be URL encoded (a space is `%20`)
|
|
202
|
+
and follow the triple slash `sql:///`. The query runs against the engine's
|
|
203
|
+
catalog, so it may reference any previously registered named DataFrame by name.
|
|
204
|
+
This is only convenient for short queries.
|
|
205
|
+
|
|
206
|
+
The SQL is parsed in a fixed dialect (`duckdb` by default) and transpiled by Ibis
|
|
207
|
+
to whichever engine runs it, so the *same* query means the same thing on every
|
|
208
|
+
backend rather than being reinterpreted per engine. Override the input dialect
|
|
209
|
+
with `?dialect=` (e.g. `sql:///<encoded>?dialect=postgres`).
|
|
210
|
+
|
|
211
|
+
### SQL-File
|
|
212
|
+
```
|
|
213
|
+
sql-file:///path/to/query.sql
|
|
214
|
+
```
|
|
215
|
+
Applies SQL read from a file to its input. The referenced tables must have been
|
|
216
|
+
registered in a previous step.
|
|
217
|
+
|
|
218
|
+
### Flatten
|
|
219
|
+
```
|
|
220
|
+
sourceName+sinkName+flatten:///
|
|
221
|
+
```
|
|
222
|
+
Recursively unpacks nested struct columns into `parent_child` columns.
|
|
223
|
+
|
|
224
|
+
### Flatten and explode
|
|
225
|
+
```
|
|
226
|
+
sourceName+sinkName+flatten-explode:///
|
|
227
|
+
```
|
|
228
|
+
Recursively unpacks struct columns **and** explodes array columns into rows.
|
|
229
|
+
|
|
230
|
+
## Extending with plugins
|
|
231
|
+
|
|
232
|
+
External packages register new schemes via entry points, the Python analogue of
|
|
233
|
+
the Scala `ServiceLoader`:
|
|
234
|
+
|
|
235
|
+
```toml
|
|
236
|
+
[project.entry-points."dfio.sources"]
|
|
237
|
+
my-scheme = "my_package:MyUriParser"
|
|
238
|
+
|
|
239
|
+
[project.entry-points."dfio.transforms"]
|
|
240
|
+
my-transform = "my_package:MyTransformerParser"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Tests
|
|
244
|
+
|
|
245
|
+
Tests are property-based, using [Hypothesis](https://hypothesis.readthedocs.io/):
|
|
246
|
+
|
|
247
|
+
```sh
|
|
248
|
+
.venv/bin/pytest | tee test-output.txt
|
|
249
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
dfio/__init__.py,sha256=089oHViIDLmIzFFbw71pNGn4ddUaxz9d7VdbZxwrvnc,232
|
|
2
|
+
dfio/base.py,sha256=OTojCNLzyP4IoUHOQOBdax3YUdoy8aZkzzEk8ygzYyQ,1597
|
|
3
|
+
dfio/cli.py,sha256=GvrcBe_aep0UH9lf7nJmt_ePKlaGsbQEQedr8zDUdkU,2312
|
|
4
|
+
dfio/engine.py,sha256=cc-07GSF4K7QAdozJJXzQb33YaXh4xiXIReH4yJUhqY,1268
|
|
5
|
+
dfio/etl.py,sha256=wzJ5mN3_FegB0B4AWDwwK9-zfqEEMDML0VTMDywgmSc,3649
|
|
6
|
+
dfio/graph.py,sha256=UwlTo3ye80_IP7_S4fVwwJn7KkmFE0_koPxVIbf7_MQ,6200
|
|
7
|
+
dfio/node.py,sha256=XpSAUJhpzQZTkSmZCwYYtARWvWVirXVsfrgKLlwLYNk,2824
|
|
8
|
+
dfio/registry.py,sha256=aUYZ0HsD3IKfTZ6CE3ViLHp0Eodu66eSPwGSPjA_6H4,2666
|
|
9
|
+
dfio/runner.py,sha256=dZguFSJYxdruWp5Zmk2Q0nh14XuWNit6rRSgG9gEGqM,1712
|
|
10
|
+
dfio/types.py,sha256=a9H4wopATeQLyBgNvQfKr7OqUVzPE6DIIKgYQpadHLk,1072
|
|
11
|
+
dfio/uri.py,sha256=SRwGyH5aUDy1W9AgImT7DADGvBKaT7FOrqScw-PwjT8,3718
|
|
12
|
+
dfio/sources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
dfio/sources/console.py,sha256=VLkAgqKSO8jvSb7OkPHF2sbxAwHnDyet2gwf_KU9yA4,777
|
|
14
|
+
dfio/sources/parquet.py,sha256=XFZIcXvBR9TQgM9pjAnwxyIcfj2aN83Y7E0qc6OPN88,869
|
|
15
|
+
dfio/sources/text.py,sha256=vmUMlanLk6dwwZoDCCHFGsH9M98CawbIvba3qIeBw88,4036
|
|
16
|
+
dfio/sources/values.py,sha256=7JgeceUXDF9E6UMeTltrHobTv7V1zm6YVzGc54NJbQc,1579
|
|
17
|
+
dfio/transforms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
dfio/transforms/flatten.py,sha256=OhEchjrwKMOljf-MwLfBDaDt0L0mMaXDJQZOXUcPKAE,2482
|
|
19
|
+
dfio/transforms/identity.py,sha256=slIiN3IigeJaTYMqt2czYQh-VGj6Au9L2X1W8vXv24I,421
|
|
20
|
+
dfio/transforms/sql.py,sha256=orzjzLGuQxPL89sxPaHuplfdqmUd1xaKTdvUdgA86Dc,1986
|
|
21
|
+
df_etl_cli-0.1.0.dist-info/METADATA,sha256=MLEMVmxPFXNS59JNjyaoqCqhwnK3oRuViMJ4qsvJWic,8002
|
|
22
|
+
df_etl_cli-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
23
|
+
df_etl_cli-0.1.0.dist-info/entry_points.txt,sha256=lGnAZMCOzN-zu_IzyvS8dfNk2eEdaIvpHEkNLs0toRY,39
|
|
24
|
+
df_etl_cli-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
25
|
+
df_etl_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
dfio/__init__.py
ADDED
dfio/base.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Core abstractions, ported from the Scala traits.
|
|
2
|
+
|
|
3
|
+
- ``DataFrameSource`` / ``DataFrameSink`` (DataFrameSource.scala, DataFrameSink.scala)
|
|
4
|
+
- ``UriParser`` (DataFrameUriParser.scala)
|
|
5
|
+
- ``TransformerParser`` (TransformerParser.scala)
|
|
6
|
+
|
|
7
|
+
A ``UriParser`` builds a source/sink from a parsed URI and the engine. A
|
|
8
|
+
``TransformerParser`` builds a ``Table -> Table`` function.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from abc import ABC, abstractmethod
|
|
14
|
+
from typing import Callable, Protocol, runtime_checkable
|
|
15
|
+
|
|
16
|
+
import ibis
|
|
17
|
+
|
|
18
|
+
from .engine import Engine
|
|
19
|
+
from .uri import ParsedUri
|
|
20
|
+
|
|
21
|
+
Transformer = Callable[[ibis.Table], ibis.Table]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@runtime_checkable
|
|
25
|
+
class DataFrameSource(Protocol):
|
|
26
|
+
def read(self) -> ibis.Table: ...
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@runtime_checkable
|
|
30
|
+
class DataFrameSink(Protocol):
|
|
31
|
+
def write(self, table: ibis.Table) -> bool: ...
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class UriParser(ABC):
|
|
35
|
+
"""Builds a source and/or sink for a set of URI schemes."""
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def schemes(self) -> list[str]: ...
|
|
40
|
+
|
|
41
|
+
def is_defined_at(self, uri: ParsedUri) -> bool:
|
|
42
|
+
return uri.scheme_and_name()[0] in self.schemes
|
|
43
|
+
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def build(self, uri: ParsedUri, engine: Engine) -> object:
|
|
46
|
+
"""Return an object implementing DataFrameSource and/or DataFrameSink."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TransformerParser(ABC):
|
|
50
|
+
@property
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def schemes(self) -> list[str]: ...
|
|
53
|
+
|
|
54
|
+
def is_defined_at(self, uri: ParsedUri) -> bool:
|
|
55
|
+
return uri.scheme_source_sink()[0] in self.schemes
|
|
56
|
+
|
|
57
|
+
@abstractmethod
|
|
58
|
+
def build(self, uri: ParsedUri) -> Transformer: ...
|
dfio/cli.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""``dfio`` command line. Ports the ETL.scala mainargs interface.
|
|
2
|
+
|
|
3
|
+
dfio --source name+scheme://... --transform src+sink+scheme://... --sink ...
|
|
4
|
+
|
|
5
|
+
``--source``/``--sink``/``--transform`` may be repeated. ``--engine`` selects the
|
|
6
|
+
Ibis backend (duckdb default), the lever that makes the same pipeline run on a
|
|
7
|
+
different dataframe implementation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
|
|
14
|
+
from .engine import Engine
|
|
15
|
+
from .etl import ETL, Sink, Source, Transformation
|
|
16
|
+
from .graph import Graph
|
|
17
|
+
from .registry import source_sink_schemes, transform_schemes
|
|
18
|
+
from .runner import run_nodes
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
22
|
+
parser = argparse.ArgumentParser(
|
|
23
|
+
prog="dfio",
|
|
24
|
+
description="URI-based, engine-agnostic ETL (built on Ibis).",
|
|
25
|
+
)
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--source", action="append", default=[], metavar="URI",
|
|
28
|
+
help=f"Source URI (repeatable). Schemes: {sorted(source_sink_schemes())}",
|
|
29
|
+
)
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"--transform", action="append", default=[], metavar="URI",
|
|
32
|
+
help=f"Transform URI (repeatable). Schemes: {sorted(transform_schemes())}",
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--sink", action="append", default=[], metavar="URI",
|
|
36
|
+
help="Sink URI (repeatable).",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument(
|
|
39
|
+
"--graph", metavar="PATH",
|
|
40
|
+
help="Declarative graph file (.json/.yaml). Mutually exclusive with "
|
|
41
|
+
"--source/--transform/--sink.",
|
|
42
|
+
)
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"--engine", default="duckdb", help="Ibis backend (default: duckdb).",
|
|
45
|
+
)
|
|
46
|
+
return parser
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main(argv: list[str] | None = None) -> None:
|
|
50
|
+
args = build_parser().parse_args(argv)
|
|
51
|
+
if args.graph:
|
|
52
|
+
assert not (args.source or args.transform or args.sink), (
|
|
53
|
+
"--graph cannot be combined with --source/--transform/--sink"
|
|
54
|
+
)
|
|
55
|
+
engine = Engine.from_config(args.engine)
|
|
56
|
+
nodes = Graph.load(args.graph).compile()
|
|
57
|
+
run_nodes(nodes, engine)
|
|
58
|
+
print("Write successful")
|
|
59
|
+
return
|
|
60
|
+
etl = ETL(
|
|
61
|
+
sources=[Source.parse(s) for s in args.source],
|
|
62
|
+
sinks=[Sink.parse(s) for s in args.sink],
|
|
63
|
+
transforms=[Transformation.parse(t) for t in args.transform],
|
|
64
|
+
backend=args.engine,
|
|
65
|
+
)
|
|
66
|
+
etl.run()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
dfio/engine.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""The execution engine: an Ibis backend connection plus a named-table catalog.
|
|
2
|
+
|
|
3
|
+
Replaces Spark's ``SparkSession``. ``register``/``table`` mirror
|
|
4
|
+
``createOrReplaceTempView``/``spark.table`` — named tables are also registered as
|
|
5
|
+
views in the backend so the SQL transformer can reference them by name.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import ibis
|
|
11
|
+
from ibis.backends import BaseBackend
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Engine:
|
|
15
|
+
def __init__(self, backend: BaseBackend, name: str = "duckdb"):
|
|
16
|
+
self.con = backend
|
|
17
|
+
self.backend_name = name
|
|
18
|
+
self._catalog: dict[str, ibis.Table] = {}
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_config(cls, backend: str = "duckdb") -> "Engine":
|
|
22
|
+
con = ibis.connect(f"{backend}://")
|
|
23
|
+
return cls(con, name=backend)
|
|
24
|
+
|
|
25
|
+
def register(self, name: str, table: ibis.Table) -> ibis.Table:
|
|
26
|
+
"""Register ``table`` under ``name`` and expose it as a backend view."""
|
|
27
|
+
view = self.con.create_view(name, table, overwrite=True)
|
|
28
|
+
self._catalog[name] = view
|
|
29
|
+
return view
|
|
30
|
+
|
|
31
|
+
def table(self, name: str) -> ibis.Table:
|
|
32
|
+
if name not in self._catalog:
|
|
33
|
+
raise KeyError(
|
|
34
|
+
f"No table named {name!r} in catalog; known: {sorted(self._catalog)}"
|
|
35
|
+
)
|
|
36
|
+
return self._catalog[name]
|