1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# Generated by crates/delta-arrow-reader-python/generate_api_docs.py.
# Do not edit. Update the Rust binding comments or the Python type stubs instead.
:
= |
"""A failure while opening a table or preparing a query.
Inspect `phase` and `code` to identify the failure without parsing the message.
Messages omit sensitive details such as table paths and storage credentials.
Attributes:
phase: The stage that failed, such as `schema` or `datafusion`.
code: The error category, such as `schema_conversion` or `sql_planning`.
Invalid Python arguments can raise built-in exceptions such as `TypeError`
or `ValueError` instead. Failures while consuming a PyArrow reader use PyArrow
exceptions; catch those around iteration or `read_all()` as well.
"""
:
:
"""Control how a scan reads files and buffers results.
Start with the defaults. If a query uses too many resources, try lowering
`max_concurrent_file_reads_per_scan`. It caps files read at once in one scan,
not network requests or total memory. A lower limit may slow the query.
Examples:
```python
from delta_arrow_reader import ScanExecutionOptions
options = ScanExecutionOptions(max_concurrent_file_reads_per_scan=4)
with table.to_reader(execution_options=options, limit=10) as reader:
print(reader.read_all())
```
Pass the options to `DeltaTable(...)` for direct-scan defaults, to `scan()`
or `to_reader()` for one scan, or to `Session.register_table()` for SQL.
An override replaces the entire options object. Instances are immutable;
create a new one to change settings. These resource limits do not change
the connection check's budget during table initialization.
Args:
parquet_backend: `"direct"` uses the reader's asynchronous Parquet backend.
`"delta_kernel"` delegates data-file reads to Delta Kernel.
max_concurrent_file_reads_per_scan: File-read limit across all partitions
of one scan. `None` derives it from the partition target times the
per-partition limit, capped at the concurrency capacity below.
max_concurrent_file_reads_per_partition: File-read limit for each group
of files processed together. Both this and the scan limit apply.
output_buffer_batches_per_partition: Batches each partition can queue
while waiting for the consumer. Larger buffers use more memory.
prefetch_files_per_partition: Upcoming files to prepare ahead of time
per partition. `0` disables prefetch. Direct backend only.
parquet_metadata_size_hint_bytes: Bytes to request initially from each
file's end when loading Parquet metadata. `None` disables the hint.
If the metadata is larger, the reader makes another request.
Direct backend only.
parquet_full_file_read_threshold_bytes: Read a file entirely into memory
when its size is at or below this threshold. `None` disables this.
This can reduce requests for small files but reads unneeded data
and uses more memory. Direct backend only.
When set, the file-read limits and output buffer size must be positive integers
no greater than `sys.maxsize >> 2`. Prefetch accepts nonnegative integers.
Byte settings accept positive integers or `None`. All integers must fit
`2 * sys.maxsize + 1`; booleans are not accepted.
Raises:
TypeError: A setting has the wrong type, including a Boolean for an integer.
ValueError: A setting is out of range or the backend name is unknown.
OverflowError: An integer exceeds `2 * sys.maxsize + 1`."""
...
"""Selected Parquet backend: `"direct"` or `"delta_kernel"`."""
...
"""File-read limit for a whole scan, or `None` to derive it automatically."""
...
"""Maximum number of files each scan partition can read at once."""
...
"""Maximum number of output batches queued per partition."""
...
"""Number of upcoming files prepared per partition; `0` disables prefetch."""
...
"""Initial Parquet metadata request size in bytes, or `None` for no hint."""
...
"""Largest file to buffer entirely, in bytes, or `None` to disable this."""
...
"""Hand a scan to a consumer that supports the Arrow stream protocol.
Created by `DeltaTable.scan()`; it has no public constructor. For normal
PyArrow usage, `DeltaTable.to_reader()` does this conversion for you.
Examples:
```python
import pyarrow as pa
stream = table.scan(limit=10)
with pa.RecordBatchReader.from_stream(stream) as reader:
print(reader.read_all())
```
Each stream can be exported once. After export, close the consuming reader
to release resources; closing this object does not close the consumer.
If you decide not to export it, call `close()` to release the scan."""
"""Transfer the stream to an Arrow consumer. Usually called by the consumer.
Args:
requested_schema: `None` or an Arrow schema capsule identical to the
scan schema. This method does not cast or convert the data.
Returns:
An Arrow stream capsule that owns the scan resources.
Raises:
TypeError: The requested schema is not a capsule.
ValueError: The schema capsule is invalid or incompatible.
NotImplementedError: The consumer requests an alternate representation.
RuntimeError: The stream has already been exported or closed.
A rejected schema request leaves the stream available for another attempt."""
...
"""Release an unexported stream. Repeated calls have no effect.
After export, call `close()` on the consuming reader instead."""
...
"""Return this exporter for use in a `with` block."""
...
"""Close any unexported stream on leaving the block. Exceptions are not suppressed."""
...
"""Open a Delta table for repeated queries against the same version.
Use `to_reader()` to read batches or register the table with a `Session`
to query it with SQL. The loaded version stays fixed even if another process
writes to the table. Call `refresh()` to get a new table with the latest version.
Examples:
Replace the path with your table's directory or S3 URL.
```python
from delta_arrow_reader import DeltaTable
table = DeltaTable("path/to/table")
with table.to_reader(limit=10) as reader:
print(reader.read_all())
```
Args:
location: Local directory or storage URL containing the Delta table.
Accepts a string or a path object that resolves to a string.
version: Version to load. `None` selects the latest available version.
An explicit version must be an integer from `0` through `2**64 - 1`;
booleans are not accepted.
storage_options: Storage configuration as string keys and string values,
for example `{"aws_region": "us-west-2"}` for S3.
warmup: How much preparation to do when opening the table.
`"automatic"` prepares reusable file information and checks connection
speed on supported S3 stores; local tables skip this extra work.
`"query_planning"` prepares file information without test reads of data.
`"none"` leaves that preparation to each query. Both explicit modes
skip the connection check and keep partial-page reads inactive.
execution_options: Defaults for this table's `scan()` and `to_reader()`
calls. `None` uses `ScanExecutionOptions()`.
SQL registrations have their own defaults.
The automatic connection check has a five-second budget and may finish sooner.
Loading file information takes additional time. Keep using the same table
object to reuse this work; query results are not cached.
Raises:
TypeError: An argument has the wrong type, including a Boolean version.
ValueError: The version is negative or the warmup mode is unknown.
OverflowError: The version exceeds `2**64 - 1`.
DeltaReaderError: The table cannot be loaded or prepared."""
...
"""Select rows and columns, then read them as PyArrow batches.
Use a `with` block so the reader closes even when you stop early.
Iterate over batches to process the result incrementally, or use
`read_all()` to collect it in memory. Rows have no guaranteed order;
use SQL with `ORDER BY` when order matters.
Examples:
For a table with `id` and `region` columns:
```python
with table.to_reader(
columns=["id", "region"],
filters=[("id", ">=", 100)],
limit=10,
) as reader:
for batch in reader:
print(batch.to_pydict())
```
Args:
columns: Column names in output order. `None` selects all columns.
An empty list selects no columns but preserves row counts.
filters: Conditions written as `(column, operator, value)` tuples.
A list of tuples combines conditions with AND. A list of lists
combines AND groups with OR. `None` or `[]` disables filtering;
an empty inner group is true. Filter columns need not be in the
output. See the filtering rules below for operators and values.
limit: Maximum number of rows after filtering. `None` reads all
matching rows; `0` returns no rows. Must be a nonnegative integer.
target_partitions: Target number of groups of files to process in
parallel. `None` chooses automatically; an override must be a
positive integer. This does not change the table's stored layout.
execution_options: Settings for this scan. `None` inherits the table's
settings. A supplied `ScanExecutionOptions` replaces the whole
settings object for this scan without changing later scans.
Returns:
A reader that yields `pyarrow.RecordBatch` objects and retains its
snapshot independently of the table object. Result data is read when
you request the first batch.
Raises:
TypeError: An argument or filter value has the wrong type. Booleans
are not accepted for integer settings or integer filter values.
ValueError: A limit, partition target, operator or filter value is invalid.
OverflowError: An integer does not fit its column type, or a limit or
partition target exceeds `2 * sys.maxsize + 1`.
DeltaReaderError: A column is unknown or scan planning fails.
Planning may read table metadata before this method returns. If automatic
connection preparation was incomplete, an eligible filtered scan retries
it once, which can add up to five seconds of test reads. Use
`warmup="none"` or `"query_planning"` when opening the table to skip that
check entirely. Errors during result consumption use PyArrow exceptions.
**Filtering rules**
Compare with `==`, `!=`, `<`, `<=`, `>` or `>=`. Use `"is"` or
`"is not"` with `None` to test for nulls; other comparisons with `None`
are invalid. For example, `[("region", "is not", None)]` excludes null
regions. `[[("region", "==", "east")], [("id", "<", 10)]]` selects
rows matching either condition. Filters use top-level logical names.
Deleted rows remain excluded.
Values must match the column type:
| Column type | Python value |
| --- | --- |
| Boolean | `bool` |
| Signed integer | `int` within the column's range |
| Float32, Float64 | Finite `float`; Float32 rounds and rejects overflow |
| Utf8, LargeUtf8 | UTF-8 encodable `str` |
| Binary, LargeBinary, FixedSizeBinary | `bytes`; fixed-size values must match the width |
| Decimal128 | Finite `decimal.Decimal` that exactly fits the precision and scale |
| Date32 | `datetime.date`, excluding `datetime.datetime` |
| Microsecond timestamp | `datetime.datetime`; naive for columns without a timezone, aware otherwise |
Float comparisons distinguish `-0.0` from `0.0`. Decimal conversion is
exact and does not depend on the decimal context. Timestamp conversion
preserves microseconds without using the process timezone. Timestamps
must be exact `datetime.datetime` instances, not subclasses, and UTC
offsets must be exact `datetime.timedelta` instances or `None`."""
...
"""Load the latest snapshot and return it as a new table.
The original table and its readers keep their version, even if refresh
fails. The new table keeps the storage, warmup and execution settings.
Examples:
```python
latest = table.refresh()
print(table.version, latest.version)
```
Returns:
A table at the latest version, which may be the same version as before.
Raises:
DeltaReaderError: The latest snapshot cannot be loaded or prepared."""
...
"""The version loaded by this table. It stays fixed until you open a new table."""
...
"""Column names and types as a `pyarrow.Schema`, without reading data files.
The schema remains usable after the table object is released."""
...
"""Plan a scan and return a single-use Arrow stream exporter.
Use `to_reader()` for a PyArrow reader directly. This lower-level method
is for consumers of the Arrow stream protocol. It accepts the same
parameters and has the same filtering, planning and error behavior as
`to_reader()`.
Examples:
```python
import pyarrow as pa
stream = table.scan(limit=10)
with pa.RecordBatchReader.from_stream(stream) as reader:
print(reader.read_all())
```
Returns:
An exporter that keeps the table snapshot alive. Once exported,
the consuming reader owns cleanup. Close that reader when finished;
closing the exporter does not close the consumer."""
...
"""Export the schema for Arrow-compatible consumers such as `pyarrow.schema()`.
Usually, use the `schema` property instead. Each call returns a fresh
Arrow schema capsule that owns its resources independently of this table."""
...
"""Query Delta tables with SQL and read the results as PyArrow batches.
Register tables you have already opened, then call `sql()`. The package
includes the Rust DataFusion engine; you do not need to install the separate
`datafusion` Python package.
Examples:
```python
from delta_arrow_reader import DeltaTable, Session
table = DeltaTable("path/to/table")
session = Session()
session.register_table("events", table)
with session.sql("SELECT COUNT(*) AS rows FROM events") as reader:
print(reader.read_all().to_pydict())
```
Register more tables to query them together with a JOIN. Only read-only SQL
is supported. Joins, sorts and aggregations can use substantial memory even
when you read their output in batches."""
...
"""Give an opened table a name to use in SQL queries.
Registration reuses the table's prepared file information and connection
measurements. It does not read Parquet data or repeat initialization.
Examples:
```python
session.register_table("latest_events", table.refresh())
```
Args:
name: A simple identifier, such as `events` or `order_items`. Start
with an ASCII letter or underscore, then use ASCII letters, digits
or underscores. SQL keywords and duplicate names are rejected.
table: The loaded `DeltaTable` snapshot to query. Refreshing the
original variable later does not change this registration.
Register the refreshed table under a new name or in a new session.
execution_options: Read settings for this registration. `None` uses
the DataFusion adapter defaults, independently of custom settings
passed to `DeltaTable`. Pass a `ScanExecutionOptions` explicitly
to override them.
Raises:
TypeError: An argument has the wrong type.
DeltaReaderError: Registration fails, including an invalid or duplicate
name. The error has phase `datafusion` and code `sql_registration`.
A duplicate does not replace the existing table."""
...
"""Run a read-only SQL query over registered tables.
This call plans the query. Result execution starts when you request the
first batch. Use a `with` block to release resources if you stop early.
Examples:
For a registered `events` table with a `region` column:
```python
with session.sql(
"SELECT region, COUNT(*) AS rows FROM events GROUP BY region"
) as reader:
for batch in reader:
print(batch.to_pydict())
```
Args:
query: One read-only SQL statement. Table creation, writes, COPY and
session-changing statements are rejected before execution.
Returns:
An independent PyArrow reader. It retains the session and table
snapshots even if those Python variables are deleted.
Raises:
TypeError: The query is not a string.
DeltaReaderError: The query is invalid, unsupported or cannot be
planned, or its schema cannot be exported. Planning failures have
phase `datafusion` and code `sql_planning`.
Execution errors are raised by PyArrow while consuming results, with
`code=sql_execution` in the message. A failed reader remains failed.
SQL error messages omit query text, literal values and table paths."""
...