pixeltable 0.4.0rc3__py3-none-any.whl → 0.4.20__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 pixeltable might be problematic. Click here for more details.
- pixeltable/__init__.py +23 -5
- pixeltable/_version.py +1 -0
- pixeltable/catalog/__init__.py +5 -3
- pixeltable/catalog/catalog.py +1318 -404
- pixeltable/catalog/column.py +186 -115
- pixeltable/catalog/dir.py +1 -2
- pixeltable/catalog/globals.py +11 -43
- pixeltable/catalog/insertable_table.py +167 -79
- pixeltable/catalog/path.py +61 -23
- pixeltable/catalog/schema_object.py +9 -10
- pixeltable/catalog/table.py +626 -308
- pixeltable/catalog/table_metadata.py +101 -0
- pixeltable/catalog/table_version.py +713 -569
- pixeltable/catalog/table_version_handle.py +37 -6
- pixeltable/catalog/table_version_path.py +42 -29
- pixeltable/catalog/tbl_ops.py +50 -0
- pixeltable/catalog/update_status.py +191 -0
- pixeltable/catalog/view.py +108 -94
- pixeltable/config.py +128 -22
- pixeltable/dataframe.py +188 -100
- pixeltable/env.py +407 -136
- pixeltable/exceptions.py +6 -0
- pixeltable/exec/__init__.py +3 -0
- pixeltable/exec/aggregation_node.py +7 -8
- pixeltable/exec/cache_prefetch_node.py +83 -110
- pixeltable/exec/cell_materialization_node.py +231 -0
- pixeltable/exec/cell_reconstruction_node.py +135 -0
- pixeltable/exec/component_iteration_node.py +4 -3
- pixeltable/exec/data_row_batch.py +8 -65
- pixeltable/exec/exec_context.py +16 -4
- pixeltable/exec/exec_node.py +13 -36
- pixeltable/exec/expr_eval/evaluators.py +7 -6
- pixeltable/exec/expr_eval/expr_eval_node.py +27 -12
- pixeltable/exec/expr_eval/globals.py +8 -5
- pixeltable/exec/expr_eval/row_buffer.py +1 -2
- pixeltable/exec/expr_eval/schedulers.py +190 -30
- pixeltable/exec/globals.py +32 -0
- pixeltable/exec/in_memory_data_node.py +18 -18
- pixeltable/exec/object_store_save_node.py +293 -0
- pixeltable/exec/row_update_node.py +16 -9
- pixeltable/exec/sql_node.py +206 -101
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/arithmetic_expr.py +27 -22
- pixeltable/exprs/array_slice.py +3 -3
- pixeltable/exprs/column_property_ref.py +34 -30
- pixeltable/exprs/column_ref.py +92 -96
- pixeltable/exprs/comparison.py +5 -5
- pixeltable/exprs/compound_predicate.py +5 -4
- pixeltable/exprs/data_row.py +152 -55
- pixeltable/exprs/expr.py +62 -43
- pixeltable/exprs/expr_dict.py +3 -3
- pixeltable/exprs/expr_set.py +17 -10
- pixeltable/exprs/function_call.py +75 -37
- pixeltable/exprs/globals.py +1 -2
- pixeltable/exprs/in_predicate.py +4 -4
- pixeltable/exprs/inline_expr.py +10 -27
- pixeltable/exprs/is_null.py +1 -3
- pixeltable/exprs/json_mapper.py +8 -8
- pixeltable/exprs/json_path.py +56 -22
- pixeltable/exprs/literal.py +5 -5
- pixeltable/exprs/method_ref.py +2 -2
- pixeltable/exprs/object_ref.py +2 -2
- pixeltable/exprs/row_builder.py +127 -53
- pixeltable/exprs/rowid_ref.py +8 -12
- pixeltable/exprs/similarity_expr.py +50 -25
- pixeltable/exprs/sql_element_cache.py +4 -4
- pixeltable/exprs/string_op.py +5 -5
- pixeltable/exprs/type_cast.py +3 -5
- pixeltable/func/__init__.py +1 -0
- pixeltable/func/aggregate_function.py +8 -8
- pixeltable/func/callable_function.py +9 -9
- pixeltable/func/expr_template_function.py +10 -10
- pixeltable/func/function.py +18 -20
- pixeltable/func/function_registry.py +6 -7
- pixeltable/func/globals.py +2 -3
- pixeltable/func/mcp.py +74 -0
- pixeltable/func/query_template_function.py +20 -18
- pixeltable/func/signature.py +43 -16
- pixeltable/func/tools.py +23 -13
- pixeltable/func/udf.py +18 -20
- pixeltable/functions/__init__.py +6 -0
- pixeltable/functions/anthropic.py +93 -33
- pixeltable/functions/audio.py +114 -10
- pixeltable/functions/bedrock.py +13 -6
- pixeltable/functions/date.py +1 -1
- pixeltable/functions/deepseek.py +20 -9
- pixeltable/functions/fireworks.py +2 -2
- pixeltable/functions/gemini.py +28 -11
- pixeltable/functions/globals.py +13 -13
- pixeltable/functions/groq.py +108 -0
- pixeltable/functions/huggingface.py +1046 -23
- pixeltable/functions/image.py +9 -18
- pixeltable/functions/llama_cpp.py +23 -8
- pixeltable/functions/math.py +3 -4
- pixeltable/functions/mistralai.py +4 -15
- pixeltable/functions/ollama.py +16 -9
- pixeltable/functions/openai.py +104 -82
- pixeltable/functions/openrouter.py +143 -0
- pixeltable/functions/replicate.py +2 -2
- pixeltable/functions/reve.py +250 -0
- pixeltable/functions/string.py +21 -28
- pixeltable/functions/timestamp.py +13 -14
- pixeltable/functions/together.py +4 -6
- pixeltable/functions/twelvelabs.py +92 -0
- pixeltable/functions/util.py +6 -1
- pixeltable/functions/video.py +1388 -106
- pixeltable/functions/vision.py +7 -7
- pixeltable/functions/whisper.py +15 -7
- pixeltable/functions/whisperx.py +179 -0
- pixeltable/{ext/functions → functions}/yolox.py +2 -4
- pixeltable/globals.py +332 -105
- pixeltable/index/base.py +13 -22
- pixeltable/index/btree.py +23 -22
- pixeltable/index/embedding_index.py +32 -44
- pixeltable/io/__init__.py +4 -2
- pixeltable/io/datarows.py +7 -6
- pixeltable/io/external_store.py +49 -77
- pixeltable/io/fiftyone.py +11 -11
- pixeltable/io/globals.py +29 -28
- pixeltable/io/hf_datasets.py +17 -9
- pixeltable/io/label_studio.py +70 -66
- pixeltable/io/lancedb.py +3 -0
- pixeltable/io/pandas.py +12 -11
- pixeltable/io/parquet.py +13 -93
- pixeltable/io/table_data_conduit.py +71 -47
- pixeltable/io/utils.py +3 -3
- pixeltable/iterators/__init__.py +2 -1
- pixeltable/iterators/audio.py +21 -11
- pixeltable/iterators/document.py +116 -55
- pixeltable/iterators/image.py +5 -2
- pixeltable/iterators/video.py +293 -13
- pixeltable/metadata/__init__.py +4 -2
- pixeltable/metadata/converters/convert_18.py +2 -2
- pixeltable/metadata/converters/convert_19.py +2 -2
- pixeltable/metadata/converters/convert_20.py +2 -2
- pixeltable/metadata/converters/convert_21.py +2 -2
- pixeltable/metadata/converters/convert_22.py +2 -2
- pixeltable/metadata/converters/convert_24.py +2 -2
- pixeltable/metadata/converters/convert_25.py +2 -2
- pixeltable/metadata/converters/convert_26.py +2 -2
- pixeltable/metadata/converters/convert_29.py +4 -4
- pixeltable/metadata/converters/convert_34.py +2 -2
- pixeltable/metadata/converters/convert_36.py +2 -2
- pixeltable/metadata/converters/convert_37.py +15 -0
- pixeltable/metadata/converters/convert_38.py +39 -0
- pixeltable/metadata/converters/convert_39.py +124 -0
- pixeltable/metadata/converters/convert_40.py +73 -0
- pixeltable/metadata/converters/util.py +13 -12
- pixeltable/metadata/notes.py +4 -0
- pixeltable/metadata/schema.py +79 -42
- pixeltable/metadata/utils.py +74 -0
- pixeltable/mypy/__init__.py +3 -0
- pixeltable/mypy/mypy_plugin.py +123 -0
- pixeltable/plan.py +274 -223
- pixeltable/share/__init__.py +1 -1
- pixeltable/share/packager.py +259 -129
- pixeltable/share/protocol/__init__.py +34 -0
- pixeltable/share/protocol/common.py +170 -0
- pixeltable/share/protocol/operation_types.py +33 -0
- pixeltable/share/protocol/replica.py +109 -0
- pixeltable/share/publish.py +213 -57
- pixeltable/store.py +238 -175
- pixeltable/type_system.py +104 -63
- pixeltable/utils/__init__.py +2 -3
- pixeltable/utils/arrow.py +108 -13
- pixeltable/utils/av.py +298 -0
- pixeltable/utils/azure_store.py +305 -0
- pixeltable/utils/code.py +3 -3
- pixeltable/utils/console_output.py +4 -1
- pixeltable/utils/coroutine.py +6 -23
- pixeltable/utils/dbms.py +31 -5
- pixeltable/utils/description_helper.py +4 -5
- pixeltable/utils/documents.py +5 -6
- pixeltable/utils/exception_handler.py +7 -30
- pixeltable/utils/filecache.py +6 -6
- pixeltable/utils/formatter.py +4 -6
- pixeltable/utils/gcs_store.py +283 -0
- pixeltable/utils/http_server.py +2 -3
- pixeltable/utils/iceberg.py +1 -2
- pixeltable/utils/image.py +17 -0
- pixeltable/utils/lancedb.py +88 -0
- pixeltable/utils/local_store.py +316 -0
- pixeltable/utils/misc.py +5 -0
- pixeltable/utils/object_stores.py +528 -0
- pixeltable/utils/pydantic.py +60 -0
- pixeltable/utils/pytorch.py +5 -6
- pixeltable/utils/s3_store.py +392 -0
- pixeltable-0.4.20.dist-info/METADATA +587 -0
- pixeltable-0.4.20.dist-info/RECORD +218 -0
- {pixeltable-0.4.0rc3.dist-info → pixeltable-0.4.20.dist-info}/WHEEL +1 -1
- pixeltable-0.4.20.dist-info/entry_points.txt +2 -0
- pixeltable/__version__.py +0 -3
- pixeltable/ext/__init__.py +0 -17
- pixeltable/ext/functions/__init__.py +0 -11
- pixeltable/ext/functions/whisperx.py +0 -77
- pixeltable/utils/media_store.py +0 -77
- pixeltable/utils/s3.py +0 -17
- pixeltable/utils/sample.py +0 -25
- pixeltable-0.4.0rc3.dist-info/METADATA +0 -435
- pixeltable-0.4.0rc3.dist-info/RECORD +0 -189
- pixeltable-0.4.0rc3.dist-info/entry_points.txt +0 -3
- {pixeltable-0.4.0rc3.dist-info → pixeltable-0.4.20.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import dataclasses
|
|
4
|
+
import itertools
|
|
5
|
+
import logging
|
|
6
|
+
from collections import defaultdict, deque
|
|
7
|
+
from concurrent import futures
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import AsyncIterator, Iterator, NamedTuple
|
|
10
|
+
|
|
11
|
+
from pixeltable import exprs
|
|
12
|
+
from pixeltable.utils.object_stores import ObjectOps, ObjectPath, StorageTarget
|
|
13
|
+
|
|
14
|
+
from .data_row_batch import DataRowBatch
|
|
15
|
+
from .exec_node import ExecNode
|
|
16
|
+
|
|
17
|
+
_logger = logging.getLogger('pixeltable')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ObjectStoreSaveNode(ExecNode):
|
|
21
|
+
"""Save files into designated object store(s).
|
|
22
|
+
|
|
23
|
+
Each row may have multiple files that need to be saved to a destination.
|
|
24
|
+
Each file may be referenced by more than one column in the row.
|
|
25
|
+
Each file may have multiple destinations, e.g., S3 bucket and local file system.
|
|
26
|
+
If there are multiple destinations, the file cannot be moved to any destination
|
|
27
|
+
until it has been copied to all of the other destinations.
|
|
28
|
+
Diagrammatically:
|
|
29
|
+
Row -> [src_path1, src_path2, ...]
|
|
30
|
+
src_path -> [dest1, dest2, ...]
|
|
31
|
+
dest1: [row_location1, row_location2, ...]
|
|
32
|
+
Paths with multiple destinations are removed from the TempStore only after all destination copies are complete.
|
|
33
|
+
|
|
34
|
+
TODO:
|
|
35
|
+
- Process a row at a time and limit the number of in-flight rows to control memory usage
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
QUEUE_DEPTH_HIGH_WATER = 50 # target number of in-flight requests
|
|
39
|
+
QUEUE_DEPTH_LOW_WATER = 20 # target number of in-flight requests
|
|
40
|
+
BATCH_SIZE = 16
|
|
41
|
+
MAX_WORKERS = 15
|
|
42
|
+
|
|
43
|
+
class WorkDesignator(NamedTuple):
|
|
44
|
+
"""Specify the source and destination for a WorkItem"""
|
|
45
|
+
|
|
46
|
+
src_path: str # source of the file to be processed
|
|
47
|
+
destination: str # destination URI for the file to be processed
|
|
48
|
+
|
|
49
|
+
class WorkItem(NamedTuple):
|
|
50
|
+
src_path: Path
|
|
51
|
+
destination: str | None
|
|
52
|
+
info: exprs.ColumnSlotIdx # column info for the file being processed
|
|
53
|
+
destination_count: int = 1 # number of unique destinations for this file
|
|
54
|
+
|
|
55
|
+
retain_input_order: bool # if True, return rows in the exact order they were received
|
|
56
|
+
file_col_info: list[exprs.ColumnSlotIdx]
|
|
57
|
+
|
|
58
|
+
# execution state
|
|
59
|
+
num_returned_rows: int
|
|
60
|
+
|
|
61
|
+
# ready_rows: rows that are ready to be returned, ordered by row idx;
|
|
62
|
+
# the implied row idx of ready_rows[0] is num_returned_rows
|
|
63
|
+
ready_rows: deque[exprs.DataRow | None]
|
|
64
|
+
|
|
65
|
+
in_flight_rows: dict[int, ObjectStoreSaveNode.RowState] # rows with in-flight work; id(row) -> RowState
|
|
66
|
+
in_flight_requests: dict[
|
|
67
|
+
futures.Future, WorkDesignator
|
|
68
|
+
] # in-flight requests to save paths: Future -> WorkDesignator
|
|
69
|
+
in_flight_work: dict[
|
|
70
|
+
WorkDesignator, list[tuple[exprs.DataRow, exprs.ColumnSlotIdx]]
|
|
71
|
+
] # WorkDesignator -> [(row, info)]
|
|
72
|
+
|
|
73
|
+
input_finished: bool
|
|
74
|
+
row_idx: Iterator[int | None]
|
|
75
|
+
|
|
76
|
+
@dataclasses.dataclass
|
|
77
|
+
class RowState:
|
|
78
|
+
row: exprs.DataRow
|
|
79
|
+
idx: int | None # position in input stream; None if we don't retain input order
|
|
80
|
+
num_missing: int # number of references to media files in this row
|
|
81
|
+
delete_destinations: list[Path] # paths to delete after all copies are complete
|
|
82
|
+
|
|
83
|
+
def __init__(self, file_col_info: list[exprs.ColumnSlotIdx], input: ExecNode, retain_input_order: bool = True):
|
|
84
|
+
# input_/output_exprs=[]: we don't have anything to evaluate
|
|
85
|
+
super().__init__(input.row_builder, [], [], input)
|
|
86
|
+
self.retain_input_order = retain_input_order
|
|
87
|
+
self.file_col_info = file_col_info
|
|
88
|
+
|
|
89
|
+
self.num_returned_rows = 0
|
|
90
|
+
self.ready_rows = deque()
|
|
91
|
+
self.in_flight_rows = {}
|
|
92
|
+
self.in_flight_requests = {}
|
|
93
|
+
self.in_flight_work = {}
|
|
94
|
+
self.input_finished = False
|
|
95
|
+
self.row_idx = itertools.count() if retain_input_order else itertools.repeat(None)
|
|
96
|
+
assert self.QUEUE_DEPTH_HIGH_WATER > self.QUEUE_DEPTH_LOW_WATER
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def queued_work(self) -> int:
|
|
100
|
+
return len(self.in_flight_requests)
|
|
101
|
+
|
|
102
|
+
async def get_input_batch(self, input_iter: AsyncIterator[DataRowBatch]) -> DataRowBatch | None:
|
|
103
|
+
"""Get the next batch of input rows, or None if there are no more rows"""
|
|
104
|
+
try:
|
|
105
|
+
input_batch = await anext(input_iter)
|
|
106
|
+
if input_batch is None:
|
|
107
|
+
self.input_finished = True
|
|
108
|
+
return input_batch
|
|
109
|
+
except StopAsyncIteration:
|
|
110
|
+
self.input_finished = True
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
async def __aiter__(self) -> AsyncIterator[DataRowBatch]:
|
|
114
|
+
input_iter = aiter(self.input)
|
|
115
|
+
with futures.ThreadPoolExecutor(max_workers=self.MAX_WORKERS) as executor:
|
|
116
|
+
while True:
|
|
117
|
+
# Create work to fill the queue to the high water mark ... ?without overrunning the in-flight row limit.
|
|
118
|
+
while not self.input_finished and self.queued_work < self.QUEUE_DEPTH_HIGH_WATER:
|
|
119
|
+
input_batch = await self.get_input_batch(input_iter)
|
|
120
|
+
if input_batch is not None:
|
|
121
|
+
self.__process_input_batch(input_batch, executor)
|
|
122
|
+
|
|
123
|
+
# Wait for enough completions to enable more queueing or if we're done
|
|
124
|
+
while self.queued_work > self.QUEUE_DEPTH_LOW_WATER or (self.input_finished and self.queued_work > 0):
|
|
125
|
+
done, _ = futures.wait(self.in_flight_requests, return_when=futures.FIRST_COMPLETED)
|
|
126
|
+
self.__process_completions(done, ignore_errors=self.ctx.ignore_errors)
|
|
127
|
+
|
|
128
|
+
# Emit results to meet batch size requirements or empty the in-flight row queue
|
|
129
|
+
if self.__has_ready_batch() or (
|
|
130
|
+
len(self.ready_rows) > 0 and self.input_finished and self.queued_work == 0
|
|
131
|
+
):
|
|
132
|
+
# create DataRowBatch from the first BATCH_SIZE ready rows
|
|
133
|
+
batch = DataRowBatch(self.row_builder)
|
|
134
|
+
rows = [self.ready_rows.popleft() for _ in range(min(self.BATCH_SIZE, len(self.ready_rows)))]
|
|
135
|
+
for row in rows:
|
|
136
|
+
assert row is not None
|
|
137
|
+
batch.add_row(row)
|
|
138
|
+
self.num_returned_rows += len(rows)
|
|
139
|
+
_logger.debug(f'returning {len(rows)} rows')
|
|
140
|
+
yield batch
|
|
141
|
+
|
|
142
|
+
if self.input_finished and self.queued_work == 0 and len(self.ready_rows) == 0:
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
def __has_ready_batch(self) -> bool:
|
|
146
|
+
"""True if there are >= BATCH_SIZES entries in ready_rows and the first BATCH_SIZE ones are all non-None"""
|
|
147
|
+
return (
|
|
148
|
+
sum(int(row is not None) for row in itertools.islice(self.ready_rows, self.BATCH_SIZE)) == self.BATCH_SIZE
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def __add_ready_row(self, row: exprs.DataRow, row_idx: int | None) -> None:
|
|
152
|
+
if row_idx is None:
|
|
153
|
+
self.ready_rows.append(row)
|
|
154
|
+
else:
|
|
155
|
+
# extend ready_rows to accommodate row_idx
|
|
156
|
+
idx = row_idx - self.num_returned_rows
|
|
157
|
+
if idx >= len(self.ready_rows):
|
|
158
|
+
self.ready_rows.extend([None] * (idx - len(self.ready_rows) + 1))
|
|
159
|
+
self.ready_rows[idx] = row
|
|
160
|
+
|
|
161
|
+
def __process_completions(self, done: set[futures.Future], ignore_errors: bool) -> None:
|
|
162
|
+
from pixeltable.utils.local_store import TempStore
|
|
163
|
+
|
|
164
|
+
for f in done:
|
|
165
|
+
work_designator = self.in_flight_requests.pop(f)
|
|
166
|
+
new_file_url, exc = f.result()
|
|
167
|
+
if exc is not None and not ignore_errors:
|
|
168
|
+
raise exc
|
|
169
|
+
assert new_file_url is not None
|
|
170
|
+
|
|
171
|
+
# add the local path/exception to the slots that reference the url
|
|
172
|
+
for row, info in self.in_flight_work.pop(work_designator):
|
|
173
|
+
if exc is not None:
|
|
174
|
+
self.row_builder.set_exc(row, info.slot_idx, exc)
|
|
175
|
+
else:
|
|
176
|
+
row.file_urls[info.slot_idx] = new_file_url
|
|
177
|
+
|
|
178
|
+
state = self.in_flight_rows[id(row)]
|
|
179
|
+
state.num_missing -= 1
|
|
180
|
+
if state.num_missing == 0:
|
|
181
|
+
# All operations for this row are complete. Delete all files which had multiple destinations
|
|
182
|
+
for src_path in state.delete_destinations:
|
|
183
|
+
TempStore.delete_media_file(src_path)
|
|
184
|
+
del self.in_flight_rows[id(row)]
|
|
185
|
+
self.__add_ready_row(row, state.idx)
|
|
186
|
+
|
|
187
|
+
def __process_input_row(self, row: exprs.DataRow) -> list[ObjectStoreSaveNode.WorkItem]:
|
|
188
|
+
"""Process a batch of input rows, generating a list of work"""
|
|
189
|
+
from pixeltable.utils.local_store import LocalStore, TempStore
|
|
190
|
+
|
|
191
|
+
# Create a list of work to do for media storage in this row
|
|
192
|
+
row_idx = next(self.row_idx)
|
|
193
|
+
row_to_do: list[ObjectStoreSaveNode.WorkItem] = []
|
|
194
|
+
num_missing = 0
|
|
195
|
+
unique_destinations: dict[Path, int] = defaultdict(int) # destination -> count of unique destinations
|
|
196
|
+
|
|
197
|
+
for info in self.file_col_info:
|
|
198
|
+
col, index = info
|
|
199
|
+
# we may need to store this imagehave yet to store this image
|
|
200
|
+
if row.prepare_col_val_for_save(index, col):
|
|
201
|
+
row.file_urls[index] = row.save_media_to_temp(index, col)
|
|
202
|
+
|
|
203
|
+
url = row.file_urls[index]
|
|
204
|
+
if url is None:
|
|
205
|
+
# nothing to do
|
|
206
|
+
continue
|
|
207
|
+
|
|
208
|
+
assert row.excs[index] is None
|
|
209
|
+
assert col.col_type.is_media_type()
|
|
210
|
+
|
|
211
|
+
destination = info.col.destination
|
|
212
|
+
if destination is not None:
|
|
213
|
+
soa = ObjectPath.parse_object_storage_addr(destination, False)
|
|
214
|
+
if soa.storage_target == StorageTarget.LOCAL_STORE and LocalStore(soa).resolve_url(url) is not None:
|
|
215
|
+
# A local non-default destination was specified, and the url already points there
|
|
216
|
+
continue
|
|
217
|
+
|
|
218
|
+
src_path = LocalStore.file_url_to_path(url)
|
|
219
|
+
if src_path is None:
|
|
220
|
+
# The url does not point to a local file, do not attempt to copy/move it
|
|
221
|
+
continue
|
|
222
|
+
|
|
223
|
+
if destination is None and not TempStore.contains_path(src_path):
|
|
224
|
+
# Do not copy local file URLs to the LocalStore
|
|
225
|
+
continue
|
|
226
|
+
|
|
227
|
+
work_designator = ObjectStoreSaveNode.WorkDesignator(str(src_path), destination)
|
|
228
|
+
locations = self.in_flight_work.get(work_designator)
|
|
229
|
+
if locations is not None:
|
|
230
|
+
# we've already seen this
|
|
231
|
+
locations.append((row, info))
|
|
232
|
+
num_missing += 1
|
|
233
|
+
continue
|
|
234
|
+
|
|
235
|
+
work_item = ObjectStoreSaveNode.WorkItem(src_path, destination, info)
|
|
236
|
+
row_to_do.append(work_item)
|
|
237
|
+
self.in_flight_work[work_designator] = [(row, info)]
|
|
238
|
+
num_missing += 1
|
|
239
|
+
unique_destinations[src_path] += 1
|
|
240
|
+
|
|
241
|
+
# Update work items to reflect the number of unique destinations
|
|
242
|
+
new_to_do = []
|
|
243
|
+
for work_item in row_to_do:
|
|
244
|
+
if unique_destinations[work_item.src_path] == 1 and TempStore.contains_path(work_item.src_path):
|
|
245
|
+
new_to_do.append(work_item)
|
|
246
|
+
else:
|
|
247
|
+
new_to_do.append(
|
|
248
|
+
ObjectStoreSaveNode.WorkItem(
|
|
249
|
+
work_item.src_path,
|
|
250
|
+
work_item.destination,
|
|
251
|
+
work_item.info,
|
|
252
|
+
destination_count=unique_destinations[work_item.src_path] + 1,
|
|
253
|
+
# +1 for the TempStore destination
|
|
254
|
+
)
|
|
255
|
+
)
|
|
256
|
+
delete_destinations = [k for k, v in unique_destinations.items() if v > 1 and TempStore.contains_path(k)]
|
|
257
|
+
row_to_do = new_to_do
|
|
258
|
+
|
|
259
|
+
if len(row_to_do) > 0:
|
|
260
|
+
self.in_flight_rows[id(row)] = self.RowState(
|
|
261
|
+
row, row_idx, num_missing, delete_destinations=delete_destinations
|
|
262
|
+
)
|
|
263
|
+
else:
|
|
264
|
+
self.__add_ready_row(row, row_idx)
|
|
265
|
+
return row_to_do
|
|
266
|
+
|
|
267
|
+
def __process_input_batch(self, input_batch: DataRowBatch, executor: futures.ThreadPoolExecutor) -> None:
|
|
268
|
+
"""Process a batch of input rows, submitting temporary files for upload"""
|
|
269
|
+
work_to_do: list[ObjectStoreSaveNode.WorkItem] = []
|
|
270
|
+
|
|
271
|
+
for row in input_batch:
|
|
272
|
+
row_to_do = self.__process_input_row(row)
|
|
273
|
+
if len(row_to_do) > 0:
|
|
274
|
+
work_to_do.extend(row_to_do)
|
|
275
|
+
|
|
276
|
+
for work_item in work_to_do:
|
|
277
|
+
f = executor.submit(self.__persist_media_file, work_item)
|
|
278
|
+
self.in_flight_requests[f] = ObjectStoreSaveNode.WorkDesignator(
|
|
279
|
+
str(work_item.src_path), work_item.destination
|
|
280
|
+
)
|
|
281
|
+
_logger.debug(f'submitted {work_item}')
|
|
282
|
+
|
|
283
|
+
def __persist_media_file(self, work_item: WorkItem) -> tuple[str | None, Exception | None]:
|
|
284
|
+
"""Move data from the TempStore to another location"""
|
|
285
|
+
src_path = work_item.src_path
|
|
286
|
+
col = work_item.info.col
|
|
287
|
+
assert col.destination == work_item.destination
|
|
288
|
+
try:
|
|
289
|
+
new_file_url = ObjectOps.put_file(col, src_path, work_item.destination_count == 1)
|
|
290
|
+
return new_file_url, None
|
|
291
|
+
except Exception as e:
|
|
292
|
+
_logger.debug(f'Failed to move/copy {src_path}: {e}', exc_info=e)
|
|
293
|
+
return None, e
|
|
@@ -14,10 +14,18 @@ class RowUpdateNode(ExecNode):
|
|
|
14
14
|
Update individual rows in the input batches, identified by key columns.
|
|
15
15
|
|
|
16
16
|
The updates for a row are provided as a dict of column names to new values.
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
Populates the slots of the columns present in the update list.
|
|
18
|
+
Assumptions:
|
|
19
|
+
- all update dicts contain the same keys
|
|
20
|
+
- the input node populates DataRow.cell_vals for all primary key columns
|
|
19
21
|
"""
|
|
20
22
|
|
|
23
|
+
updates: dict[tuple, dict[catalog.Column, Any]]
|
|
24
|
+
is_rowid_key: bool # if True, key_vals_batch contains rowids rather than primary key values
|
|
25
|
+
col_slot_idxs: dict[catalog.Column, int]
|
|
26
|
+
pk_columns: list[catalog.Column]
|
|
27
|
+
matched_key_vals: set[tuple]
|
|
28
|
+
|
|
21
29
|
def __init__(
|
|
22
30
|
self,
|
|
23
31
|
tbl: catalog.TableVersionPath,
|
|
@@ -37,16 +45,16 @@ class RowUpdateNode(ExecNode):
|
|
|
37
45
|
for col_ref in row_builder.unique_exprs
|
|
38
46
|
if isinstance(col_ref, exprs.ColumnRef)
|
|
39
47
|
}
|
|
48
|
+
# all update target columns should have assigned slot idxs
|
|
49
|
+
assert all(col in all_col_slot_idxs for col in col_vals_batch[0])
|
|
40
50
|
self.col_slot_idxs = {col: all_col_slot_idxs[col] for col in col_vals_batch[0]}
|
|
41
|
-
self.
|
|
42
|
-
self.matched_key_vals
|
|
51
|
+
self.pk_columns = tbl.tbl_version.get().primary_key_columns()
|
|
52
|
+
self.matched_key_vals = set()
|
|
43
53
|
|
|
44
54
|
async def __aiter__(self) -> AsyncIterator[DataRowBatch]:
|
|
45
55
|
async for batch in self.input:
|
|
46
56
|
for row in batch:
|
|
47
|
-
key_vals = (
|
|
48
|
-
row.rowid if self.is_rowid_key else tuple(row[slot_idx] for slot_idx in self.key_slot_idxs.values())
|
|
49
|
-
)
|
|
57
|
+
key_vals = row.rowid if self.is_rowid_key else tuple(row.cell_vals[col.id] for col in self.pk_columns)
|
|
50
58
|
if key_vals not in self.updates:
|
|
51
59
|
continue
|
|
52
60
|
self.matched_key_vals.add(key_vals)
|
|
@@ -59,11 +67,10 @@ class RowUpdateNode(ExecNode):
|
|
|
59
67
|
def unmatched_rows(self) -> list[dict[str, Any]]:
|
|
60
68
|
"""Return rows that didn't get used in the updates as a list of dicts compatible with TableVersion.insert()."""
|
|
61
69
|
result: list[dict[str, Any]] = []
|
|
62
|
-
key_cols = self.key_slot_idxs.keys()
|
|
63
70
|
for key_vals, col_vals in self.updates.items():
|
|
64
71
|
if key_vals in self.matched_key_vals:
|
|
65
72
|
continue
|
|
66
|
-
row = {col.name: val for col, val in zip(
|
|
73
|
+
row = {col.name: val for col, val in zip(self.pk_columns, key_vals)}
|
|
67
74
|
row.update({col.name: val for col, val in col_vals.items()})
|
|
68
75
|
result.append(row)
|
|
69
76
|
return result
|