daft-lance 0.1.0__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.
- daft_lance-0.1.0/.github/workflows/pr-test-suite.yml +19 -0
- daft_lance-0.1.0/.github/workflows/publish-package.yml +18 -0
- daft_lance-0.1.0/.gitignore +10 -0
- daft_lance-0.1.0/LICENSE +199 -0
- daft_lance-0.1.0/PKG-INFO +12 -0
- daft_lance-0.1.0/README.md +63 -0
- daft_lance-0.1.0/daft_lance/__init__.py +278 -0
- daft_lance-0.1.0/daft_lance/compaction.py +68 -0
- daft_lance-0.1.0/daft_lance/merge.py +323 -0
- daft_lance-0.1.0/daft_lance/rest_config.py +55 -0
- daft_lance-0.1.0/daft_lance/rest_write.py +204 -0
- daft_lance-0.1.0/daft_lance/scalar_index.py +224 -0
- daft_lance-0.1.0/daft_lance/utils.py +189 -0
- daft_lance-0.1.0/lance_rest_example.py +107 -0
- daft_lance-0.1.0/pyproject.toml +23 -0
- daft_lance-0.1.0/tests/__init__.py +0 -0
- daft_lance-0.1.0/tests/io/__init__.py +0 -0
- daft_lance-0.1.0/tests/io/lance/__init__.py +0 -0
- daft_lance-0.1.0/tests/io/lance/test_lance_rest_comprehensive.py +907 -0
- daft_lance-0.1.0/tests/io/lancedb/__init__.py +0 -0
- daft_lance-0.1.0/tests/io/lancedb/conftest.py +6 -0
- daft_lance-0.1.0/tests/io/lancedb/test_lance_merge_evolution.py +142 -0
- daft_lance-0.1.0/tests/io/lancedb/test_lancedb_compaction.py +142 -0
- daft_lance-0.1.0/tests/io/lancedb/test_lancedb_custom_task.py +50 -0
- daft_lance-0.1.0/tests/io/lancedb/test_lancedb_scalar_index.py +542 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: PR Test Suite
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: astral-sh/setup-uv@v5
|
|
18
|
+
- name: Run tests
|
|
19
|
+
run: uv run --python ${{ matrix.python-version }} pytest tests/ -v
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Publish Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: astral-sh/setup-uv@v5
|
|
15
|
+
- name: Build package
|
|
16
|
+
run: uv build
|
|
17
|
+
- name: Publish to PyPI
|
|
18
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
daft_lance-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
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 the 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 the 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 any 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. Please also get an
|
|
185
|
+
"Whose License Is It Anyway?" lawyer to review your project.
|
|
186
|
+
|
|
187
|
+
Copyright [yyyy] [name of copyright owner]
|
|
188
|
+
|
|
189
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
190
|
+
you may not use this file except in compliance with the License.
|
|
191
|
+
You may obtain a copy of the License at
|
|
192
|
+
|
|
193
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
194
|
+
|
|
195
|
+
Unless required by applicable law or agreed to in writing, software
|
|
196
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
197
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
198
|
+
See the License for the specific language governing permissions and
|
|
199
|
+
limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: daft-lance
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lance integration for Daft - compaction, indexing, merge columns, and REST operations
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: daft>=0.7.5
|
|
9
|
+
Requires-Dist: pylance<0.40.0
|
|
10
|
+
Provides-Extra: rest
|
|
11
|
+
Requires-Dist: lance-namespace; extra == 'rest'
|
|
12
|
+
Requires-Dist: lance-namespace-urllib3-client; extra == 'rest'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# daft-lance
|
|
2
|
+
|
|
3
|
+
Lance integration for [Daft](https://github.com/Eventual-Inc/Daft). Provides distributed compaction, scalar indexing, column merging, and REST catalog operations for Lance datasets.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install daft-lance
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For REST catalog support:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
pip install daft-lance[rest]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Compaction
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from daft_lance import compact_files
|
|
23
|
+
|
|
24
|
+
compact_files("s3://bucket/my_dataset")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Scalar Indexing
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from daft_lance import create_scalar_index
|
|
31
|
+
|
|
32
|
+
create_scalar_index("s3://bucket/my_dataset", column="name", index_type="INVERTED")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Column Merging
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from daft_lance import merge_columns_df
|
|
39
|
+
|
|
40
|
+
merge_columns_df(df, "s3://bucket/my_dataset")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### REST Catalog
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from daft_lance import LanceRestConfig, write_lance_rest
|
|
47
|
+
|
|
48
|
+
config = LanceRestConfig(base_url="https://api.lancedb.com", api_key="...")
|
|
49
|
+
write_lance_rest(mp, config, namespace="default", table_name="my_table")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
Requires [uv](https://docs.astral.sh/uv/).
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
uv sync
|
|
58
|
+
uv run pytest tests/ -v
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
Apache-2.0
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# ruff: noqa: I002
|
|
2
|
+
# isort: dont-add-import: from __future__ import annotations
|
|
3
|
+
import pathlib
|
|
4
|
+
import warnings
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
6
|
+
|
|
7
|
+
from daft import context
|
|
8
|
+
from daft.daft import IOConfig
|
|
9
|
+
from daft.io.object_store_options import io_config_to_storage_options
|
|
10
|
+
|
|
11
|
+
from daft_lance.merge import merge_columns_from_df, merge_columns_internal
|
|
12
|
+
from daft_lance.rest_config import LanceRestConfig
|
|
13
|
+
from daft_lance.rest_write import create_lance_table_rest, register_lance_table_rest, write_lance_rest
|
|
14
|
+
from daft_lance.utils import construct_lance_dataset
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from collections.abc import Callable
|
|
18
|
+
|
|
19
|
+
from daft.dataframe import DataFrame
|
|
20
|
+
from daft.dependencies import pa
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from lance.dataset import LanceDataset
|
|
24
|
+
from lance.udf import BatchUDF
|
|
25
|
+
except ImportError:
|
|
26
|
+
BatchUDF = None
|
|
27
|
+
LanceDataset = None
|
|
28
|
+
|
|
29
|
+
LanceDataset = Any
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def merge_columns(
|
|
33
|
+
uri: str | pathlib.Path,
|
|
34
|
+
io_config: IOConfig | None = None,
|
|
35
|
+
*,
|
|
36
|
+
transform: Union[dict[str, str], "BatchUDF", Callable[["pa.lib.RecordBatch"], "pa.lib.RecordBatch"]] = None,
|
|
37
|
+
read_columns: list[str] | None = None,
|
|
38
|
+
reader_schema: Optional["pa.Schema"] = None,
|
|
39
|
+
storage_options: dict[str, Any] | None = None,
|
|
40
|
+
daft_remote_args: dict[str, Any] | None = None,
|
|
41
|
+
concurrency: int | None = None,
|
|
42
|
+
version: int | str | None = None,
|
|
43
|
+
asof: str | None = None,
|
|
44
|
+
block_size: int | None = None,
|
|
45
|
+
commit_lock: Any | None = None,
|
|
46
|
+
index_cache_size: int | None = None,
|
|
47
|
+
default_scan_options: dict[str, Any] | None = None,
|
|
48
|
+
metadata_cache_size_bytes: int | None = None,
|
|
49
|
+
) -> LanceDataset:
|
|
50
|
+
"""Merge new columns into a LanceDB table using a transformation function."""
|
|
51
|
+
warnings.warn(
|
|
52
|
+
"merge_columns is deprecated and will be removed in a future release. "
|
|
53
|
+
"Please use merge_columns_df instead.",
|
|
54
|
+
category=DeprecationWarning,
|
|
55
|
+
stacklevel=2,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
if transform is None:
|
|
59
|
+
raise ValueError(
|
|
60
|
+
"merge_columns requires a `transform` function; prefer using merge_columns_df with a prepared DataFrame if no transform is needed."
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
io_config = context.get_context().daft_planning_config.default_io_config if io_config is None else io_config
|
|
64
|
+
storage_options = storage_options or io_config_to_storage_options(io_config, uri)
|
|
65
|
+
|
|
66
|
+
lance_ds = construct_lance_dataset(
|
|
67
|
+
uri,
|
|
68
|
+
storage_options=storage_options,
|
|
69
|
+
version=version,
|
|
70
|
+
asof=asof,
|
|
71
|
+
block_size=block_size,
|
|
72
|
+
commit_lock=commit_lock,
|
|
73
|
+
index_cache_size=index_cache_size,
|
|
74
|
+
default_scan_options=default_scan_options,
|
|
75
|
+
metadata_cache_size_bytes=metadata_cache_size_bytes,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return merge_columns_internal(
|
|
79
|
+
lance_ds,
|
|
80
|
+
uri,
|
|
81
|
+
transform=transform,
|
|
82
|
+
read_columns=read_columns,
|
|
83
|
+
reader_schema=reader_schema,
|
|
84
|
+
storage_options=storage_options,
|
|
85
|
+
daft_remote_args=daft_remote_args,
|
|
86
|
+
concurrency=concurrency,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def merge_columns_df(
|
|
91
|
+
df: "DataFrame",
|
|
92
|
+
uri: str | pathlib.Path,
|
|
93
|
+
io_config: IOConfig | None = None,
|
|
94
|
+
*,
|
|
95
|
+
read_columns: list[str] | None = None,
|
|
96
|
+
reader_schema: Optional["pa.Schema"] = None,
|
|
97
|
+
storage_options: dict[str, Any] | None = None,
|
|
98
|
+
daft_remote_args: dict[str, Any] | None = None,
|
|
99
|
+
concurrency: int | None = None,
|
|
100
|
+
version: int | str | None = None,
|
|
101
|
+
asof: str | None = None,
|
|
102
|
+
block_size: int | None = None,
|
|
103
|
+
commit_lock: Any | None = None,
|
|
104
|
+
index_cache_size: int | None = None,
|
|
105
|
+
default_scan_options: dict[str, Any] | None = None,
|
|
106
|
+
metadata_cache_size_bytes: int | None = None,
|
|
107
|
+
batch_size: int | None = None,
|
|
108
|
+
left_on: str | None = "_rowaddr",
|
|
109
|
+
right_on: str | None = "_rowaddr",
|
|
110
|
+
) -> None:
|
|
111
|
+
"""Row-level merge columns entrypoint using a DataFrame."""
|
|
112
|
+
io_config = context.get_context().daft_planning_config.default_io_config if io_config is None else io_config
|
|
113
|
+
storage_options = storage_options or io_config_to_storage_options(io_config, uri)
|
|
114
|
+
|
|
115
|
+
lance_ds = construct_lance_dataset(
|
|
116
|
+
uri,
|
|
117
|
+
storage_options=storage_options,
|
|
118
|
+
version=version,
|
|
119
|
+
asof=asof,
|
|
120
|
+
block_size=block_size,
|
|
121
|
+
commit_lock=commit_lock,
|
|
122
|
+
index_cache_size=index_cache_size,
|
|
123
|
+
default_scan_options=default_scan_options,
|
|
124
|
+
metadata_cache_size_bytes=metadata_cache_size_bytes,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
effective_right_on = right_on or left_on
|
|
128
|
+
effective_batch_size = (
|
|
129
|
+
batch_size if batch_size is not None else daft_remote_args.get("batch_size", None) if daft_remote_args else None
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
return merge_columns_from_df(
|
|
133
|
+
df,
|
|
134
|
+
lance_ds=lance_ds,
|
|
135
|
+
uri=uri,
|
|
136
|
+
read_columns=read_columns,
|
|
137
|
+
reader_schema=reader_schema,
|
|
138
|
+
storage_options=storage_options,
|
|
139
|
+
daft_remote_args=daft_remote_args,
|
|
140
|
+
concurrency=concurrency,
|
|
141
|
+
left_on=left_on,
|
|
142
|
+
right_on=effective_right_on,
|
|
143
|
+
batch_size=effective_batch_size,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def create_scalar_index(
|
|
148
|
+
uri: str | pathlib.Path,
|
|
149
|
+
io_config: IOConfig | None = None,
|
|
150
|
+
*,
|
|
151
|
+
column: str,
|
|
152
|
+
index_type: str = "INVERTED",
|
|
153
|
+
name: str | None = None,
|
|
154
|
+
replace: bool = True,
|
|
155
|
+
storage_options: dict[str, Any] | None = None,
|
|
156
|
+
version: int | str | None = None,
|
|
157
|
+
asof: str | None = None,
|
|
158
|
+
block_size: int | None = None,
|
|
159
|
+
commit_lock: Any | None = None,
|
|
160
|
+
index_cache_size: int | None = None,
|
|
161
|
+
default_scan_options: dict[str, Any] | None = None,
|
|
162
|
+
metadata_cache_size_bytes: int | None = None,
|
|
163
|
+
fragment_group_size: int | None = None,
|
|
164
|
+
num_partitions: int | None = None,
|
|
165
|
+
max_concurrency: int | None = None,
|
|
166
|
+
**kwargs: Any,
|
|
167
|
+
) -> None:
|
|
168
|
+
"""Build a distributed scalar index using Daft's distributed execution."""
|
|
169
|
+
try:
|
|
170
|
+
import lance
|
|
171
|
+
from packaging import version as packaging_version
|
|
172
|
+
|
|
173
|
+
from daft_lance.scalar_index import create_scalar_index_internal
|
|
174
|
+
|
|
175
|
+
lance_version = packaging_version.parse(lance.__version__)
|
|
176
|
+
min_required_version = packaging_version.parse("0.37.0")
|
|
177
|
+
if lance_version < min_required_version:
|
|
178
|
+
raise RuntimeError(
|
|
179
|
+
f"Distributed indexing requires pylance >= 0.37.0, but found {lance.__version__}. "
|
|
180
|
+
"The distributed indexing interfaces are not available in older versions. "
|
|
181
|
+
"Please upgrade lance by running: pip install --upgrade pylance"
|
|
182
|
+
)
|
|
183
|
+
except ImportError as e:
|
|
184
|
+
raise ImportError(
|
|
185
|
+
"Unable to import the `lance` package, please install: `pip install pylance`"
|
|
186
|
+
) from e
|
|
187
|
+
|
|
188
|
+
io_config = context.get_context().daft_planning_config.default_io_config if io_config is None else io_config
|
|
189
|
+
storage_options = storage_options or io_config_to_storage_options(io_config, str(uri))
|
|
190
|
+
|
|
191
|
+
lance_ds = construct_lance_dataset(
|
|
192
|
+
uri,
|
|
193
|
+
storage_options=storage_options,
|
|
194
|
+
version=version,
|
|
195
|
+
asof=asof,
|
|
196
|
+
block_size=block_size,
|
|
197
|
+
commit_lock=commit_lock,
|
|
198
|
+
index_cache_size=index_cache_size,
|
|
199
|
+
default_scan_options=default_scan_options,
|
|
200
|
+
metadata_cache_size_bytes=metadata_cache_size_bytes,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
create_scalar_index_internal(
|
|
204
|
+
lance_ds=lance_ds,
|
|
205
|
+
uri=uri,
|
|
206
|
+
column=column,
|
|
207
|
+
index_type=index_type,
|
|
208
|
+
name=name,
|
|
209
|
+
replace=replace,
|
|
210
|
+
storage_options=storage_options,
|
|
211
|
+
fragment_group_size=fragment_group_size,
|
|
212
|
+
num_partitions=num_partitions,
|
|
213
|
+
max_concurrency=max_concurrency,
|
|
214
|
+
**kwargs,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def compact_files(
|
|
219
|
+
uri: str | pathlib.Path,
|
|
220
|
+
io_config: IOConfig | None = None,
|
|
221
|
+
*,
|
|
222
|
+
storage_options: dict[str, Any] | None = None,
|
|
223
|
+
version: int | str | None = None,
|
|
224
|
+
asof: str | None = None,
|
|
225
|
+
block_size: int | None = None,
|
|
226
|
+
commit_lock: Any | None = None,
|
|
227
|
+
index_cache_size: int | None = None,
|
|
228
|
+
default_scan_options: dict[str, Any] | None = None,
|
|
229
|
+
metadata_cache_size_bytes: int | None = None,
|
|
230
|
+
compaction_options: dict[str, Any] | None = None,
|
|
231
|
+
partition_num: int | None = None,
|
|
232
|
+
concurrency: int | None = None,
|
|
233
|
+
) -> Any:
|
|
234
|
+
"""Compact Lance dataset files using Daft UDF-style distributed execution."""
|
|
235
|
+
try:
|
|
236
|
+
import lance
|
|
237
|
+
|
|
238
|
+
from daft_lance.compaction import compact_files_internal
|
|
239
|
+
except ImportError as e:
|
|
240
|
+
raise ImportError(
|
|
241
|
+
"Unable to import the `lance` package, please install: `pip install pylance`"
|
|
242
|
+
) from e
|
|
243
|
+
|
|
244
|
+
io_config = context.get_context().daft_planning_config.default_io_config if io_config is None else io_config
|
|
245
|
+
storage_options = storage_options or io_config_to_storage_options(
|
|
246
|
+
io_config, str(uri) if isinstance(uri, pathlib.Path) else uri
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
lance_ds = lance.dataset(
|
|
250
|
+
uri,
|
|
251
|
+
storage_options=storage_options,
|
|
252
|
+
version=version,
|
|
253
|
+
asof=asof,
|
|
254
|
+
block_size=block_size,
|
|
255
|
+
commit_lock=commit_lock,
|
|
256
|
+
index_cache_size=index_cache_size,
|
|
257
|
+
default_scan_options=default_scan_options,
|
|
258
|
+
metadata_cache_size_bytes=metadata_cache_size_bytes,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
return compact_files_internal(
|
|
262
|
+
lance_ds=lance_ds,
|
|
263
|
+
compaction_options=compaction_options,
|
|
264
|
+
partition_num=partition_num,
|
|
265
|
+
concurrency=concurrency,
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
__all__ = [
|
|
270
|
+
"LanceRestConfig",
|
|
271
|
+
"compact_files",
|
|
272
|
+
"create_lance_table_rest",
|
|
273
|
+
"create_scalar_index",
|
|
274
|
+
"merge_columns",
|
|
275
|
+
"merge_columns_df",
|
|
276
|
+
"register_lance_table_rest",
|
|
277
|
+
"write_lance_rest",
|
|
278
|
+
]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
|
+
|
|
6
|
+
from lance.optimize import Compaction, CompactionMetrics, CompactionOptions, CompactionTask, RewriteResult
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
import lance
|
|
10
|
+
import daft
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CompactionTaskUDF:
|
|
16
|
+
"""UDF to execute a batch of Lance CompactionTasks on remote workers and return execution result dictionaries."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
lance_ds: lance.LanceDataset,
|
|
21
|
+
) -> None:
|
|
22
|
+
self.lance_ds = lance_ds
|
|
23
|
+
|
|
24
|
+
def __call__(self, task: CompactionTask) -> RewriteResult:
|
|
25
|
+
rewrite = task.execute(self.lance_ds)
|
|
26
|
+
return rewrite
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def compact_files_internal(
|
|
30
|
+
lance_ds: lance.LanceDataset,
|
|
31
|
+
*,
|
|
32
|
+
compaction_options: dict[str, Any] | None = None,
|
|
33
|
+
partition_num: int | None = None,
|
|
34
|
+
concurrency: int | None = None,
|
|
35
|
+
) -> CompactionMetrics | None:
|
|
36
|
+
"""Execute Lance file compaction in distributed environment using Daft UDF style."""
|
|
37
|
+
logger.info("Starting UDF-style distributed compaction")
|
|
38
|
+
plan = Compaction.plan(
|
|
39
|
+
lance_ds,
|
|
40
|
+
CompactionOptions(
|
|
41
|
+
**(compaction_options or {}),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
num_tasks = plan.num_tasks()
|
|
45
|
+
logger.info("Compaction plan created with %d tasks", num_tasks)
|
|
46
|
+
|
|
47
|
+
if num_tasks == 0:
|
|
48
|
+
logger.info("No compaction tasks needed")
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
effective_partition_num = partition_num or 1
|
|
52
|
+
effective_partition_num = min(num_tasks, effective_partition_num)
|
|
53
|
+
assert effective_partition_num > 0
|
|
54
|
+
if effective_partition_num == 1:
|
|
55
|
+
df = daft.from_pydict({"task": plan.tasks})
|
|
56
|
+
else:
|
|
57
|
+
df = daft.from_pydict({"task": plan.tasks}).repartition(effective_partition_num)
|
|
58
|
+
|
|
59
|
+
WrappedRunner = daft.cls(
|
|
60
|
+
CompactionTaskUDF,
|
|
61
|
+
max_concurrency=concurrency,
|
|
62
|
+
)
|
|
63
|
+
df = df.select(WrappedRunner(lance_ds)(df["task"]).alias("rewrite"))
|
|
64
|
+
results = df.to_pandas()
|
|
65
|
+
|
|
66
|
+
metrics = Compaction.commit(lance_ds, results["rewrite"].to_list())
|
|
67
|
+
logger.info("Compaction completed successfully. Metrics: %s", metrics)
|
|
68
|
+
return metrics
|