@konstit/csv 0.4.1 → 0.5.0

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.
Files changed (65) hide show
  1. package/README.md +152 -463
  2. package/THIRD_PARTY_NOTICES.md +7 -1
  3. package/dist/api.d.ts +169 -44
  4. package/dist/api.js +75 -368
  5. package/dist/batches.d.ts +250 -7
  6. package/dist/batches.js +135 -83
  7. package/dist/cli-command.d.ts +7 -0
  8. package/dist/cli-command.js +350 -0
  9. package/dist/cli-schema.d.ts +111 -0
  10. package/dist/cli-schema.js +219 -0
  11. package/dist/cli.js +2 -604
  12. package/dist/file-stream.d.ts +57 -2
  13. package/dist/file-stream.js +244 -36
  14. package/dist/files.d.ts +149 -3
  15. package/dist/files.js +37 -29
  16. package/dist/filter.d.ts +80 -0
  17. package/dist/format-bytes.d.ts +1 -0
  18. package/dist/format-bytes.js +11 -0
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +2 -14
  21. package/dist/inspect-file.d.ts +12 -0
  22. package/dist/inspect-file.js +88 -0
  23. package/dist/latin1-rows.d.ts +5 -0
  24. package/dist/latin1-rows.js +122 -0
  25. package/dist/materialize-field.d.ts +3 -0
  26. package/dist/materialize-field.js +31 -0
  27. package/dist/native.d.ts +51 -2
  28. package/dist/native.js +43 -4
  29. package/dist/normalize.d.ts +32 -2
  30. package/dist/normalize.js +51 -2
  31. package/dist/options-snapshot.d.ts +3 -0
  32. package/dist/options-snapshot.js +51 -0
  33. package/dist/options.d.ts +25 -10
  34. package/dist/options.js +0 -6
  35. package/dist/parser.d.ts +309 -4
  36. package/dist/parser.js +128 -31
  37. package/dist/strict-schema.d.ts +5 -3
  38. package/dist/strict-schema.js +4 -1
  39. package/dist/types.d.ts +355 -121
  40. package/dist/zip-reader.d.ts +11 -1
  41. package/dist/zip-reader.js +12 -3
  42. package/package.json +44 -29
  43. package/prebuilds/darwin-arm64/libcsv_native.dylib +0 -0
  44. package/prebuilds/darwin-x64/libcsv_native.dylib +0 -0
  45. package/prebuilds/linux-x64/libcsv_native.so +0 -0
  46. package/prebuilds/manifest.json +9 -8
  47. package/prebuilds/provenance/darwin-arm64.json +1 -1
  48. package/prebuilds/provenance/darwin-x64.json +1 -1
  49. package/prebuilds/provenance/linux-x64.json +1 -1
  50. package/dist/worker-count.d.ts +0 -2
  51. package/dist/worker-count.js +0 -96
  52. package/dist/worker-factory.d.ts +0 -3
  53. package/dist/worker-factory.js +0 -9
  54. package/dist/worker-filter.d.ts +0 -29
  55. package/dist/worker-filter.js +0 -46
  56. package/dist/worker-module.d.ts +0 -1
  57. package/dist/worker-module.js +0 -4
  58. package/dist/worker-pool.d.ts +0 -17
  59. package/dist/worker-pool.js +0 -290
  60. package/dist/worker-rows.d.ts +0 -8
  61. package/dist/worker-rows.js +0 -118
  62. package/dist/workers/count.worker.d.ts +0 -1
  63. package/dist/workers/count.worker.js +0 -49
  64. package/dist/workers/rows.worker.d.ts +0 -1
  65. package/dist/workers/rows.worker.js +0 -85
