datashard 0.1.1__tar.gz
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.
- datashard-0.1.1/.readthedocs.yaml +13 -0
- datashard-0.1.1/LICENSE +201 -0
- datashard-0.1.1/PKG-INFO +172 -0
- datashard-0.1.1/README.txt +126 -0
- datashard-0.1.1/datashard/__init__.py +24 -0
- datashard-0.1.1/docs/README.md +149 -0
- datashard-0.1.1/docs/conf.py +40 -0
- datashard-0.1.1/mapping.txt +131 -0
- datashard-0.1.1/pyproject.toml +155 -0
- datashard-0.1.1/setup.cfg +4 -0
- datashard-0.1.1/src/datashard.egg-info/PKG-INFO +172 -0
- datashard-0.1.1/src/datashard.egg-info/SOURCES.txt +21 -0
- datashard-0.1.1/src/datashard.egg-info/dependency_links.txt +1 -0
- datashard-0.1.1/src/datashard.egg-info/requires.txt +19 -0
- datashard-0.1.1/src/datashard.egg-info/top_level.txt +1 -0
- datashard-0.1.1/tests/clear_demo.py +268 -0
- datashard-0.1.1/tests/full_demo.py +272 -0
- datashard-0.1.1/tests/test_basic.py +33 -0
- datashard-0.1.1/tests/test_data_operations.py +190 -0
- datashard-0.1.1/tests/test_file_management.py +229 -0
- datashard-0.1.1/tests/test_iceberg.py +272 -0
- datashard-0.1.1/tests/test_main.py +64 -0
- datashard-0.1.1/tests/test_occ.py +138 -0
datashard-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2025] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
datashard-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datashard
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Safe concurrent data operations for ML/AI workloads, Python implementation of Apache Iceberg concepts
|
|
5
|
+
Author-email: Farshid Ashouri <farsheed.ashouri@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/rodmena-limited/datashard
|
|
8
|
+
Project-URL: Repository, https://github.com/rodmena-limited/datashard
|
|
9
|
+
Project-URL: Documentation, https://datashard.readthedocs.io/
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Database
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Requires-Python: >=3.7
|
|
28
|
+
Description-Content-Type: text/plain
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pyarrow>=10.0.0
|
|
31
|
+
Requires-Dist: typing-extensions>=3.10.0; python_version < "3.10"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-xdist>=3.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
|
37
|
+
Requires-Dist: ruff>=0.0.247; extra == "dev"
|
|
38
|
+
Requires-Dist: isort>=5.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
40
|
+
Requires-Dist: types-setuptools>=65.0; extra == "dev"
|
|
41
|
+
Provides-Extra: docs
|
|
42
|
+
Requires-Dist: sphinx>=4.0; extra == "docs"
|
|
43
|
+
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "docs"
|
|
44
|
+
Requires-Dist: sphinx-autodoc-typehints>=1.0; extra == "docs"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
//
|
|
48
|
+
//
|
|
49
|
+
//
|
|
50
|
+
//
|
|
51
|
+
//
|
|
52
|
+
//
|
|
53
|
+
//
|
|
54
|
+
//
|
|
55
|
+
//
|
|
56
|
+
//
|
|
57
|
+
//
|
|
58
|
+
//
|
|
59
|
+
//___________________
|
|
60
|
+
// /
|
|
61
|
+
//___________________/
|
|
62
|
+
|
|
63
|
+
D A T A S H A R D
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
datashard
|
|
69
|
+
========
|
|
70
|
+
Iceberg-inspired safe concurrent data operations for ML/AI workloads in Python.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
What is datashard?
|
|
74
|
+
==================
|
|
75
|
+
|
|
76
|
+
datashard is a Python package that provides safe concurrent data operations for machine learning and AI workloads. It implements the core concepts of Apache Iceberg to give you:
|
|
77
|
+
|
|
78
|
+
Copyright (c) RODMENA LIMITED. Licensed under Apache 2.0.
|
|
79
|
+
|
|
80
|
+
- ACID transactions: Operations either fully complete or fully fail
|
|
81
|
+
- Time travel: Ability to look at your data as it existed at any point in time
|
|
82
|
+
- Safe concurrent access: Multiple processes can read and write safely without corrupting data
|
|
83
|
+
- Data integrity: No matter how many processes access your data simultaneously, it stays intact
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
Demo: 12 Processes Lost 111,434 Operations Due to Data Corruption
|
|
87
|
+
===================================================================
|
|
88
|
+
|
|
89
|
+
In our test, 12 processes each tried to increment a counter 10,000 times:
|
|
90
|
+
- Expected result: 120,000 (12 × 10,000)
|
|
91
|
+
- Normal files result: Only 8,566 operations completed (111,434 LOST!)
|
|
92
|
+
- datashard result: 120,000 (all operations completed safely)
|
|
93
|
+
|
|
94
|
+
This is the difference between using regular files and using datashard.
|
|
95
|
+
|
|
96
|
+
Why Do You Need This for ML/AI?
|
|
97
|
+
===============================
|
|
98
|
+
|
|
99
|
+
Machine learning and AI projects often involve multiple processes:
|
|
100
|
+
- Different models training on the same data
|
|
101
|
+
- Data pipelines running concurrently
|
|
102
|
+
- Multiple experiments accessing shared datasets
|
|
103
|
+
- Real-time inference and batch processing happening together
|
|
104
|
+
|
|
105
|
+
Without proper data management, these operations can corrupt your data. datashard ensures that even when 10 or 100 processes access your data simultaneously, everything works safely.
|
|
106
|
+
|
|
107
|
+
Real-World Analogy
|
|
108
|
+
==================
|
|
109
|
+
|
|
110
|
+
Think of regular file access like a shared notebook where 10 people write simultaneously. You get smudged, overlapping text.
|
|
111
|
+
|
|
112
|
+
datashard is like a smart filing system with multiple copies of the notebook. When someone updates it, everyone sees a consistent version at the time they looked, and no one's work gets overwritten.
|
|
113
|
+
|
|
114
|
+
How It Compares to Apache Iceberg
|
|
115
|
+
=================================
|
|
116
|
+
|
|
117
|
+
Apache Iceberg is a Java-based system built for big data platforms like Spark, Flink, and Hive. It's complex and requires significant infrastructure.
|
|
118
|
+
|
|
119
|
+
datashard is a pure Python implementation designed for:
|
|
120
|
+
- Individual data scientists and ML engineers
|
|
121
|
+
- Smaller datasets and personal projects
|
|
122
|
+
- Direct Python integration without Java dependencies
|
|
123
|
+
- Quick setup without complex infrastructure
|
|
124
|
+
|
|
125
|
+
Apache Iceberg offers more features and better performance for huge datasets, but datashard provides the same safety guarantees in a simple Python package.
|
|
126
|
+
|
|
127
|
+
Installation
|
|
128
|
+
============
|
|
129
|
+
|
|
130
|
+
pip install datashard
|
|
131
|
+
|
|
132
|
+
Quick Start
|
|
133
|
+
===========
|
|
134
|
+
|
|
135
|
+
from datashard import create_table
|
|
136
|
+
|
|
137
|
+
# Create a table to store your data safely
|
|
138
|
+
table = create_table("/path/to/your/data")
|
|
139
|
+
|
|
140
|
+
# Multiple processes can safely add data
|
|
141
|
+
table.append_records([
|
|
142
|
+
{"id": 1, "name": "data_point", "value": 42}
|
|
143
|
+
])
|
|
144
|
+
|
|
145
|
+
# Access data from any point in time
|
|
146
|
+
historical_snapshot = table.time_travel(snapshot_id=12345)
|
|
147
|
+
|
|
148
|
+
Safety Guarantee
|
|
149
|
+
================
|
|
150
|
+
|
|
151
|
+
No matter how many Python processes access your data simultaneously, datashard ensures:
|
|
152
|
+
- No data loss or corruption
|
|
153
|
+
- All operations complete successfully
|
|
154
|
+
- Consistent views for readers
|
|
155
|
+
- Atomic commits (never partial updates)
|
|
156
|
+
- Recovery from failures without data damage
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
Why I Built datashard
|
|
160
|
+
=======================
|
|
161
|
+
Datashard was born as part of my effort to build a strictly Atomic workflow system.
|
|
162
|
+
I needed to record huge amounts of metadata from multiple concurrent processes without risking data corruption.
|
|
163
|
+
In the meantime, I do not have good memories of almost all java-based solutions I tried. Iceberg conceptually fit my needs perfectly,
|
|
164
|
+
but I wanted a pure Python solution. There were complexities in the implementation that I couldn't purely do it myslef, by we're in 2025 now and
|
|
165
|
+
Gemiini has made it possible for me to build complex OCC parts in pure Python.
|
|
166
|
+
This makes it safe for production ML/AI systems where data corruption could be expensive or dangerous.
|
|
167
|
+
|
|
168
|
+
Enjoy using datashard!
|
|
169
|
+
Farshid.
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//
|
|
2
|
+
//
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
//
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
//
|
|
9
|
+
//
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
//
|
|
13
|
+
//___________________
|
|
14
|
+
// /
|
|
15
|
+
//___________________/
|
|
16
|
+
|
|
17
|
+
D A T A S H A R D
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
datashard
|
|
23
|
+
========
|
|
24
|
+
Iceberg-inspired safe concurrent data operations for ML/AI workloads in Python.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
What is datashard?
|
|
28
|
+
==================
|
|
29
|
+
|
|
30
|
+
datashard is a Python package that provides safe concurrent data operations for machine learning and AI workloads. It implements the core concepts of Apache Iceberg to give you:
|
|
31
|
+
|
|
32
|
+
Copyright (c) RODMENA LIMITED. Licensed under Apache 2.0.
|
|
33
|
+
|
|
34
|
+
- ACID transactions: Operations either fully complete or fully fail
|
|
35
|
+
- Time travel: Ability to look at your data as it existed at any point in time
|
|
36
|
+
- Safe concurrent access: Multiple processes can read and write safely without corrupting data
|
|
37
|
+
- Data integrity: No matter how many processes access your data simultaneously, it stays intact
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Demo: 12 Processes Lost 111,434 Operations Due to Data Corruption
|
|
41
|
+
===================================================================
|
|
42
|
+
|
|
43
|
+
In our test, 12 processes each tried to increment a counter 10,000 times:
|
|
44
|
+
- Expected result: 120,000 (12 × 10,000)
|
|
45
|
+
- Normal files result: Only 8,566 operations completed (111,434 LOST!)
|
|
46
|
+
- datashard result: 120,000 (all operations completed safely)
|
|
47
|
+
|
|
48
|
+
This is the difference between using regular files and using datashard.
|
|
49
|
+
|
|
50
|
+
Why Do You Need This for ML/AI?
|
|
51
|
+
===============================
|
|
52
|
+
|
|
53
|
+
Machine learning and AI projects often involve multiple processes:
|
|
54
|
+
- Different models training on the same data
|
|
55
|
+
- Data pipelines running concurrently
|
|
56
|
+
- Multiple experiments accessing shared datasets
|
|
57
|
+
- Real-time inference and batch processing happening together
|
|
58
|
+
|
|
59
|
+
Without proper data management, these operations can corrupt your data. datashard ensures that even when 10 or 100 processes access your data simultaneously, everything works safely.
|
|
60
|
+
|
|
61
|
+
Real-World Analogy
|
|
62
|
+
==================
|
|
63
|
+
|
|
64
|
+
Think of regular file access like a shared notebook where 10 people write simultaneously. You get smudged, overlapping text.
|
|
65
|
+
|
|
66
|
+
datashard is like a smart filing system with multiple copies of the notebook. When someone updates it, everyone sees a consistent version at the time they looked, and no one's work gets overwritten.
|
|
67
|
+
|
|
68
|
+
How It Compares to Apache Iceberg
|
|
69
|
+
=================================
|
|
70
|
+
|
|
71
|
+
Apache Iceberg is a Java-based system built for big data platforms like Spark, Flink, and Hive. It's complex and requires significant infrastructure.
|
|
72
|
+
|
|
73
|
+
datashard is a pure Python implementation designed for:
|
|
74
|
+
- Individual data scientists and ML engineers
|
|
75
|
+
- Smaller datasets and personal projects
|
|
76
|
+
- Direct Python integration without Java dependencies
|
|
77
|
+
- Quick setup without complex infrastructure
|
|
78
|
+
|
|
79
|
+
Apache Iceberg offers more features and better performance for huge datasets, but datashard provides the same safety guarantees in a simple Python package.
|
|
80
|
+
|
|
81
|
+
Installation
|
|
82
|
+
============
|
|
83
|
+
|
|
84
|
+
pip install datashard
|
|
85
|
+
|
|
86
|
+
Quick Start
|
|
87
|
+
===========
|
|
88
|
+
|
|
89
|
+
from datashard import create_table
|
|
90
|
+
|
|
91
|
+
# Create a table to store your data safely
|
|
92
|
+
table = create_table("/path/to/your/data")
|
|
93
|
+
|
|
94
|
+
# Multiple processes can safely add data
|
|
95
|
+
table.append_records([
|
|
96
|
+
{"id": 1, "name": "data_point", "value": 42}
|
|
97
|
+
])
|
|
98
|
+
|
|
99
|
+
# Access data from any point in time
|
|
100
|
+
historical_snapshot = table.time_travel(snapshot_id=12345)
|
|
101
|
+
|
|
102
|
+
Safety Guarantee
|
|
103
|
+
================
|
|
104
|
+
|
|
105
|
+
No matter how many Python processes access your data simultaneously, datashard ensures:
|
|
106
|
+
- No data loss or corruption
|
|
107
|
+
- All operations complete successfully
|
|
108
|
+
- Consistent views for readers
|
|
109
|
+
- Atomic commits (never partial updates)
|
|
110
|
+
- Recovery from failures without data damage
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
Why I Built datashard
|
|
114
|
+
=======================
|
|
115
|
+
Datashard was born as part of my effort to build a strictly Atomic workflow system.
|
|
116
|
+
I needed to record huge amounts of metadata from multiple concurrent processes without risking data corruption.
|
|
117
|
+
In the meantime, I do not have good memories of almost all java-based solutions I tried. Iceberg conceptually fit my needs perfectly,
|
|
118
|
+
but I wanted a pure Python solution. There were complexities in the implementation that I couldn't purely do it myslef, by we're in 2025 now and
|
|
119
|
+
Gemiini has made it possible for me to build complex OCC parts in pure Python.
|
|
120
|
+
This makes it safe for production ML/AI systems where data corruption could be expensive or dangerous.
|
|
121
|
+
|
|
122
|
+
Enjoy using datashard!
|
|
123
|
+
Farshid.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
datashard - Safe concurrent data operations for ML/AI workloads
|
|
3
|
+
|
|
4
|
+
A Python implementation of Apache Iceberg providing ACID transactions,
|
|
5
|
+
time travel, and safe concurrent access.
|
|
6
|
+
"""
|
|
7
|
+
__version__ = "0.1.1"
|
|
8
|
+
__author__ = "RODMENA LIMITED"
|
|
9
|
+
|
|
10
|
+
# Import the main classes to make them available at package level
|
|
11
|
+
from .iceberg import create_table, load_table, DataFile
|
|
12
|
+
from .data_structures import FileFormat
|
|
13
|
+
from .transaction import Table
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
'create_table',
|
|
18
|
+
'load_table',
|
|
19
|
+
'DataFile',
|
|
20
|
+
'FileFormat',
|
|
21
|
+
'Table',
|
|
22
|
+
'__version__',
|
|
23
|
+
'__author__'
|
|
24
|
+
]
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Python Iceberg Implementation
|
|
2
|
+
|
|
3
|
+
This is a simplified but powerful Python implementation of Apache Iceberg that provides core functionality including ACID transactions, time travel, metadata management, and proper file system operations.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **ACID Transactions**: Supports atomic, consistent, isolated, and durable transactions
|
|
8
|
+
- **Time Travel**: Ability to query table state at any point in time
|
|
9
|
+
- **Metadata Management**: Comprehensive metadata tracking and persistence
|
|
10
|
+
- **Snapshotting**: Point-in-time snapshots of table state
|
|
11
|
+
- **File Management**: Proper file system operations, validation, and manifest management
|
|
12
|
+
- **Data Operations**: Reading and writing actual data files (Parquet) with schema management
|
|
13
|
+
|
|
14
|
+
## Architecture
|
|
15
|
+
|
|
16
|
+
The implementation consists of several key components:
|
|
17
|
+
|
|
18
|
+
### Core Data Structures
|
|
19
|
+
- `TableMetadata`: Contains table schema, partition spec, sort order, properties, and snapshot information
|
|
20
|
+
- `Snapshot`: Represents a point-in-time view of the table
|
|
21
|
+
- `DataFile`: Represents individual data files in the table
|
|
22
|
+
- `ManifestFile`: Lists data files and their metadata
|
|
23
|
+
- `Schema`: Defines the table schema
|
|
24
|
+
- `PartitionSpec`: Defines how the table is partitioned
|
|
25
|
+
|
|
26
|
+
### Core Components
|
|
27
|
+
- `MetadataManager`: Handles metadata persistence and updates
|
|
28
|
+
- `SnapshotManager`: Manages snapshots and time travel functionality
|
|
29
|
+
- `Transaction`: Provides ACID transaction support
|
|
30
|
+
- `Table`: Main table interface that ties everything together
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Creating a Table
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from rewrite.iceberg import create_table, DataFile, FileFormat
|
|
38
|
+
|
|
39
|
+
# Create a new table
|
|
40
|
+
table = create_table("/path/to/your/table")
|
|
41
|
+
|
|
42
|
+
# Add data files to the table using a transaction
|
|
43
|
+
from rewrite.data_structures import DataFile, FileFormat
|
|
44
|
+
|
|
45
|
+
data_files = [
|
|
46
|
+
DataFile(
|
|
47
|
+
file_path="/data/file1.parquet",
|
|
48
|
+
file_format=FileFormat.PARQUET,
|
|
49
|
+
partition_values={"year": 2023, "month": 1},
|
|
50
|
+
record_count=1000,
|
|
51
|
+
file_size_in_bytes=102400
|
|
52
|
+
)
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
# Use a transaction to add files
|
|
56
|
+
with table.new_transaction() as tx:
|
|
57
|
+
tx.append_files(data_files)
|
|
58
|
+
tx.commit()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Time Travel
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
# Get the current snapshot
|
|
65
|
+
current = table.current_snapshot()
|
|
66
|
+
|
|
67
|
+
# Get a snapshot by ID
|
|
68
|
+
snapshot = table.snapshot_by_id(123456789)
|
|
69
|
+
|
|
70
|
+
# Get all snapshots
|
|
71
|
+
snapshots = table.snapshots()
|
|
72
|
+
|
|
73
|
+
# Time travel to a specific snapshot
|
|
74
|
+
traveled_snapshot = table.time_travel(snapshot_id=123456789)
|
|
75
|
+
|
|
76
|
+
# Time travel to a snapshot as of a specific time
|
|
77
|
+
from datetime import datetime
|
|
78
|
+
timestamp_ms = int(datetime.now().timestamp() * 1000)
|
|
79
|
+
traveled_snapshot = table.time_travel(timestamp=timestamp_ms)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Transactions
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
# Create a transaction
|
|
86
|
+
with table.new_transaction() as tx:
|
|
87
|
+
# Add files
|
|
88
|
+
tx.append_files([data_file1, data_file2])
|
|
89
|
+
|
|
90
|
+
# Perform other operations
|
|
91
|
+
tx.expire_snapshots(older_than_ms=1609459200000) # Jan 1, 2021
|
|
92
|
+
|
|
93
|
+
# Transaction commits automatically when exiting the 'with' block
|
|
94
|
+
# or explicitly call tx.commit()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Data Operations
|
|
98
|
+
|
|
99
|
+
The implementation includes full data file operations:
|
|
100
|
+
|
|
101
|
+
- **Parquet Support**: Reading and writing Parquet files using PyArrow
|
|
102
|
+
- **Schema Conversion**: Automatic conversion between Iceberg and PyArrow schemas
|
|
103
|
+
- **Data Validation**: Verification of data compatibility with schema
|
|
104
|
+
- **File Readers/Writers**: Efficient reading and writing of data files
|
|
105
|
+
- **Transaction Integration**: Data operations integrated with ACID transactions
|
|
106
|
+
|
|
107
|
+
## Storage Format
|
|
108
|
+
|
|
109
|
+
The implementation stores metadata in JSON format following Iceberg's metadata evolution principles:
|
|
110
|
+
|
|
111
|
+
- `metadata/`: Contains versioned metadata files (v0.json, v1.json, etc.)
|
|
112
|
+
- `metadata.version-hint.text`: Points to the current metadata version
|
|
113
|
+
- `snapshots/`: Contains snapshot-specific information
|
|
114
|
+
- `manifests/`: Contains manifest list files for each snapshot
|
|
115
|
+
|
|
116
|
+
## ACID Properties
|
|
117
|
+
|
|
118
|
+
1. **Atomicity**: All transactions are atomic - they either complete entirely or are rolled back completely
|
|
119
|
+
2. **Consistency**: Metadata is validated on each update to maintain consistency
|
|
120
|
+
3. **Isolation**: Achieved through Optimistic Concurrency Control with base state comparison and retry logic
|
|
121
|
+
4. **Durability**: All metadata changes are immediately persisted to disk
|
|
122
|
+
|
|
123
|
+
## Limitations
|
|
124
|
+
|
|
125
|
+
This is a simplified implementation focusing on the core Iceberg concepts. Some advanced features of Apache Iceberg are not implemented:
|
|
126
|
+
|
|
127
|
+
- Advanced partition transforms beyond basic ones
|
|
128
|
+
- Row-level deletes beyond file-level deletes
|
|
129
|
+
- Advanced optimization operations like file compaction
|
|
130
|
+
- Encryption support
|
|
131
|
+
|
|
132
|
+
## Optimistic Concurrency Control (OCC)
|
|
133
|
+
|
|
134
|
+
This implementation properly follows Apache Iceberg's atomic commit pattern:
|
|
135
|
+
|
|
136
|
+
- Uses base metadata comparison to detect concurrent modifications
|
|
137
|
+
- Implements automatic retry logic with backoff for conflicts
|
|
138
|
+
- Provides proper exception handling when operations cannot be resolved
|
|
139
|
+
- Maintains consistency in concurrent environments without distributed locks
|
|
140
|
+
- Follows the same atomic commit patterns as the Apache Iceberg Java implementation
|
|
141
|
+
|
|
142
|
+
## Testing
|
|
143
|
+
|
|
144
|
+
Run the comprehensive test suite:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
cd rewrite
|
|
148
|
+
python test_iceberg.py
|
|
149
|
+
```
|