opteryx-catalog 0.4.8__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.
Potentially problematic release.
This version of opteryx-catalog might be problematic. Click here for more details.
- opteryx_catalog/__init__.py +31 -0
- opteryx_catalog/catalog/__init__.py +4 -0
- opteryx_catalog/catalog/compaction.py +529 -0
- opteryx_catalog/catalog/dataset.py +1199 -0
- opteryx_catalog/catalog/manifest.py +289 -0
- opteryx_catalog/catalog/metadata.py +81 -0
- opteryx_catalog/catalog/metastore.py +68 -0
- opteryx_catalog/catalog/view.py +12 -0
- opteryx_catalog/exceptions.py +38 -0
- opteryx_catalog/iops/__init__.py +6 -0
- opteryx_catalog/iops/base.py +42 -0
- opteryx_catalog/iops/fileio.py +125 -0
- opteryx_catalog/iops/gcs.py +255 -0
- opteryx_catalog/opteryx_catalog.py +857 -0
- opteryx_catalog-0.4.8.dist-info/METADATA +464 -0
- opteryx_catalog-0.4.8.dist-info/RECORD +25 -0
- opteryx_catalog-0.4.8.dist-info/WHEEL +5 -0
- opteryx_catalog-0.4.8.dist-info/licenses/LICENSE +201 -0
- opteryx_catalog-0.4.8.dist-info/top_level.txt +3 -0
- scripts/create_dataset.py +201 -0
- scripts/read_dataset.py +268 -0
- tests/test_compaction.py +233 -0
- tests/test_dataset_metadata.py +29 -0
- tests/test_import.py +5 -0
- tests/test_pyproject.py +8 -0
|
@@ -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 Justin Joyce (@joocer)
|
|
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.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Create test tables using the `FirestoreCatalog` and write Parquet-only
|
|
2
|
+
manifests/files (no Avro). This script creates a small deterministic set of
|
|
3
|
+
tables under `tests_temp`, writes a single Parquet data file per table, writes
|
|
4
|
+
a Parquet manifest for each snapshot, and records a minimal snapshot document
|
|
5
|
+
in Firestore so planners can discover the Parquet manifest.
|
|
6
|
+
|
|
7
|
+
Run locally with valid GCP credentials set in `GOOGLE_APPLICATION_CREDENTIALS`.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
import time
|
|
13
|
+
import traceback
|
|
14
|
+
|
|
15
|
+
import pyarrow as pa
|
|
16
|
+
|
|
17
|
+
from opteryx_catalog import OpteryxCatalog
|
|
18
|
+
|
|
19
|
+
sys.path.insert(0, os.path.join(sys.path[0], "..")) # Add parent dir for pyiceberg_firestore_gcs
|
|
20
|
+
sys.path.insert(1, os.path.join(sys.path[0], "../opteryx-core"))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def create_parquet_only_tables(count: int = 2) -> list:
|
|
24
|
+
workspace = os.environ.get("OPTERYX_WORKSPACE", "opteryx")
|
|
25
|
+
catalog = OpteryxCatalog(
|
|
26
|
+
workspace=workspace,
|
|
27
|
+
firestore_project=os.environ.get("GCP_PROJECT_ID"),
|
|
28
|
+
firestore_database=os.environ.get("FIRESTORE_DATABASE"),
|
|
29
|
+
gcs_bucket=os.environ.get("GCS_BUCKET"),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
collection = "tests_temp"
|
|
33
|
+
created = []
|
|
34
|
+
|
|
35
|
+
for i in range(count):
|
|
36
|
+
table_name = f"test_table_{i}_{int(time.time())}"
|
|
37
|
+
# location = f"gs://{os.environ.get('GCS_BUCKET')}/{workspace}/{collection}/{table_name}"
|
|
38
|
+
|
|
39
|
+
# Use fixed test author
|
|
40
|
+
author = "me"
|
|
41
|
+
|
|
42
|
+
# Create dataset metadata (create_collection is handled inside create_dataset)
|
|
43
|
+
try:
|
|
44
|
+
tbl = catalog.create_dataset(
|
|
45
|
+
f"{collection}.{table_name}",
|
|
46
|
+
pa.schema([pa.field("id", pa.int64()), pa.field("name", pa.string())]),
|
|
47
|
+
author=author,
|
|
48
|
+
)
|
|
49
|
+
print("Created dataset metadata:", f"{collection}.{table_name}")
|
|
50
|
+
except Exception:
|
|
51
|
+
tbl = catalog.load_dataset(f"{collection}.{table_name}")
|
|
52
|
+
print("Loaded existing dataset metadata:", f"{collection}.{table_name}")
|
|
53
|
+
|
|
54
|
+
# Add an example sort order to the table metadata and persist it so
|
|
55
|
+
# we can inspect `sort-orders` in Firestore.
|
|
56
|
+
try:
|
|
57
|
+
tbl.metadata.sort_orders = [
|
|
58
|
+
{"order-id": 1, "fields": [{"name": "id", "direction": "asc"}]}
|
|
59
|
+
]
|
|
60
|
+
if hasattr(catalog, "save_dataset_metadata"):
|
|
61
|
+
catalog.save_dataset_metadata(f"{collection}.{table_name}", tbl.metadata)
|
|
62
|
+
except Exception:
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
# Create a deterministic planets dataset so read_table tests can validate
|
|
66
|
+
planets = [
|
|
67
|
+
(1, "Mercury"),
|
|
68
|
+
(2, "Venus"),
|
|
69
|
+
(3, "Earth"),
|
|
70
|
+
(4, "Mars"),
|
|
71
|
+
(5, "Jupiter"),
|
|
72
|
+
(6, "Saturn"),
|
|
73
|
+
(7, "Uranus"),
|
|
74
|
+
(8, "Neptune"),
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
data = pa.table({"id": [p[0] for p in planets], "name": [p[1] for p in planets]})
|
|
78
|
+
|
|
79
|
+
# Append data using the new SimpleDataset.append() which writes the data
|
|
80
|
+
# file, creates a Parquet manifest and persists snapshot metadata.
|
|
81
|
+
try:
|
|
82
|
+
tbl.append(data, author=author)
|
|
83
|
+
print("Appended data via Dataset.append() for", f"{collection}.{table_name}")
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print("Dataset.append() failed:", e)
|
|
86
|
+
raise
|
|
87
|
+
|
|
88
|
+
# Also append a second dataset (an edit) so we have multiple snapshots/files
|
|
89
|
+
try:
|
|
90
|
+
# small additional rows to simulate an update
|
|
91
|
+
extra = [(9, "Pluto"), (10, "Eris")]
|
|
92
|
+
data2 = pa.table({"id": [p[0] for p in extra], "name": [p[1] for p in extra]})
|
|
93
|
+
tbl.append(data2, author=author, commit_message="append extra planets")
|
|
94
|
+
print("Appended second dataset via Dataset.append() for", f"{collection}.{table_name}")
|
|
95
|
+
except Exception as e:
|
|
96
|
+
print("Second Dataset.append() failed:", e)
|
|
97
|
+
raise
|
|
98
|
+
|
|
99
|
+
# Inspect snapshot and Firestore snapshot doc for parquet-manifest
|
|
100
|
+
parquet_manifest_path = None
|
|
101
|
+
try:
|
|
102
|
+
snapshot = tbl.snapshot()
|
|
103
|
+
snapshot_id = snapshot.snapshot_id if snapshot else None
|
|
104
|
+
print("Current snapshot id:", snapshot_id)
|
|
105
|
+
if snapshot_id is not None:
|
|
106
|
+
from google.cloud import firestore
|
|
107
|
+
|
|
108
|
+
db = firestore.Client(
|
|
109
|
+
project=os.environ.get("GCP_PROJECT_ID"),
|
|
110
|
+
database=os.environ.get("FIRESTORE_DATABASE"),
|
|
111
|
+
)
|
|
112
|
+
snap_doc = (
|
|
113
|
+
db.collection(workspace)
|
|
114
|
+
.document(collection)
|
|
115
|
+
.collection("datasets")
|
|
116
|
+
.document(table_name)
|
|
117
|
+
.collection("snapshots")
|
|
118
|
+
.document(str(snapshot_id))
|
|
119
|
+
.get()
|
|
120
|
+
)
|
|
121
|
+
if snap_doc.exists:
|
|
122
|
+
d = snap_doc.to_dict() or {}
|
|
123
|
+
parquet_manifest_path = d.get("manifest")
|
|
124
|
+
print("Snapshot doc keys:", list(d.keys()))
|
|
125
|
+
print("manifest:", parquet_manifest_path)
|
|
126
|
+
else:
|
|
127
|
+
print("Snapshot document not found in Firestore for", snapshot_id)
|
|
128
|
+
except Exception as e:
|
|
129
|
+
print("Failed to read snapshot/Firestore doc:", e)
|
|
130
|
+
|
|
131
|
+
created.append(
|
|
132
|
+
{
|
|
133
|
+
"collection": collection,
|
|
134
|
+
"dataset": table_name,
|
|
135
|
+
"location": tbl.metadata.location,
|
|
136
|
+
"manifest": parquet_manifest_path,
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Create a simple view document in Firestore under `views` subcollection
|
|
141
|
+
try:
|
|
142
|
+
from google.cloud import firestore
|
|
143
|
+
|
|
144
|
+
db = firestore.Client(
|
|
145
|
+
project=os.environ.get("GCP_PROJECT_ID"),
|
|
146
|
+
database=os.environ.get("FIRESTORE_DATABASE"),
|
|
147
|
+
)
|
|
148
|
+
view_name = f"view_{table_name}"
|
|
149
|
+
view_doc_ref = (
|
|
150
|
+
db.collection(workspace)
|
|
151
|
+
.document(collection)
|
|
152
|
+
.collection("views")
|
|
153
|
+
.document(view_name)
|
|
154
|
+
)
|
|
155
|
+
now_ms = int(time.time() * 1000)
|
|
156
|
+
author = "me"
|
|
157
|
+
# Include optional last-execution metrics (populated later by the view runner)
|
|
158
|
+
# Store the SQL text in a `statement` subcollection so we can version/track changes
|
|
159
|
+
statement_id = str(now_ms)
|
|
160
|
+
statement_coll = view_doc_ref.collection("statement")
|
|
161
|
+
statement_coll.document(statement_id).set(
|
|
162
|
+
{
|
|
163
|
+
"sql": f"SELECT * FROM {workspace}.{collection}.{table_name}",
|
|
164
|
+
"timestamp-ms": now_ms,
|
|
165
|
+
"author": author,
|
|
166
|
+
"sequence-number": 1,
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Root view doc references the statement doc via `statement-id` (no inline query)
|
|
171
|
+
view_doc_ref.set(
|
|
172
|
+
{
|
|
173
|
+
"name": view_name,
|
|
174
|
+
"collection": collection,
|
|
175
|
+
"workspace": workspace,
|
|
176
|
+
"timestamp-ms": now_ms,
|
|
177
|
+
"author": author,
|
|
178
|
+
"description": f"View over {table_name}",
|
|
179
|
+
"describer": author,
|
|
180
|
+
"last-execution-ms": None,
|
|
181
|
+
"last-execution-data-size": None,
|
|
182
|
+
"last-execution-records": None,
|
|
183
|
+
"statement-id": statement_id,
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
print("Created view doc:", f"{collection}.{view_name}")
|
|
187
|
+
except Exception as e:
|
|
188
|
+
print("Failed to create view doc:", e)
|
|
189
|
+
|
|
190
|
+
return created
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
if __name__ == "__main__":
|
|
194
|
+
try:
|
|
195
|
+
created = create_parquet_only_tables(2)
|
|
196
|
+
print("\nCreated datasets summary:")
|
|
197
|
+
for c in created:
|
|
198
|
+
print(c)
|
|
199
|
+
except Exception:
|
|
200
|
+
traceback.print_exc()
|
|
201
|
+
raise
|
scripts/read_dataset.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import pyarrow as pa
|
|
7
|
+
import pyarrow.parquet as pq
|
|
8
|
+
|
|
9
|
+
from opteryx_catalog.opteryx_catalog import OpteryxCatalog
|
|
10
|
+
|
|
11
|
+
# Add local paths to sys.path to use local code instead of installed packages
|
|
12
|
+
sys.path.insert(0, os.path.join(sys.path[0], "..")) # Add parent dir for pyiceberg_firestore_gcs
|
|
13
|
+
sys.path.insert(1, os.path.join(sys.path[0], "../opteryx-core"))
|
|
14
|
+
sys.path.insert(1, os.path.join(sys.path[0], "../pyiceberg-firestore-gcs"))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = (
|
|
18
|
+
"/Users/justin/Nextcloud/mabel/mabeldev-b37f651c2916.json"
|
|
19
|
+
)
|
|
20
|
+
os.environ["GCP_PROJECT_ID"] = "mabeldev"
|
|
21
|
+
os.environ["FIRESTORE_DATABASE"] = "catalogs"
|
|
22
|
+
os.environ["GCS_BUCKET"] = "opteryx_data"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# from opteryx.connectors.iceberg_connector import IcebergConnector
|
|
26
|
+
# Using opteryx_catalog for manifest discovery + simple in-Python filters
|
|
27
|
+
|
|
28
|
+
workspace = "opteryx"
|
|
29
|
+
collection_name = "tests_temp"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Step 1: Create a local catalog
|
|
33
|
+
catalog = OpteryxCatalog(
|
|
34
|
+
workspace,
|
|
35
|
+
firestore_project="mabeldev",
|
|
36
|
+
firestore_database="catalogs",
|
|
37
|
+
gcs_bucket="opteryx_data",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Choose the latest dataset in the collection to test against
|
|
41
|
+
datasets = list(catalog.list_datasets(collection_name))
|
|
42
|
+
if not datasets:
|
|
43
|
+
raise RuntimeError(f"No datasets found in collection {collection_name}")
|
|
44
|
+
datasets = sorted(datasets)
|
|
45
|
+
table = datasets[-1]
|
|
46
|
+
|
|
47
|
+
table = "test_table_0_1767300842"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# opteryx.register_store(
|
|
51
|
+
# prefix="_default",
|
|
52
|
+
# connector=IcebergConnector,
|
|
53
|
+
# remove_prefix=True,
|
|
54
|
+
# catalog=FirestoreCatalog,
|
|
55
|
+
# firestore_project="mabeldev",
|
|
56
|
+
# firestore_database="catalogs",
|
|
57
|
+
# gcs_bucket="opteryx_data",
|
|
58
|
+
# )
|
|
59
|
+
|
|
60
|
+
# catalog.create_collection_if_not_exists(schema_name, properties={"iceberg_compatible": "false"})
|
|
61
|
+
|
|
62
|
+
# df = opteryx.query_to_arrow("SELECT * FROM $planets")
|
|
63
|
+
|
|
64
|
+
# Drop table if it exists
|
|
65
|
+
# try:
|
|
66
|
+
# catalog.drop_dataset(f"{schema_name}.{table}")
|
|
67
|
+
# except Exception:
|
|
68
|
+
# pass
|
|
69
|
+
|
|
70
|
+
# s = catalog.create_dataset(f"{schema_name}.{table}", df.schema, properties={"iceberg_compatible": "false"})
|
|
71
|
+
|
|
72
|
+
# Load table metadata using the new catalog
|
|
73
|
+
# Attempt to load the requested table; if it has no manifest, fall back to
|
|
74
|
+
# the most recently created table in the namespace (useful when running the
|
|
75
|
+
# paired `create_dataset.py` script which creates new deterministic datasets).
|
|
76
|
+
s = catalog.load_dataset(f"{collection_name}.{table}")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _read_parquet_manifest(io, manifest_path: str) -> list:
|
|
80
|
+
"""Read a Parquet manifest produced by `FirestoreCatalog.write_parquet_manifest`.
|
|
81
|
+
|
|
82
|
+
Returns a list of entry dicts (the original pyarrow.from_pylist rows).
|
|
83
|
+
"""
|
|
84
|
+
if not manifest_path:
|
|
85
|
+
return []
|
|
86
|
+
inp = io.new_input(manifest_path)
|
|
87
|
+
try:
|
|
88
|
+
buf = inp.open().read()
|
|
89
|
+
except FileNotFoundError:
|
|
90
|
+
return []
|
|
91
|
+
tbl = pq.read_table(pa.BufferReader(buf))
|
|
92
|
+
return tbl.to_pylist()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _read_data_file(io, path: str) -> list:
|
|
96
|
+
inp = io.new_input(path)
|
|
97
|
+
buf = inp.open().read()
|
|
98
|
+
tbl = pq.read_table(pa.BufferReader(buf))
|
|
99
|
+
return tbl.to_pylist()
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# s.append(df)
|
|
103
|
+
|
|
104
|
+
ts = s.snapshots()[-1].timestamp_ms
|
|
105
|
+
print(f"Table last updated: {datetime.datetime.fromtimestamp(ts / 1000)}")
|
|
106
|
+
ts = s.snapshots()[0].timestamp_ms
|
|
107
|
+
print(f"Table last created: {datetime.datetime.fromtimestamp(ts / 1000)}")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
print(f"Table format version: {s.metadata.format_version}")
|
|
111
|
+
print(f"Table location: {s.metadata.location}")
|
|
112
|
+
|
|
113
|
+
# Discover planned files from the Parquet manifest
|
|
114
|
+
print("\n=== Test 1: No filter (baseline) ===")
|
|
115
|
+
entries = []
|
|
116
|
+
# Read manifests from all snapshots so edits (additional snapshots) are included
|
|
117
|
+
for snap in s.metadata.snapshots:
|
|
118
|
+
if snap.manifest_list:
|
|
119
|
+
entries.extend(_read_parquet_manifest(catalog.io, snap.manifest_list))
|
|
120
|
+
if not entries:
|
|
121
|
+
# Try the most recently listed dataset in the namespace
|
|
122
|
+
try:
|
|
123
|
+
datasets = list(catalog.list_datasets(collection_name))
|
|
124
|
+
if datasets:
|
|
125
|
+
last = datasets[-1]
|
|
126
|
+
print(f"Falling back to dataset: {last}")
|
|
127
|
+
s = catalog.load_dataset(f"{collection_name}.{last}")
|
|
128
|
+
# read manifests from all snapshots
|
|
129
|
+
entries = []
|
|
130
|
+
for snap in s.metadata.snapshots:
|
|
131
|
+
if snap.manifest_list:
|
|
132
|
+
entries.extend(_read_parquet_manifest(catalog.io, snap.manifest_list))
|
|
133
|
+
except Exception:
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
files = []
|
|
137
|
+
seen = set()
|
|
138
|
+
for e in entries:
|
|
139
|
+
fp = e.get("file_path")
|
|
140
|
+
if fp and fp not in seen:
|
|
141
|
+
seen.add(fp)
|
|
142
|
+
files.append(fp)
|
|
143
|
+
print(f"✓ Planned {len(files)} files (from manifest)")
|
|
144
|
+
assert len(files) > 0, "Should have at least 1 file without filter"
|
|
145
|
+
baseline_file_count = len(files)
|
|
146
|
+
|
|
147
|
+
# Test 2: EqualTo filter on 'name' = 'Earth'
|
|
148
|
+
print("\n=== Test 2: EqualTo filter (name = 'Earth') ===")
|
|
149
|
+
t = time.monotonic_ns()
|
|
150
|
+
files_eq = files
|
|
151
|
+
print(f"✓ Planned {len(files_eq)} files (from manifest)")
|
|
152
|
+
# Read and verify data by scanning files and applying the filter in Python
|
|
153
|
+
rows_eq = []
|
|
154
|
+
for fpath in files_eq:
|
|
155
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
156
|
+
for r in rows:
|
|
157
|
+
if r.get("name") == "Earth":
|
|
158
|
+
rows_eq.append(r)
|
|
159
|
+
print(f" Found {len(rows_eq)} rows")
|
|
160
|
+
assert len(rows_eq) == 1, f"Expected 1 row for Earth, got {len(rows_eq)}"
|
|
161
|
+
assert rows_eq[0]["name"] == "Earth", f"Expected Earth, got {rows_eq[0]['name']}"
|
|
162
|
+
print(" ✓ Verified: Only 'Earth' returned")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# Test 2a: EqualTo filter on 'name' = 'Xenon'
|
|
166
|
+
print("\n=== Test 2a: EqualTo filter (name = 'Xenon') ===")
|
|
167
|
+
t = time.monotonic_ns()
|
|
168
|
+
rows_eq = []
|
|
169
|
+
for fpath in files:
|
|
170
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
171
|
+
for r in rows:
|
|
172
|
+
if r.get("name") == "Xenon":
|
|
173
|
+
rows_eq.append(r)
|
|
174
|
+
print(f" Found {len(rows_eq)} rows")
|
|
175
|
+
assert len(rows_eq) == 0, f"Expected 0 rows for Xenon, got {len(rows_eq)}"
|
|
176
|
+
print(" ✓ Verified: No rows returned")
|
|
177
|
+
|
|
178
|
+
# Test 3: In filter with multiple values
|
|
179
|
+
print("\n=== Test 3: In filter (name IN ['Earth', 'Mars']) ===")
|
|
180
|
+
t = time.monotonic_ns()
|
|
181
|
+
rows_in = []
|
|
182
|
+
for fpath in files:
|
|
183
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
184
|
+
for r in rows:
|
|
185
|
+
if r.get("name") in {"Earth", "Mars"}:
|
|
186
|
+
rows_in.append(r)
|
|
187
|
+
print(f" Found {len(rows_in)} rows")
|
|
188
|
+
assert len(rows_in) == 2, f"Expected 2 rows for Earth and Mars, got {len(rows_in)}"
|
|
189
|
+
names = {row["name"] for row in rows_in}
|
|
190
|
+
assert names == {"Earth", "Mars"}, f"Expected Earth and Mars, got {names}"
|
|
191
|
+
print(" ✓ Verified: Only 'Earth' and 'Mars' returned")
|
|
192
|
+
|
|
193
|
+
# Test 4: In filter that should return no rows
|
|
194
|
+
print("\n=== Test 4: In filter (name IN ['NonExistent1', 'NonExistent2']) ===")
|
|
195
|
+
t = time.monotonic_ns()
|
|
196
|
+
rows_empty = []
|
|
197
|
+
for fpath in files:
|
|
198
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
199
|
+
for r in rows:
|
|
200
|
+
if r.get("name") in {"NonExistent1", "NonExistent2"}:
|
|
201
|
+
rows_empty.append(r)
|
|
202
|
+
print(f" Found {len(rows_empty)} rows")
|
|
203
|
+
assert len(rows_empty) == 0, f"Expected 0 rows for non-existent names, got {len(rows_empty)}"
|
|
204
|
+
print(" ✓ Verified: No rows returned (filter works at row level)")
|
|
205
|
+
if baseline_file_count == len(files):
|
|
206
|
+
print(f" ⚠ Note: File pruning not working - still scanned {len(files)} files (expected 0)")
|
|
207
|
+
|
|
208
|
+
# Test 5: EqualTo on a different value
|
|
209
|
+
print("\n=== Test 5: EqualTo filter (name = 'Jupiter') ===")
|
|
210
|
+
t = time.monotonic_ns()
|
|
211
|
+
rows_jupiter = []
|
|
212
|
+
for fpath in files:
|
|
213
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
214
|
+
for r in rows:
|
|
215
|
+
if r.get("name") == "Jupiter":
|
|
216
|
+
rows_jupiter.append(r)
|
|
217
|
+
print(f" Found {len(rows_jupiter)} rows")
|
|
218
|
+
assert len(rows_jupiter) == 1, f"Expected 1 row for Jupiter, got {len(rows_jupiter)}"
|
|
219
|
+
assert rows_jupiter[0]["name"] == "Jupiter", f"Expected Jupiter, got {rows_jupiter[0]['name']}"
|
|
220
|
+
print(" ✓ Verified: Only 'Jupiter' returned")
|
|
221
|
+
|
|
222
|
+
# Test 6: In filter with single value (should behave like EqualTo)
|
|
223
|
+
print("\n=== Test 6: In filter (name IN ['Venus']) ===")
|
|
224
|
+
t = time.monotonic_ns()
|
|
225
|
+
rows_single = []
|
|
226
|
+
for fpath in files:
|
|
227
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
228
|
+
for r in rows:
|
|
229
|
+
if r.get("name") == "Venus":
|
|
230
|
+
rows_single.append(r)
|
|
231
|
+
print(f" Found {len(rows_single)} rows")
|
|
232
|
+
assert len(rows_single) == 1, f"Expected 1 row for Venus, got {len(rows_single)}"
|
|
233
|
+
assert rows_single[0]["name"] == "Venus", f"Expected Venus, got {rows_single[0]['name']}"
|
|
234
|
+
print(" ✓ Verified: Only 'Venus' returned")
|
|
235
|
+
|
|
236
|
+
# Test 7: In filter with all planets
|
|
237
|
+
print("\n=== Test 7: In filter with all planet names ===")
|
|
238
|
+
all_planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
|
239
|
+
t = time.monotonic_ns()
|
|
240
|
+
rows_all = []
|
|
241
|
+
for fpath in files:
|
|
242
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
243
|
+
rows_all.extend(rows)
|
|
244
|
+
print(f" Found {len(rows_all)} rows")
|
|
245
|
+
assert len(rows_all) == 10, f"Expected 10 rows for all planets, got {len(rows_all)}"
|
|
246
|
+
print(" ✓ Verified: All rows returned (including appended rows)")
|
|
247
|
+
|
|
248
|
+
# Test 8: Empty In filter
|
|
249
|
+
print("\n=== Test 8: In filter with empty list (name IN []) ===")
|
|
250
|
+
t = time.monotonic_ns()
|
|
251
|
+
rows_empty_list = []
|
|
252
|
+
for fpath in files:
|
|
253
|
+
rows = _read_data_file(catalog.io, fpath)
|
|
254
|
+
for r in rows:
|
|
255
|
+
if r.get("name") in []:
|
|
256
|
+
rows_empty_list.append(r)
|
|
257
|
+
print(f" Found {len(rows_empty_list)} rows")
|
|
258
|
+
assert len(rows_empty_list) == 0, f"Expected 0 rows for empty IN list, got {len(rows_empty_list)}"
|
|
259
|
+
print(" ✓ Verified: No rows returned for empty IN list")
|
|
260
|
+
|
|
261
|
+
print("\n" + "=" * 60)
|
|
262
|
+
print("SUMMARY OF FILTER PUSHDOWN TESTS")
|
|
263
|
+
print("=" * 60)
|
|
264
|
+
print("✅ All filter checks passed (performed in-Python against data files)")
|
|
265
|
+
print("✅ Filters work correctly at row level")
|
|
266
|
+
print(f"File counts: baseline={baseline_file_count}, planned_files={len(files)}")
|
|
267
|
+
print("⚠️ File-level pruning not implemented in this test (manifest-driven planning)")
|
|
268
|
+
print("=" * 60)
|