package/dist/api.js CHANGED
@@ -1,4 +1,3 @@
1
- import { NativeCsvRowView } from "./batches.js";
2
1
  import {
3
2
  prepareCsvFileInput,
4
3
  rejectAutoDelimiterSharding,
@@ -16,58 +15,66 @@ import {
16
15
  not,
17
16
  re
18
17
  } from "./filter.js";
19
- import { normalizeColumns } from "./normalize.js";
20
- import { NativeCsvParser } from "./parser.js";
18
+ import { latin1Rows } from "./latin1-rows.js";
19
+ import { latin1RowsParser } from "./native.js";
20
+ import {
21
+ normalizeFixedColumnsCount,
22
+ prepareCsvBufferInput,
23
+ resolveInputEncoding
24
+ } from "./normalize.js";
25
+ import { snapshotCsvOptions } from "./options-snapshot.js";
26
+ import { createPreparedParser } from "./parser.js";
21
27
  import {
22
28
  rejectStrictSchemaUnsupported,
23
29
  strictSchemaValidator
24
30
  } from "./strict-schema.js";
25
- import { parallelCount } from "./worker-count.js";
26
- import {
27
- createWorkerPool,
28
- CsvWorkerPool
29
- } from "./worker-pool.js";
30
- import { parallelRows } from "./worker-rows.js";
31
- export async function parse(buffer, options = {}) {
31
+ export async function parse(buffer, suppliedOptions = {}) {
32
+ const options = snapshotCsvOptions(suppliedOptions);
32
33
  if ("compression" in options && options.compression !== void 0)
33
34
  throw Error("parse() does not support compression; pass decompressed bytes or use a file API");
34
35
  if (options.delimiter === "auto")
35
36
  throw Error("parse() does not support automatic delimiter detection; specify delimiter or use a file API");
36
37
  rejectFilteredStrictSchema(options);
37
38
  const filters = toNativeFilters(options.where);
38
- const parser = new NativeCsvParser(toParserOptions(options));
39
+ const columns = options.columns;
40
+ const projected = filters !== void 0 || options.strict !== !0 && columns !== void 0;
41
+ const input = prepareCsvBufferInput(buffer, options.encoding, options.delimiter);
42
+ using parser = createPreparedParser(toParserOptions(options, input.parserEncoding), projected ? columns : void 0, filters);
39
43
  const validator = strictSchemaValidator(options);
44
+ const batch = parser.writeBatch(input.bytes, !0);
40
45
  try {
41
- const batch = writeMaterializeBatch(parser, buffer, options, filters, !0);
42
- try {
43
- validator?.validateBatch(batch);
44
- validator?.finish();
45
- return materializeRows(batch, options);
46
- } finally {
47
- batch.close();
48
- }
46
+ validator?.validateBatch(batch);
47
+ validator?.finish();
48
+ return materializeRows(batch, columns, projected);
49
49
  } finally {
50
- parser.close();
50
+ batch.close();
51
51
  }
52
52
  }
53
- export async function* rows(path, options = {}) {
54
- if ((options.workerCount ?? 1) > 1) {
55
- rejectCompressedSharding(options, "parallel row parsing");
56
- rejectAutoDelimiterSharding(options, "parallel row parsing");
57
- yield* parallelRows(path, options);
58
- return;
59
- }
53
+ export function rows(path, options = {}) {
54
+ return iterateRows(path, snapshotCsvOptions(options));
55
+ }
56
+ export async function* iterateRows(path, options, probeFormat) {
60
57
  rejectFilteredStrictSchema(options);
61
58
  const filters = toNativeFilters(options.where);
62
- await using input = await prepareCsvFileInput(path, options);
63
- using parser = new NativeCsvParser(toParserOptions(options, input.delimiter));
59
+ const columns = options.columns;
60
+ const projected = filters !== void 0 || options.strict !== !0 && columns !== void 0;
61
+ await using input = await prepareCsvFileInput(path, options, "read-ahead", probeFormat);
62
+ const parserOptions = toParserOptions(options, input.parserEncoding, input.delimiter);
64
63
  const validator = strictSchemaValidator(options);
64
+ const reusableRows = options.reuseArrays === !0 ? [] : void 0;
65
+ if (options.strict !== !0 && validator === void 0 && input.parserEncoding === "latin1") {
66
+ const fixedColumns = normalizeFixedColumnsCount(options.fixedColumns, "fixed column count");
67
+ const createParser = latin1RowsParser(fixedColumns);
68
+ yield* latin1Rows(input.chunks(), input.delimiter, columns, filters, createParser, reusableRows);
69
+ return;
70
+ }
71
+ using parser = createPreparedParser(parserOptions, projected ? columns : void 0, filters);
65
72
  for await (const chunk of input.chunks()) {
66
- const batch = writeMaterializeBatch(parser, chunk, options, filters);
73
+ const batch = parser.writeBatch(chunk);
67
74
  if (batch.rowCount > 0)
68
75
  try {
69
76
  validator?.validateBatch(batch);
70
- const values = materializeRows(batch, options);
77
+ const values = materializeRows(batch, columns, projected, reusableRows);
71
78
  if (values.length > 0)
72
79
  yield values;
73
80
  } finally {
@@ -76,12 +83,12 @@ export async function* rows(path, options = {}) {
76
83
  else
77
84
  batch.close();
78
85
  }
79
- const batch = finishMaterializeBatch(parser, options, filters);
86
+ const batch = parser.endBatch();
80
87
  if (batch.rowCount > 0)
81
88
  try {
82
89
  validator?.validateBatch(batch);
83
90
  validator?.finish();
84
- const values = materializeRows(batch, options);
91
+ const values = materializeRows(batch, columns, projected, reusableRows);
85
92
  if (values.length > 0)
86
93
  yield values;
87
94
  } finally {
@@ -92,17 +99,20 @@ export async function* rows(path, options = {}) {
92
99
  batch.close();
93
100
  }
94
101
  }
95
-
96
- export { parallelRows };
97
- export { CsvWorkerPool };
98
- export async function* batches(path, options = {}) {
102
+ export function batches(path, options = {}) {
103
+ return iterateBatches(path, snapshotCsvOptions(options));
104
+ }
105
+ async function* iterateBatches(path, options) {
99
106
  rejectFilteredStrictSchema(options);
100
107
  const filters = toNativeFilters(options.where);
108
+ const columns = options.columns;
109
+ if (options.strict === !0 && columns !== void 0)
110
+ throw Error("strict CSV validation is not supported for projected batches; use csv.rows() for strict projection");
101
111
  await using input = await prepareCsvFileInput(path, options);
102
- using parser = new NativeCsvParser(toParserOptions(options, input.delimiter));
112
+ using parser = createPreparedParser(toParserOptions(options, input.parserEncoding, input.delimiter), columns, filters);
103
113
  const validator = strictSchemaValidator(options);
104
114
  for await (const chunk of input.chunks()) {
105
- const batch = writeRowsBatch(parser, chunk, options, filters);
115
+ const batch = parser.writeBatch(chunk);
106
116
  if (batch.rowCount > 0) {
107
117
  try {
108
118
  validator?.validateBatch(batch);
@@ -114,7 +124,7 @@ export async function* batches(path, options = {}) {
114
124
  } else
115
125
  batch.close();
116
126
  }
117
- const batch = finishRowsBatch(parser, options, filters);
127
+ const batch = parser.endBatch();
118
128
  if (batch.rowCount > 0) {
119
129
  try {
120
130
  validator?.validateBatch(batch);
@@ -125,105 +135,17 @@ export async function* batches(path, options = {}) {
125
135
  }
126
136
  yield batch;
127
137
  } else {
128
- validator?.finish();
129
138
  batch.close();
130
- }
131
- }
132
- export async function withBatches(path, options, callback) {
133
- for await (const batch of batches(path, options))
134
- try {
135
- await callback(batch);
136
- } finally {
137
- batch.close();
138
- }
139
- }
140
- export async function forEachColumnarBatches(path, options = {}, callback) {
141
- ensureColumnarBatchesSupported(options);
142
- const filters = toNativeFilters(options.where);
143
- const scopedBatch = new ScopedCsvColumnarBatchView(selectedColumns(options));
144
- let batchIndex = 0;
145
- await using input = await prepareCsvFileInput(path, options);
146
- using parser = new NativeCsvParser(toParserOptions(options, input.delimiter));
147
- const validator = strictSchemaValidator(options);
148
- for await (const chunk of input.chunks()) {
149
- const batch = writeColumnarBatch(parser, chunk, options, filters);
150
- if (batch.rowCount > 0)
151
- try {
152
- validator?.validateBatch(batch);
153
- scopedBatch.bind(batch);
154
- try {
155
- const result = callback(scopedBatch, batchIndex);
156
- if (isPromiseLike(result))
157
- throw TypeError("columnar batch callback must be synchronous");
158
- } finally {
159
- scopedBatch.release();
160
- }
161
- ++batchIndex;
162
- } finally {
163
- batch.close();
164
- }
165
- else
166
- batch.close();
167
- }
168
- const batch = finishColumnarBatch(parser, options, filters);
169
- if (batch.rowCount > 0)
170
- try {
171
- validator?.validateBatch(batch);
172
- validator?.finish();
173
- scopedBatch.bind(batch);
174
- try {
175
- const result = callback(scopedBatch, batchIndex);
176
- if (isPromiseLike(result))
177
- throw TypeError("columnar batch callback must be synchronous");
178
- } finally {
179
- scopedBatch.release();
180
- }
181
- } finally {
182
- batch.close();
183
- }
184
- else {
185
139
  validator?.finish();
186
- batch.close();
187
140
  }
188
141
  }
189
- export function withColumnarBatches(path, options, callback) {
190
- return forEachColumnarBatches(path, options, callback);
191
- }
192
- export async function forEachRowViews(path, options = {}, callback) {
193
- ensureRowViewsSupported(options);
194
- const scopedRowView = new ScopedCsvRowView(selectedColumns(options));
195
- for await (const batch of batches(path, options))
196
- try {
197
- const rowCount = batch.rowCount;
198
- if (rowCount === 0)
199
- continue;
200
- const reusable = new NativeCsvRowView(batch.data(), batch.rowOffsets(), batch.fieldOffsets());
201
- for (let rowIndex = 0;rowIndex < rowCount; ++rowIndex) {
202
- scopedRowView.bind(reusable.moveTo(rowIndex));
203
- try {
204
- const result = callback(scopedRowView, rowIndex);
205
- if (isPromiseLike(result))
206
- throw TypeError("row view callback must be synchronous");
207
- } finally {
208
- scopedRowView.release();
209
- }
210
- }
211
- } finally {
212
- batch.close();
213
- }
214
- }
215
- export function withRowViews(path, options, callback) {
216
- return forEachRowViews(path, options, callback);
217
- }
218
- export async function count(path, options = {}) {
219
- if ((options.workerCount ?? 1) > 1) {
220
- rejectCompressedSharding(options, "parallel counting");
221
- rejectAutoDelimiterSharding(options, "parallel counting");
222
- return parallelCount(path, options);
223
- }
142
+ export async function count(path, suppliedOptions = {}) {
143
+ const options = snapshotCsvOptions(suppliedOptions);
224
144
  const filters = toNativeFilters(options.where);
225
- await using input = await prepareCsvFileInput(path, options);
226
- using parser = new NativeCsvParser(toParserOptions(options, input.delimiter));
145
+ await using input = await prepareCsvFileInput(path, options, "count");
146
+ if (options.strict === !0 && filters !== void 0)
147
+ throw Error("strict CSV validation is not supported for count filters");
148
+ using parser = createPreparedParser(toParserOptions(options, input.parserEncoding, input.delimiter), void 0, filters);
227
149
  const validator = strictSchemaValidator(options);
228
150
  let total = 0;
229
151
  if (options.strict === !0 && filters === void 0) {
@@ -247,24 +169,24 @@ export async function count(path, options = {}) {
247
169
  return total;
248
170
  }
249
171
  for await (const chunk of input.chunks())
250
- total += writeCount(parser, chunk, filters);
251
- total += finishCount(parser, filters);
172
+ total += parser.writeCount(chunk);
173
+ total += parser.endCount();
252
174
  return total;
253
175
  }
254
-
255
- export { parallelCount };
256
- export function findCsvSafeSplitOffsets(path, shardCount, options = {}) {
257
- rejectCompressedSharding(options, "CSV split offset scanning");
258
- rejectAutoDelimiterSharding(options, "CSV split offset scanning");
259
- return findCsvSafeSplitOffsetsNative(path, shardCount, options.delimiter ?? ",");
176
+ function findCsvSafeSplitOffsets(path, shardCount, suppliedOptions = {}) {
177
+ const options = snapshotCsvOptions(suppliedOptions);
178
+ return findCsvSafeSplitOffsetsNative(path, shardCount, shardingDelimiter(options, "CSV split offset scanning"));
260
179
  }
261
- export function findCsvSafeShards(path, shardCount, options = {}) {
262
- rejectCompressedSharding(options, "CSV shard scanning");
263
- rejectAutoDelimiterSharding(options, "CSV shard scanning");
264
- return findCsvSafeShardsNative(path, shardCount, options.delimiter ?? ",");
180
+ function findCsvSafeShards(path, shardCount, suppliedOptions = {}) {
181
+ const options = snapshotCsvOptions(suppliedOptions);
182
+ return findCsvSafeShardsNative(path, shardCount, shardingDelimiter(options, "CSV shard scanning"));
265
183
  }
266
- export function workerPool(path, options) {
267
- return createWorkerPool(path, options);
184
+ function shardingDelimiter(options, operation) {
185
+ rejectCompressedSharding(options, operation);
186
+ rejectAutoDelimiterSharding(options, operation);
187
+ if (typeof resolveInputEncoding(options.encoding) !== "string")
188
+ throw Error(`${operation} requires a native UTF-8 or Latin-1 encoding because offsets refer to the source file`);
189
+ return options.delimiter ?? ",";
268
190
  }
269
191
  export const csv = {
270
192
  all,
@@ -272,244 +194,29 @@ export const csv = {
272
194
  column,
273
195
  not,
274
196
  re,
275
- workerPool,
276
197
  parse,
277
198
  rows,
278
- parallelCount,
279
- parallelRows,
280
199
  batches,
281
- withBatches,
282
- forEachColumnarBatches,
283
- withColumnarBatches,
284
- forEachRowViews,
285
- withRowViews,
286
200
  count,
287
201
  findCsvSafeSplitOffsets,
288
202
  findCsvSafeShards
289
203
  };
290
- function toParserOptions(options, delimiter = options.delimiter) {
291
- const selectedColumns = "columns" in options && options.columns !== void 0 ? options.columns : options.selectedColumns;
292
- if ("columns" in options && options.columns !== void 0 && options.selectedColumns !== void 0)
293
- throw Error("use columns or selectedColumns, not both");
204
+ function toParserOptions(options, encoding, delimiter = options.delimiter) {
294
205
  return {
295
206
  delimiter,
296
- encoding: options.encoding,
207
+ encoding,
297
208
  strict: options.strict,
298
- selectedColumns,
209
+ columns: options.columns,
299
210
  fixedColumns: options.fixedColumns
300
211
  };
301
212
  }
302
- function selectedColumns(options) {
303
- if (options.columns !== void 0 && options.selectedColumns !== void 0)
304
- throw Error("use columns or selectedColumns, not both");
305
- const columns = options.columns ?? options.selectedColumns;
306
- normalizeColumns(columns);
307
- return columns;
308
- }
309
- function materializeRows(batch, options) {
310
- const columns = selectedColumns(options);
311
- if (usesProjectedMaterialization(options))
312
- return batch.rowsInto([]);
313
- return batch.rowsInto([], columns);
314
- }
315
- function usesProjectedMaterialization(options) {
316
- return options.where !== void 0 || options.strict !== !0 && selectedColumns(options) !== void 0;
317
- }
318
- function writeRowsBatch(parser, chunk, options, filters, final = !1) {
319
- if (filters !== void 0)
320
- return parser.writeProjectedBatchWhere(chunk, selectedColumns(options), filters, final);
321
- return parser.writeBatch(chunk, final);
322
- }
323
- function writeMaterializeBatch(parser, chunk, options, filters, final = !1) {
324
- const columns = selectedColumns(options);
325
- if (filters !== void 0)
326
- return parser.writeProjectedBatchWhere(chunk, columns, filters, final);
327
- if (options.strict !== !0 && columns !== void 0)
328
- return parser.writeProjectedBatch(chunk, { selectedColumns: columns }, final);
329
- return parser.writeBatch(chunk, final);
330
- }
331
- function writeColumnarBatch(parser, chunk, options, filters, final = !1) {
332
- const columns = selectedColumns(options);
333
- if (filters !== void 0)
334
- return parser.writeProjectedBatchWhere(chunk, columns, filters, final);
335
- if (columns !== void 0)
336
- return parser.writeProjectedBatch(chunk, { selectedColumns: columns }, final);
337
- return parser.writeBatch(chunk, final);
338
- }
339
- function finishRowsBatch(parser, options, filters) {
340
- if (filters !== void 0)
341
- return parser.endProjectedBatchWhere(selectedColumns(options), filters);
342
- return parser.endBatch();
343
- }
344
- function finishMaterializeBatch(parser, options, filters) {
345
- const columns = selectedColumns(options);
346
- if (filters !== void 0)
347
- return parser.endProjectedBatchWhere(columns, filters);
348
- if (options.strict !== !0 && columns !== void 0)
349
- return parser.endProjectedBatch({ selectedColumns: columns });
350
- return parser.endBatch();
351
- }
352
- function finishColumnarBatch(parser, options, filters) {
353
- const columns = selectedColumns(options);
354
- if (filters !== void 0)
355
- return parser.endProjectedBatchWhere(columns, filters);
356
- if (columns !== void 0)
357
- return parser.endProjectedBatch({ selectedColumns: columns });
358
- return parser.endBatch();
359
- }
360
- function ensureRowViewsSupported(options) {
361
- if ((options.workerCount ?? 1) > 1)
362
- throw Error("row view callbacks do not support workerCount; use rows()/parallelRows() for materialized rows or withBatches() for low-level streaming");
363
- }
364
- function ensureColumnarBatchesSupported(options) {
365
- ensureRowViewsSupported(options);
366
- if (options.strict === !0 && selectedColumns(options) !== void 0)
367
- throw Error("columnar batch callbacks do not support strict selectedColumns; use rows() for projected validation or withBatches() for manual low-level handling");
213
+ function materializeRows(batch, columns, projected, target = []) {
214
+ return batch.rowsInto(target, projected ? void 0 : columns);
368
215
  }
369
216
  function rejectFilteredStrictSchema(options) {
370
217
  if (options.where !== void 0)
371
218
  rejectStrictSchemaUnsupported(options, "filtered rows");
372
219
  }
373
- function isPromiseLike(value) {
374
- return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
375
- }
376
-
377
- class ScopedCsvRowView {
378
- #selectedColumns;
379
- #rowView = null;
380
- constructor(selectedColumns) {
381
- this.#selectedColumns = selectedColumns;
382
- }
383
- bind(rowView) {
384
- this.#rowView = rowView;
385
- return this;
386
- }
387
- release() {
388
- this.#rowView = null;
389
- }
390
- get rowIndex() {
391
- return this.#requireRowView().rowIndex;
392
- }
393
- get fieldCount() {
394
- return this.#requireRowView().fieldCount;
395
- }
396
- get selectedColumns() {
397
- return this.#selectedColumns;
398
- }
399
- fieldRange(columnIndex) {
400
- return this.#requireRowView().fieldRange(columnIndex);
401
- }
402
- range(columnIndex) {
403
- return this.#requireRowView().range(columnIndex);
404
- }
405
- fieldBytes(columnIndex) {
406
- return this.#requireRowView().fieldBytes(columnIndex);
407
- }
408
- bytes(columnIndex) {
409
- return this.#requireRowView().bytes(columnIndex);
410
- }
411
- fieldBuffer(columnIndex) {
412
- return this.#requireRowView().fieldBuffer(columnIndex);
413
- }
414
- buffer(columnIndex) {
415
- return this.#requireRowView().buffer(columnIndex);
416
- }
417
- fieldString(columnIndex) {
418
- return this.#requireRowView().fieldString(columnIndex);
419
- }
420
- getPhysical(columnIndex) {
421
- return this.#requireRowView().getPhysical(columnIndex);
422
- }
423
- get(columnIndex) {
424
- return this.#requireRowView().get(columnIndex);
425
- }
426
- pickPhysical(columns) {
427
- return this.#requireRowView().pickPhysical(columns);
428
- }
429
- pick(columns) {
430
- return this.#requireRowView().pick(columns);
431
- }
432
- #requireRowView() {
433
- if (this.#rowView === null)
434
- throw Error("row view is only valid during row view callback");
435
- return this.#rowView;
436
- }
437
- }
438
-
439
- class ScopedCsvColumnarBatchView {
440
- #selectedColumns;
441
- #batch = null;
442
- constructor(selectedColumns) {
443
- this.#selectedColumns = selectedColumns;
444
- }
445
- bind(batch) {
446
- this.#batch = batch;
447
- return this;
448
- }
449
- release() {
450
- this.#batch = null;
451
- }
452
- get rowCount() {
453
- return this.#requireBatch().rowCount;
454
- }
455
- get totalFields() {
456
- return this.#requireBatch().totalFields;
457
- }
458
- get dataLength() {
459
- return this.#requireBatch().dataLength;
460
- }
461
- get selectedColumns() {
462
- return this.#selectedColumns;
463
- }
464
- data() {
465
- return this.#requireBatch().data();
466
- }
467
- dataView() {
468
- return this.#requireBatch().dataView();
469
- }
470
- rowOffsets() {
471
- return this.#requireBatch().rowOffsets();
472
- }
473
- fieldOffsets() {
474
- return this.#requireBatch().fieldOffsets();
475
- }
476
- rowFieldCount(rowIndex) {
477
- return this.#requireBatch().rowFieldCount(rowIndex);
478
- }
479
- fieldRange(rowIndex, columnIndex) {
480
- return this.#requireBatch().fieldRange(rowIndex, columnIndex);
481
- }
482
- fieldBytes(rowIndex, columnIndex) {
483
- return this.#requireBatch().fieldBytes(rowIndex, columnIndex);
484
- }
485
- fieldBuffer(rowIndex, columnIndex) {
486
- return this.#requireBatch().fieldBuffer(rowIndex, columnIndex);
487
- }
488
- forEachColumnRange(columnIndex, callback, startRow, endRow) {
489
- return this.#requireBatch().forEachColumnRange(columnIndex, callback, startRow, endRow);
490
- }
491
- forEachColumnBytes(columnIndex, callback, startRow, endRow) {
492
- return this.#requireBatch().forEachColumnBytes(columnIndex, callback, startRow, endRow);
493
- }
494
- scanColumns(columns, callback, startRow, endRow) {
495
- return this.#requireBatch().scanColumns(columns, callback, startRow, endRow);
496
- }
497
- #requireBatch() {
498
- if (this.#batch === null)
499
- throw Error("columnar batch view is only valid during columnar batch callback");
500
- return this.#batch;
501
- }
502
- }
503
- function writeCount(parser, chunk, filters) {
504
- if (filters === void 0)
505
- return parser.writeCount(chunk);
506
- return parser.writeCountWhere(chunk, filters);
507
- }
508
- function finishCount(parser, filters) {
509
- if (filters === void 0)
510
- return parser.endCount();
511
- return parser.endCountWhere(filters);
512
- }
513
220
  function toNativeFilters(where) {
514
221
  return nativeFilterProgramFor(where);
515
222
  }