parquet_streamer¶
Parquet file streaming reader with lazy column loading.
This module provides :class:ParquetStreamer which reads Parquet files in
batches, optionally prefetching external columns via URLs, and supports
column renaming. Records are yielded one at a time for memory-efficient
iteration over large Parquet datasets.
Example
import os
import tempfile
import pyarrow as pa
import pyarrow.parquet as pq
import py_misc_utils.parquet_streamer as ps
tdir = tempfile.mkdtemp()
path = os.path.join(tdir, 'data.parquet')
pq.write_table(pa.table({'id': [1, 2], 'val': ['one', 'two']}), path)
recs = list(ps.ParquetStreamer(path))
assert recs == [{'id': 1, 'val': 'one'}, {'id': 2, 'val': 'two'}]
ParquetStreamer
¶
Stream records from a Parquet file in batches with optional column loading.
Example
import os
import tempfile
import pyarrow as pa
import pyarrow.parquet as pq
import py_misc_utils.parquet_streamer as ps
tdir = tempfile.mkdtemp()
path = os.path.join(tdir, 'data.parquet')
pq.write_table(pa.table({'id': [1, 2], 'val': ['one', 'two']}), path)
streamer = ps.ParquetStreamer(path, batch_size=1,
rename_columns={'id': 'ident'})
assert list(streamer) == [{'val': 'one', 'ident': 1},
{'val': 'two', 'ident': 2}]
Source code in py_misc_utils/parquet_streamer.py
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 | |
generate()
¶
Yield transformed records from the Parquet file.
Reads the Parquet file in batches, prefetches load_columns via URL fetcher, transforms each record, and yields it. Errors in individual records are logged verbosely and skipped.
Yields:
| Type | Description |
|---|---|
|
Transformed record dictionaries. |
Source code in py_misc_utils/parquet_streamer.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |