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
//! Public writer configuration and accounting types.
/// The default maximum number of logical rows buffered into one data block.
pub const DEFAULT_ROW_BLOCK_TARGET: u64 = 65_536;
/// The default maximum estimated raw frame size buffered into one data block.
pub const DEFAULT_BYTE_BLOCK_TARGET: u64 = 64 * 1024 * 1024;
/// The default Zstandard compression level used by [`WriterOptions`].
pub const DEFAULT_ZSTD_LEVEL: i32 = 3;
/// The stream codec selected by a [`crate::Writer`].
/// The block-local min/max statistics policy selected by a [`crate::Writer`].
///
/// Statistics are written only for v0.2 logical types with a fixed canonical
/// representation: booleans, numeric types, decimals, timestamps, dates, and
/// fixed-width binary values. Variable-width strings and binary values have no
/// v0.2 min/max representation and are left without statistics under either
/// enabled policy. `None` is the default and preserves the writer's historical
/// byte output.
///
/// Under both enabled policies nulls and floating-point NaNs are ignored, a
/// column left with no value has no statistic at all, and infinities are
/// ordinary bounds. Floating-point bounds are numeric, so `-0.0` and `0.0` are
/// interchangeable as a bound; the writer keeps whichever bit pattern it saw
/// first, which makes the choice deterministic without claiming that one
/// encoding of zero is smaller than the other.
///
/// A pair costs twice its logical type's canonical width and lives in the data
/// frame header, which readers bound at 64 MiB. A `fixed_binary` column
/// therefore charges twice its byte width against that budget, and a schema
/// wide enough to exhaust it is refused by [`crate::Writer::append`] rather
/// than written; such a schema can still be written with [`Self::None`].
/// A value transform/layout that a writer can apply without profiling.
///
/// Some variants describe a complete column layout rather than one physical
/// stream transform. For example, `Dictionary` uses raw dictionary values and
/// bit-packed indices. Those supporting streams retain the transforms required
/// by the v0.2 layout; the selected variant is the fixed policy for the dense
/// column values.
///
/// Not every variant applies to every logical type, and
/// [`WriterEncoding::Fixed`] documents which set a column offers.
/// The writer-side encoding policy.
///
/// `Raw` is the default and preserves the plain-layout, raw-transform stream
/// choices, so a file written without asking for anything else is byte-for-byte
/// what earlier versions of this writer produced. `Adaptive` profiles each dense
/// stream once and selects a specialized v0.2 layout only after the complete
/// stored representation — every stream, its descriptor, its padding, and its
/// compressed size — beats the raw baseline by at least the larger of 64 bytes
/// or one percent. Selection is deterministic and depends only on the block's
/// values, never on how those rows were divided among [`crate::Writer::append`]
/// calls.
///
/// `Fixed` applies one requested transform or layout to every dense column
/// value stream. It prices nothing and never falls back:
/// [`crate::Writer::create`] returns an error for a transform this writer does
/// not offer for one of the schema's logical types, and a block whose values
/// the transform cannot describe fails when it is published.
///
/// The offered set is exactly the candidate set `Adaptive` would have priced,
/// so a fixed file is always a shape adaptive could also have written. That set
/// is narrower than what the format permits: a `timestamp64` column offers raw,
/// frame of reference, delta, and delta-of-delta and nothing else, so
/// `Fixed(WriterTransform::Dictionary)` is refused for one even though a
/// dictionary `timestamp64` column is a legal v0.2 shape.
///
/// Validity streams stay raw under `Fixed`, because they are independent
/// boolean streams that the requested value transform does not describe.
///
/// `Adaptive` profiling holds the block's dense values a second time while it
/// prices candidates, so it raises peak writer memory by a small multiple of
/// [`WriterOptions::byte_block_target`]. Lower that target to lower the peak.
/// A point-in-time view of writer data accounting.
///
/// Row counts are logical rows. Byte counts are the estimated *raw* serialized
/// data-frame lengths used for bounded buffering, so they are independent of
/// both the selected compression codec and the selected encoding policy: a
/// column that Zstandard or an adaptive transform shrinks is still counted at
/// its raw size. They describe how much the writer is holding and has accepted,
/// not how much it wrote. [`WriteSummary::bytes_written`] is the actual final
/// file length, including the prologue and schema frame.
///
/// Every count here belongs to one writer session. A writer from
/// [`crate::Writer::open`] starts them all at zero, whatever the file already
/// contains.
/// Options for buffered Stage 7 writing.
///
/// Blocks are published when either target is reached, so the buffer holds at
/// most one target's worth of rows and the two targets together bound the
/// writer's memory. A single row whose encoded representation exceeds the byte
/// target is accepted as an unavoidable oversize block; this keeps the buffer
/// bounded for all splittable input while preserving row order. The default
/// codec is raw, so default output remains deterministic and uses the same raw
/// wire representation as the Stage 6 writer.
///
/// This type is `#[non_exhaustive]`, so build it from [`WriterOptions::new`] or
/// [`Default`] and the `with_` methods rather than a struct literal. Later
/// format work can then add an option without breaking callers.
/// The result of a successfully finished writer.
///
/// Row, block, and sequence counts describe *this writer session*. A session
/// from [`crate::Writer::open`] reports only what it appended, so a reopened
/// file's earlier rows and blocks are not counted again.
/// [`Self::bytes_written`] is the exception: it is the length of the whole
/// file, including anything earlier sessions wrote.