fsspec-data 0.7.0__tar.gz → 0.9.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.
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/Cargo.lock +57 -6
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/Cargo.toml +1 -1
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/PKG-INFO +4 -3
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/README.md +3 -2
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/__init__.py +1 -3
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/describe.py +92 -2
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/interchange.py +15 -2
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/test_all.py +17 -0
- fsspec_data-0.9.0/fsspec_data/tests/test_describe.py +423 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/test_schema.py +10 -14
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/test_view.py +70 -2
- fsspec_data-0.9.0/fsspec_data/tests/test_view_conversion.py +164 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/view.py +161 -16
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/pyproject.toml +2 -3
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/Cargo.lock +68 -5
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/Cargo.toml +7 -3
- fsspec_data-0.9.0/rust/coverage +5825 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/python/lib.rs +187 -32
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/codec.rs +567 -12
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/describe.rs +182 -3
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/error.rs +2 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/lib.rs +4 -1
- fsspec_data-0.9.0/rust/src/parquet_range_tests.rs +296 -0
- fsspec_data-0.9.0/rust/src/parquet_ranges.rs +197 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/stream.rs +76 -1
- fsspec_data-0.7.0/fsspec_data/filesystem.py +0 -151
- fsspec_data-0.7.0/fsspec_data/tests/test_describe.py +0 -111
- fsspec_data-0.7.0/fsspec_data/tests/test_filesystem.py +0 -223
- fsspec_data-0.7.0/rust/coverage +0 -4858
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/.gitignore +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/LICENSE +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/_version.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/backends/__init__.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/backends/base.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/backends/http.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/backends/sqlalchemy.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/confluent.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/converters.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/json_schema.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/schema.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/__init__.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/conftest.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/tests/test_converters.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/fsspec_data/xarray_zarr.py +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/.config/nextest.toml +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/avro.rs +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/confluent.rs +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/converter.rs +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/json_schema.rs +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/plan.rs +0 -0
- {fsspec_data-0.7.0 → fsspec_data-0.9.0}/rust/src/schema.rs +0 -0
|
@@ -390,6 +390,15 @@ version = "2.13.2"
|
|
|
390
390
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
391
391
|
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
392
392
|
|
|
393
|
+
[[package]]
|
|
394
|
+
name = "block-buffer"
|
|
395
|
+
version = "0.10.4"
|
|
396
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
397
|
+
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
|
398
|
+
dependencies = [
|
|
399
|
+
"generic-array",
|
|
400
|
+
]
|
|
401
|
+
|
|
393
402
|
[[package]]
|
|
394
403
|
name = "block-buffer"
|
|
395
404
|
version = "0.12.1"
|
|
@@ -463,7 +472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
463
472
|
checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
|
|
464
473
|
dependencies = [
|
|
465
474
|
"cfg-if",
|
|
466
|
-
"cpufeatures",
|
|
475
|
+
"cpufeatures 0.3.1",
|
|
467
476
|
"rand_core",
|
|
468
477
|
]
|
|
469
478
|
|
|
@@ -534,6 +543,15 @@ version = "0.8.7"
|
|
|
534
543
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
535
544
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
|
536
545
|
|
|
546
|
+
[[package]]
|
|
547
|
+
name = "cpufeatures"
|
|
548
|
+
version = "0.2.17"
|
|
549
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
550
|
+
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
|
551
|
+
dependencies = [
|
|
552
|
+
"libc",
|
|
553
|
+
]
|
|
554
|
+
|
|
537
555
|
[[package]]
|
|
538
556
|
name = "cpufeatures"
|
|
539
557
|
version = "0.3.1"
|
|
@@ -629,6 +647,7 @@ version = "0.10.7"
|
|
|
629
647
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
630
648
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
|
631
649
|
dependencies = [
|
|
650
|
+
"block-buffer 0.10.4",
|
|
632
651
|
"crypto-common 0.1.7",
|
|
633
652
|
]
|
|
634
653
|
|
|
@@ -638,7 +657,7 @@ version = "0.11.3"
|
|
|
638
657
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
639
658
|
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
|
640
659
|
dependencies = [
|
|
641
|
-
"block-buffer",
|
|
660
|
+
"block-buffer 0.12.1",
|
|
642
661
|
"crypto-common 0.2.2",
|
|
643
662
|
]
|
|
644
663
|
|
|
@@ -721,12 +740,13 @@ checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
|
|
|
721
740
|
|
|
722
741
|
[[package]]
|
|
723
742
|
name = "fsspec_data"
|
|
724
|
-
version = "0.
|
|
743
|
+
version = "0.9.0"
|
|
725
744
|
dependencies = [
|
|
726
745
|
"arrow",
|
|
727
746
|
"arrow-avro",
|
|
728
747
|
"bytes",
|
|
729
748
|
"fsspec_rs",
|
|
749
|
+
"futures",
|
|
730
750
|
"parquet",
|
|
731
751
|
"serde",
|
|
732
752
|
"serde_json",
|
|
@@ -735,7 +755,7 @@ dependencies = [
|
|
|
735
755
|
|
|
736
756
|
[[package]]
|
|
737
757
|
name = "fsspec_data_py"
|
|
738
|
-
version = "0.
|
|
758
|
+
version = "0.9.0"
|
|
739
759
|
dependencies = [
|
|
740
760
|
"arrow",
|
|
741
761
|
"fsspec_data",
|
|
@@ -744,17 +764,34 @@ dependencies = [
|
|
|
744
764
|
|
|
745
765
|
[[package]]
|
|
746
766
|
name = "fsspec_rs"
|
|
747
|
-
version = "0.
|
|
767
|
+
version = "0.3.0"
|
|
748
768
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
749
|
-
checksum = "
|
|
769
|
+
checksum = "1255e82fe05d791d8c402fbc4e75a25697ff389076e2166720a24c426d81825c"
|
|
750
770
|
dependencies = [
|
|
771
|
+
"async-trait",
|
|
751
772
|
"bytes",
|
|
773
|
+
"futures-util",
|
|
752
774
|
"object_store",
|
|
753
775
|
"percent-encoding",
|
|
776
|
+
"sha2",
|
|
754
777
|
"tokio",
|
|
755
778
|
"url",
|
|
756
779
|
]
|
|
757
780
|
|
|
781
|
+
[[package]]
|
|
782
|
+
name = "futures"
|
|
783
|
+
version = "0.3.34"
|
|
784
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
785
|
+
checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3"
|
|
786
|
+
dependencies = [
|
|
787
|
+
"futures-channel",
|
|
788
|
+
"futures-core",
|
|
789
|
+
"futures-io",
|
|
790
|
+
"futures-sink",
|
|
791
|
+
"futures-task",
|
|
792
|
+
"futures-util",
|
|
793
|
+
]
|
|
794
|
+
|
|
758
795
|
[[package]]
|
|
759
796
|
name = "futures-channel"
|
|
760
797
|
version = "0.3.34"
|
|
@@ -806,6 +843,7 @@ version = "0.3.34"
|
|
|
806
843
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
807
844
|
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
|
808
845
|
dependencies = [
|
|
846
|
+
"futures-channel",
|
|
809
847
|
"futures-core",
|
|
810
848
|
"futures-io",
|
|
811
849
|
"futures-macro",
|
|
@@ -1538,6 +1576,7 @@ dependencies = [
|
|
|
1538
1576
|
"bytes",
|
|
1539
1577
|
"chrono",
|
|
1540
1578
|
"flate2",
|
|
1579
|
+
"futures",
|
|
1541
1580
|
"half",
|
|
1542
1581
|
"hashbrown",
|
|
1543
1582
|
"lz4_flex",
|
|
@@ -1547,6 +1586,7 @@ dependencies = [
|
|
|
1547
1586
|
"seq-macro",
|
|
1548
1587
|
"simdutf8",
|
|
1549
1588
|
"snap",
|
|
1589
|
+
"tokio",
|
|
1550
1590
|
"twox-hash",
|
|
1551
1591
|
"zstd",
|
|
1552
1592
|
]
|
|
@@ -2071,6 +2111,17 @@ dependencies = [
|
|
|
2071
2111
|
"serde",
|
|
2072
2112
|
]
|
|
2073
2113
|
|
|
2114
|
+
[[package]]
|
|
2115
|
+
name = "sha2"
|
|
2116
|
+
version = "0.10.9"
|
|
2117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
2118
|
+
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
|
2119
|
+
dependencies = [
|
|
2120
|
+
"cfg-if",
|
|
2121
|
+
"cpufeatures 0.2.17",
|
|
2122
|
+
"digest 0.10.7",
|
|
2123
|
+
]
|
|
2124
|
+
|
|
2074
2125
|
[[package]]
|
|
2075
2126
|
name = "shlex"
|
|
2076
2127
|
version = "2.0.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: fsspec-data
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Arrow interchange planning for the fsspec data ecosystem
|
|
5
5
|
Project-URL: Repository, https://github.com/1kbgz/fsspec-data
|
|
6
6
|
Project-URL: Homepage, https://github.com/1kbgz/fsspec-data
|
|
@@ -54,8 +54,9 @@ Convert tabular formats and reconcile Arrow schemas over fsspec.
|
|
|
54
54
|
[](https://pypi.python.org/pypi/fsspec-data)
|
|
55
55
|
|
|
56
56
|
`fsspec-data` plans schema mappings and executes them over Arrow record batches.
|
|
57
|
-
Codecs handle Arrow IPC, Parquet, CSV, and JSONL.
|
|
58
|
-
exposes converted files
|
|
57
|
+
Codecs handle Arrow IPC, Parquet, CSV, and JSONL. The `dataview` filesystem
|
|
58
|
+
exposes converted files, schemas, and metadata of any source and passes writes to raw files
|
|
59
|
+
through to it; a separate converter registry handles resources such as
|
|
59
60
|
Xarray datasets and Zarr stores.
|
|
60
61
|
|
|
61
62
|
## Start here
|
|
@@ -8,8 +8,9 @@ Convert tabular formats and reconcile Arrow schemas over fsspec.
|
|
|
8
8
|
[](https://pypi.python.org/pypi/fsspec-data)
|
|
9
9
|
|
|
10
10
|
`fsspec-data` plans schema mappings and executes them over Arrow record batches.
|
|
11
|
-
Codecs handle Arrow IPC, Parquet, CSV, and JSONL.
|
|
12
|
-
exposes converted files
|
|
11
|
+
Codecs handle Arrow IPC, Parquet, CSV, and JSONL. The `dataview` filesystem
|
|
12
|
+
exposes converted files, schemas, and metadata of any source and passes writes to raw files
|
|
13
|
+
through to it; a separate converter registry handles resources such as
|
|
13
14
|
Xarray datasets and Zarr stores.
|
|
14
15
|
|
|
15
16
|
## Start here
|
|
@@ -5,7 +5,6 @@ from .converters import (
|
|
|
5
5
|
ConverterRegistry,
|
|
6
6
|
)
|
|
7
7
|
from .describe import DataSource, Facet, FacetNotSupportedError, FileDataSource, Node
|
|
8
|
-
from .filesystem import DataFileSystem
|
|
9
8
|
from .interchange import (
|
|
10
9
|
DEFAULT_REGISTRY,
|
|
11
10
|
Codec,
|
|
@@ -35,7 +34,7 @@ from .schema import (
|
|
|
35
34
|
)
|
|
36
35
|
from .view import DEFAULT_MAPPING, DataViewFileSystem, ViewEntry
|
|
37
36
|
|
|
38
|
-
__version__ = "0.
|
|
37
|
+
__version__ = "0.9.0"
|
|
39
38
|
|
|
40
39
|
__all__ = [
|
|
41
40
|
"CONVERTER_ENTRY_POINT_GROUP",
|
|
@@ -48,7 +47,6 @@ __all__ = [
|
|
|
48
47
|
"CodecRegistry",
|
|
49
48
|
"Converter",
|
|
50
49
|
"ConverterRegistry",
|
|
51
|
-
"DataFileSystem",
|
|
52
50
|
"DataFormat",
|
|
53
51
|
"DataSource",
|
|
54
52
|
"DataViewFileSystem",
|
|
@@ -7,7 +7,7 @@ facets as files; the backend never knows which forms are requested.
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
-
from collections.abc import Iterable
|
|
10
|
+
from collections.abc import Iterable, Sequence
|
|
11
11
|
from dataclasses import dataclass
|
|
12
12
|
from enum import Enum
|
|
13
13
|
from typing import Any, BinaryIO
|
|
@@ -15,7 +15,7 @@ from typing import Any, BinaryIO
|
|
|
15
15
|
import pyarrow as pa
|
|
16
16
|
from fsspec import AbstractFileSystem
|
|
17
17
|
|
|
18
|
-
from .interchange import DEFAULT_REGISTRY, DataFormat, DecodedBatchStream
|
|
18
|
+
from .interchange import DEFAULT_REGISTRY, DataFormat, DecodedBatchStream, _rust
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class Facet(str, Enum):
|
|
@@ -78,6 +78,50 @@ class DataSource:
|
|
|
78
78
|
) -> DecodedBatchStream:
|
|
79
79
|
raise FacetNotSupportedError(path, Facet.TABLE)
|
|
80
80
|
|
|
81
|
+
def scan_columns(
|
|
82
|
+
self,
|
|
83
|
+
path: str,
|
|
84
|
+
columns: Sequence[str],
|
|
85
|
+
*,
|
|
86
|
+
batch_size: int = 1024,
|
|
87
|
+
row_limit: int | None = None,
|
|
88
|
+
byte_limit: int | None = None,
|
|
89
|
+
) -> DecodedBatchStream:
|
|
90
|
+
"""Scan top-level columns in requested order, preserving duplicates and row counts.
|
|
91
|
+
|
|
92
|
+
Existing backends use batch projection. Output limits apply after projection.
|
|
93
|
+
"""
|
|
94
|
+
source = self.scan(path, batch_size=batch_size, row_limit=row_limit, byte_limit=None)
|
|
95
|
+
schema = getattr(source, "schema", None)
|
|
96
|
+
if schema is None:
|
|
97
|
+
schema = self.schema(path)
|
|
98
|
+
schema, native = _rust.project_batches(schema, iter(source), columns, batch_size, row_limit, byte_limit)
|
|
99
|
+
return DecodedBatchStream(schema, native, on_cancel=getattr(source, "cancel", None))
|
|
100
|
+
|
|
101
|
+
def scan_selected(
|
|
102
|
+
self,
|
|
103
|
+
path: str,
|
|
104
|
+
*,
|
|
105
|
+
columns: Sequence[str] | None = None,
|
|
106
|
+
row_offset: int = 0,
|
|
107
|
+
batch_size: int = 1024,
|
|
108
|
+
row_limit: int | None = None,
|
|
109
|
+
byte_limit: int | None = None,
|
|
110
|
+
) -> DecodedBatchStream:
|
|
111
|
+
"""Select columns and skip source rows before enforcing output limits."""
|
|
112
|
+
if row_offset < 0:
|
|
113
|
+
raise ValueError("row_offset must be nonnegative")
|
|
114
|
+
source_limit = row_limit if row_offset == 0 else None
|
|
115
|
+
if columns is None:
|
|
116
|
+
source = self.scan(path, batch_size=batch_size, row_limit=source_limit, byte_limit=None)
|
|
117
|
+
else:
|
|
118
|
+
source = self.scan_columns(path, columns, batch_size=batch_size, row_limit=source_limit, byte_limit=None)
|
|
119
|
+
schema = getattr(source, "schema", None)
|
|
120
|
+
if schema is None:
|
|
121
|
+
schema = self.schema(path)
|
|
122
|
+
schema, native = _rust.project_batches(schema, iter(source), None, batch_size, row_limit, byte_limit, row_offset)
|
|
123
|
+
return DecodedBatchStream(schema, native, on_cancel=getattr(source, "cancel", None))
|
|
124
|
+
|
|
81
125
|
def open_raw(self, path: str) -> BinaryIO:
|
|
82
126
|
raise FacetNotSupportedError(path, Facet.RAW)
|
|
83
127
|
|
|
@@ -136,12 +180,58 @@ class FileDataSource(DataSource):
|
|
|
136
180
|
batch_size: int = 1024,
|
|
137
181
|
row_limit: int | None = None,
|
|
138
182
|
byte_limit: int | None = None,
|
|
183
|
+
) -> DecodedBatchStream:
|
|
184
|
+
return self.scan_selected(path, batch_size=batch_size, row_limit=row_limit, byte_limit=byte_limit)
|
|
185
|
+
|
|
186
|
+
def scan_columns(
|
|
187
|
+
self,
|
|
188
|
+
path: str,
|
|
189
|
+
columns: Sequence[str],
|
|
190
|
+
*,
|
|
191
|
+
batch_size: int = 1024,
|
|
192
|
+
row_limit: int | None = None,
|
|
193
|
+
byte_limit: int | None = None,
|
|
194
|
+
) -> DecodedBatchStream:
|
|
195
|
+
return self.scan_selected(path, columns=columns, batch_size=batch_size, row_limit=row_limit, byte_limit=byte_limit)
|
|
196
|
+
|
|
197
|
+
def scan_selected(
|
|
198
|
+
self,
|
|
199
|
+
path: str,
|
|
200
|
+
*,
|
|
201
|
+
columns: Sequence[str] | None = None,
|
|
202
|
+
row_offset: int = 0,
|
|
203
|
+
batch_size: int = 1024,
|
|
204
|
+
row_limit: int | None = None,
|
|
205
|
+
byte_limit: int | None = None,
|
|
139
206
|
) -> DecodedBatchStream:
|
|
140
207
|
format = self._table_format(path)
|
|
208
|
+
if format == DataFormat.PARQUET:
|
|
209
|
+
condition = None
|
|
210
|
+
first_read = True
|
|
211
|
+
|
|
212
|
+
def fetch(ranges):
|
|
213
|
+
nonlocal condition, first_read
|
|
214
|
+
if hasattr(self.fs, "read_ranges"):
|
|
215
|
+
result = self.fs.read_ranges(path, ranges, condition=condition)
|
|
216
|
+
if first_read:
|
|
217
|
+
if result.validator is not None:
|
|
218
|
+
from fsspec_rs import Match
|
|
219
|
+
|
|
220
|
+
condition = Match(result.validator)
|
|
221
|
+
first_read = False
|
|
222
|
+
return result.data
|
|
223
|
+
starts, ends = zip(*ranges) if ranges else ([], [])
|
|
224
|
+
return self.fs.cat_ranges([path] * len(ranges), list(starts), list(ends), on_error="raise")
|
|
225
|
+
|
|
226
|
+
schema, native = _rust.decode_parquet_ranges(fetch, batch_size, row_limit, byte_limit, columns, row_offset)
|
|
227
|
+
return DecodedBatchStream(schema, native)
|
|
228
|
+
|
|
141
229
|
schema = self._decode_schema(path, format)
|
|
142
230
|
return DEFAULT_REGISTRY.get(format).iter_batches(
|
|
143
231
|
self.open_raw(path),
|
|
144
232
|
schema=schema,
|
|
233
|
+
columns=columns,
|
|
234
|
+
row_offset=row_offset,
|
|
145
235
|
batch_size=batch_size,
|
|
146
236
|
row_limit=row_limit,
|
|
147
237
|
byte_limit=byte_limit,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from collections.abc import Iterable, Mapping, Sequence
|
|
3
|
+
from collections.abc import Callable, Iterable, Mapping, Sequence
|
|
4
4
|
from dataclasses import dataclass, replace
|
|
5
5
|
from enum import Enum
|
|
6
6
|
from importlib import import_module
|
|
@@ -64,9 +64,10 @@ class DecodedBatches:
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
class DecodedBatchStream:
|
|
67
|
-
def __init__(self, schema: pa.Schema, native: Any) -> None:
|
|
67
|
+
def __init__(self, schema: pa.Schema, native: Any, *, on_cancel: Callable[[], None] | None = None) -> None:
|
|
68
68
|
self.schema = schema
|
|
69
69
|
self._native = native
|
|
70
|
+
self._on_cancel = on_cancel
|
|
70
71
|
|
|
71
72
|
def __iter__(self) -> DecodedBatchStream:
|
|
72
73
|
return self
|
|
@@ -76,6 +77,8 @@ class DecodedBatchStream:
|
|
|
76
77
|
|
|
77
78
|
def cancel(self) -> None:
|
|
78
79
|
self._native.cancel()
|
|
80
|
+
if self._on_cancel is not None:
|
|
81
|
+
self._on_cancel()
|
|
79
82
|
|
|
80
83
|
def collect(self) -> DecodedBatches:
|
|
81
84
|
return DecodedBatches(self.schema, tuple(self))
|
|
@@ -164,6 +167,8 @@ class Codec:
|
|
|
164
167
|
batch_size: int = 1024,
|
|
165
168
|
row_limit: int | None = None,
|
|
166
169
|
byte_limit: int | None = None,
|
|
170
|
+
columns: Sequence[str] | None = None,
|
|
171
|
+
row_offset: int = 0,
|
|
167
172
|
) -> DecodedBatches:
|
|
168
173
|
return self.iter_batches(
|
|
169
174
|
data,
|
|
@@ -171,6 +176,8 @@ class Codec:
|
|
|
171
176
|
batch_size=batch_size,
|
|
172
177
|
row_limit=row_limit,
|
|
173
178
|
byte_limit=byte_limit,
|
|
179
|
+
columns=columns,
|
|
180
|
+
row_offset=row_offset,
|
|
174
181
|
).collect()
|
|
175
182
|
|
|
176
183
|
def iter_batches(
|
|
@@ -181,6 +188,8 @@ class Codec:
|
|
|
181
188
|
batch_size: int = 1024,
|
|
182
189
|
row_limit: int | None = None,
|
|
183
190
|
byte_limit: int | None = None,
|
|
191
|
+
columns: Sequence[str] | None = None,
|
|
192
|
+
row_offset: int = 0,
|
|
184
193
|
) -> DecodedBatchStream:
|
|
185
194
|
if schema is not None:
|
|
186
195
|
schema = _ensure_pyarrow(schema)
|
|
@@ -192,6 +201,8 @@ class Codec:
|
|
|
192
201
|
batch_size,
|
|
193
202
|
row_limit,
|
|
194
203
|
byte_limit,
|
|
204
|
+
columns,
|
|
205
|
+
row_offset,
|
|
195
206
|
)
|
|
196
207
|
elif hasattr(data, "read"):
|
|
197
208
|
decoded_schema, native = _rust.decode_reader(
|
|
@@ -201,6 +212,8 @@ class Codec:
|
|
|
201
212
|
batch_size,
|
|
202
213
|
row_limit,
|
|
203
214
|
byte_limit,
|
|
215
|
+
columns,
|
|
216
|
+
row_offset,
|
|
204
217
|
)
|
|
205
218
|
else:
|
|
206
219
|
raise TypeError("data must be bytes-like or a binary file-like object")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import threading
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
4
5
|
import pyarrow as pa
|
|
@@ -401,6 +402,22 @@ def test_lazy_decode_observes_cancellation():
|
|
|
401
402
|
next(stream)
|
|
402
403
|
|
|
403
404
|
|
|
405
|
+
def test_streams_can_be_read_from_any_thread():
|
|
406
|
+
codec = DEFAULT_REGISTRY.get(DataFormat.CSV)
|
|
407
|
+
source = io.BytesIO(b"id\n1\n2\n3\n")
|
|
408
|
+
stream = codec.iter_batches(source, schema=pa.schema([("id", pa.int64())]), batch_size=1)
|
|
409
|
+
batches = [next(stream)]
|
|
410
|
+
|
|
411
|
+
def read_rest():
|
|
412
|
+
batches.extend(stream)
|
|
413
|
+
stream.cancel()
|
|
414
|
+
|
|
415
|
+
worker = threading.Thread(target=read_rest)
|
|
416
|
+
worker.start()
|
|
417
|
+
worker.join()
|
|
418
|
+
assert [batch.column(0).to_pylist() for batch in batches] == [[1], [2], [3]]
|
|
419
|
+
|
|
420
|
+
|
|
404
421
|
def test_lazy_decode_enforces_byte_limit():
|
|
405
422
|
schema = pa.schema([("id", pa.int64())])
|
|
406
423
|
codec = DEFAULT_REGISTRY.get(DataFormat.ARROW)
|