@loaders.gl/schema 3.4.14 → 3.4.15
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.
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/category/mesh/convert-mesh.js +2 -7
- package/dist/es5/category/mesh/convert-mesh.js.map +1 -1
- package/dist/es5/category/mesh/deduce-mesh-schema.js +8 -8
- package/dist/es5/category/mesh/deduce-mesh-schema.js.map +1 -1
- package/dist/es5/category/mesh/mesh-to-arrow-table.js +17 -16
- package/dist/es5/category/mesh/mesh-to-arrow-table.js.map +1 -1
- package/dist/es5/category/mesh/mesh-utils.js +15 -15
- package/dist/es5/category/mesh/mesh-utils.js.map +1 -1
- package/dist/es5/category/table/deduce-table-schema.js +9 -9
- package/dist/es5/category/table/deduce-table-schema.js.map +1 -1
- package/dist/es5/index.js +51 -51
- package/dist/es5/lib/arrow/get-type-info.js +3 -3
- package/dist/es5/lib/arrow/get-type-info.js.map +1 -1
- package/dist/es5/lib/batches/base-table-batch-aggregator.js +38 -51
- package/dist/es5/lib/batches/base-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/columnar-table-batch-aggregator.js +60 -81
- package/dist/es5/lib/batches/columnar-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/row-table-batch-aggregator.js +53 -66
- package/dist/es5/lib/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/table-batch-builder.js +101 -127
- package/dist/es5/lib/batches/table-batch-builder.js.map +1 -1
- package/dist/es5/lib/schema/impl/enum.js +1 -1
- package/dist/es5/lib/schema/impl/field.js +17 -30
- package/dist/es5/lib/schema/impl/field.js.map +1 -1
- package/dist/es5/lib/schema/impl/schema.js +55 -105
- package/dist/es5/lib/schema/impl/schema.js.map +1 -1
- package/dist/es5/lib/schema/impl/type.js +375 -675
- package/dist/es5/lib/schema/impl/type.js.map +1 -1
- package/dist/es5/lib/schema/schema.js +37 -37
- package/dist/es5/lib/utils/async-queue.js +72 -138
- package/dist/es5/lib/utils/async-queue.js.map +1 -1
- package/dist/es5/lib/utils/row-utils.js +4 -4
- package/dist/es5/lib/utils/row-utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(0, _classCallCheck2.default)(this, ColumnarTableBatchAggregator);
|
|
9
|
+
const DEFAULT_ROW_COUNT = 100;
|
|
10
|
+
class ColumnarTableBatchAggregator {
|
|
11
|
+
constructor(schema, options) {
|
|
16
12
|
(0, _defineProperty2.default)(this, "schema", void 0);
|
|
17
13
|
(0, _defineProperty2.default)(this, "length", 0);
|
|
18
14
|
(0, _defineProperty2.default)(this, "allocated", 0);
|
|
@@ -20,87 +16,70 @@ var ColumnarTableBatchAggregator = function () {
|
|
|
20
16
|
this.schema = schema;
|
|
21
17
|
this._reallocateColumns();
|
|
22
18
|
}
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
rowCount() {
|
|
20
|
+
return this.length;
|
|
21
|
+
}
|
|
22
|
+
addArrayRow(row) {
|
|
23
|
+
this._reallocateColumns();
|
|
24
|
+
let i = 0;
|
|
25
|
+
for (const fieldName in this.columns) {
|
|
26
|
+
this.columns[fieldName][this.length] = row[i++];
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.columns[fieldName][this.length] = row[i++];
|
|
35
|
-
}
|
|
36
|
-
this.length++;
|
|
28
|
+
this.length++;
|
|
29
|
+
}
|
|
30
|
+
addObjectRow(row) {
|
|
31
|
+
this._reallocateColumns();
|
|
32
|
+
for (const fieldName in row) {
|
|
33
|
+
this.columns[fieldName][this.length] = row[fieldName];
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
this.length++;
|
|
36
|
+
}
|
|
37
|
+
getBatch() {
|
|
38
|
+
this._pruneColumns();
|
|
39
|
+
const columns = Array.isArray(this.schema) ? this.columns : {};
|
|
40
|
+
if (!Array.isArray(this.schema)) {
|
|
41
|
+
for (const fieldName in this.schema) {
|
|
42
|
+
const field = this.schema[fieldName];
|
|
43
|
+
columns[field.name] = this.columns[field.index];
|
|
44
44
|
}
|
|
45
|
-
this.length++;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
shape: 'columnar-table',
|
|
61
|
-
batchType: 'data',
|
|
62
|
-
data: columns,
|
|
63
|
-
schema: this.schema,
|
|
64
|
-
length: this.length
|
|
65
|
-
};
|
|
66
|
-
return batch;
|
|
46
|
+
this.columns = {};
|
|
47
|
+
const batch = {
|
|
48
|
+
shape: 'columnar-table',
|
|
49
|
+
batchType: 'data',
|
|
50
|
+
data: columns,
|
|
51
|
+
schema: this.schema,
|
|
52
|
+
length: this.length
|
|
53
|
+
};
|
|
54
|
+
return batch;
|
|
55
|
+
}
|
|
56
|
+
_reallocateColumns() {
|
|
57
|
+
if (this.length < this.allocated) {
|
|
58
|
+
return;
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.columns[field.index] = typedArray;
|
|
84
|
-
} else if (oldColumn) {
|
|
85
|
-
oldColumn.length = this.allocated;
|
|
86
|
-
this.columns[field.index] = oldColumn;
|
|
87
|
-
} else {
|
|
88
|
-
this.columns[field.index] = new ArrayType(this.allocated);
|
|
89
|
-
}
|
|
60
|
+
this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT;
|
|
61
|
+
this.columns = {};
|
|
62
|
+
for (const fieldName in this.schema) {
|
|
63
|
+
const field = this.schema[fieldName];
|
|
64
|
+
const ArrayType = field.type || Float32Array;
|
|
65
|
+
const oldColumn = this.columns[field.index];
|
|
66
|
+
if (oldColumn && ArrayBuffer.isView(oldColumn)) {
|
|
67
|
+
const typedArray = new ArrayType(this.allocated);
|
|
68
|
+
typedArray.set(oldColumn);
|
|
69
|
+
this.columns[field.index] = typedArray;
|
|
70
|
+
} else if (oldColumn) {
|
|
71
|
+
oldColumn.length = this.allocated;
|
|
72
|
+
this.columns[field.index] = oldColumn;
|
|
73
|
+
} else {
|
|
74
|
+
this.columns[field.index] = new ArrayType(this.allocated);
|
|
90
75
|
}
|
|
91
76
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
97
|
-
_columnName = _Object$entries$_i[0],
|
|
98
|
-
column = _Object$entries$_i[1];
|
|
99
|
-
this.columns[_columnName] = column.slice(0, this.length);
|
|
100
|
-
}
|
|
77
|
+
}
|
|
78
|
+
_pruneColumns() {
|
|
79
|
+
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
80
|
+
this.columns[columnName] = column.slice(0, this.length);
|
|
101
81
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
}();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
105
84
|
exports.default = ColumnarTableBatchAggregator;
|
|
106
85
|
//# sourceMappingURL=columnar-table-batch-aggregator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columnar-table-batch-aggregator.js","names":["DEFAULT_ROW_COUNT","ColumnarTableBatchAggregator","schema","options","
|
|
1
|
+
{"version":3,"file":"columnar-table-batch-aggregator.js","names":["DEFAULT_ROW_COUNT","ColumnarTableBatchAggregator","constructor","schema","options","_defineProperty2","default","_reallocateColumns","rowCount","length","addArrayRow","row","i","fieldName","columns","addObjectRow","getBatch","_pruneColumns","Array","isArray","field","name","index","batch","shape","batchType","data","allocated","ArrayType","type","Float32Array","oldColumn","ArrayBuffer","isView","typedArray","set","columnName","column","Object","entries","slice","exports"],"sources":["../../../../src/lib/batches/columnar-table-batch-aggregator.ts"],"sourcesContent":["import type {Schema} from '../schema/schema';\nimport type {ColumnarTableBatch, ArrowTableBatch} from '../../category/table/table-types';\nimport {TableBatchAggregator} from './table-batch-aggregator';\n\ntype ColumnarTableBatchOptions = {};\n\nconst DEFAULT_ROW_COUNT = 100;\n\nexport default class ColumnarTableBatchAggregator implements TableBatchAggregator {\n schema: Schema;\n length: number = 0;\n allocated: number = 0;\n columns: {[columnName: string]: any[]} = {};\n\n constructor(schema: Schema, options: ColumnarTableBatchOptions) {\n this.schema = schema;\n this._reallocateColumns();\n }\n\n rowCount(): number {\n return this.length;\n }\n\n addArrayRow(row: any[]) {\n // If user keeps pushing rows beyond batch size, reallocate\n this._reallocateColumns();\n let i = 0;\n // TODO what if no csv header, columns not populated?\n for (const fieldName in this.columns) {\n this.columns[fieldName][this.length] = row[i++];\n }\n this.length++;\n }\n\n addObjectRow(row: {[columnName: string]: any}): void {\n // If user keeps pushing rows beyond batch size, reallocate\n this._reallocateColumns();\n for (const fieldName in row) {\n this.columns[fieldName][this.length] = row[fieldName];\n }\n this.length++;\n }\n\n getBatch(): ColumnarTableBatch | ArrowTableBatch | null {\n this._pruneColumns();\n const columns = Array.isArray(this.schema) ? this.columns : {};\n\n // schema is an array if there're no headers\n // object if there are headers\n // columns should match schema format\n if (!Array.isArray(this.schema)) {\n for (const fieldName in this.schema) {\n const field = this.schema[fieldName];\n columns[field.name] = this.columns[field.index];\n }\n }\n\n this.columns = {};\n\n const batch: ColumnarTableBatch = {\n shape: 'columnar-table',\n batchType: 'data',\n data: columns,\n schema: this.schema,\n length: this.length\n };\n\n return batch;\n }\n\n // HELPERS\n\n _reallocateColumns() {\n if (this.length < this.allocated) {\n return;\n }\n\n // @ts-ignore TODO\n this.allocated = this.allocated > 0 ? (this.allocated *= 2) : DEFAULT_ROW_COUNT;\n this.columns = {};\n\n for (const fieldName in this.schema) {\n const field = this.schema[fieldName];\n const ArrayType = field.type || Float32Array;\n const oldColumn = this.columns[field.index];\n\n if (oldColumn && ArrayBuffer.isView(oldColumn)) {\n // Copy the old data to the new array\n const typedArray = new ArrayType(this.allocated);\n typedArray.set(oldColumn);\n this.columns[field.index] = typedArray;\n } else if (oldColumn) {\n // Plain array\n oldColumn.length = this.allocated;\n this.columns[field.index] = oldColumn;\n } else {\n // Create new\n this.columns[field.index] = new ArrayType(this.allocated);\n }\n }\n }\n\n _pruneColumns() {\n for (const [columnName, column] of Object.entries(this.columns)) {\n this.columns[columnName] = column.slice(0, this.length);\n }\n }\n}\n"],"mappings":";;;;;;;;AAMA,MAAMA,iBAAiB,GAAG,GAAG;AAEd,MAAMC,4BAA4B,CAAiC;EAMhFC,WAAWA,CAACC,MAAc,EAAEC,OAAkC,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,kBAJ/C,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,qBACE,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,mBACoB,CAAC,CAAC;IAGzC,IAAI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CAAC,IAAI,CAACD,SAAS,CAAC;MAC3D;IACF;EACF;EAEAV,aAAaA,CAAA,EAAG;IACd,KAAK,MAAM,CAACmB,UAAU,EAAEC,MAAM,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAC,IAAI,CAACzB,OAAO,CAAC,EAAE;MAC/D,IAAI,CAACA,OAAO,CAACsB,UAAU,CAAC,GAAGC,MAAM,CAACG,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC/B,MAAM,CAAC;IACzD;EACF;AACF;AAACgC,OAAA,CAAAnC,OAAA,GAAAL,4BAAA"}
|
|
@@ -5,14 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
9
|
var _rowUtils = require("../utils/row-utils");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(0, _classCallCheck2.default)(this, RowTableBatchAggregator);
|
|
10
|
+
const DEFAULT_ROW_COUNT = 100;
|
|
11
|
+
class RowTableBatchAggregator {
|
|
12
|
+
constructor(schema, options) {
|
|
16
13
|
(0, _defineProperty2.default)(this, "schema", void 0);
|
|
17
14
|
(0, _defineProperty2.default)(this, "options", void 0);
|
|
18
15
|
(0, _defineProperty2.default)(this, "length", 0);
|
|
@@ -24,73 +21,63 @@ var RowTableBatchAggregator = function () {
|
|
|
24
21
|
this.schema = schema;
|
|
25
22
|
if (!Array.isArray(schema)) {
|
|
26
23
|
this._headers = [];
|
|
27
|
-
for (
|
|
24
|
+
for (const key in schema) {
|
|
28
25
|
this._headers[schema[key].index] = schema[key].name;
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
rowCount() {
|
|
30
|
+
return this.length;
|
|
31
|
+
}
|
|
32
|
+
addArrayRow(row, cursor) {
|
|
33
|
+
if (Number.isFinite(cursor)) {
|
|
34
|
+
this.cursor = cursor;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
break;
|
|
48
|
-
case 'array-row-table':
|
|
49
|
-
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
|
|
50
|
-
this.arrayRows[this.length] = row;
|
|
51
|
-
this.length++;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
36
|
+
switch (this.options.shape) {
|
|
37
|
+
case 'object-row-table':
|
|
38
|
+
const rowObject = (0, _rowUtils.convertToObjectRow)(row, this._headers);
|
|
39
|
+
this.addObjectRow(rowObject, cursor);
|
|
40
|
+
break;
|
|
41
|
+
case 'array-row-table':
|
|
42
|
+
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
|
|
43
|
+
this.arrayRows[this.length] = row;
|
|
44
|
+
this.length++;
|
|
45
|
+
break;
|
|
54
46
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.cursor = cursor;
|
|
60
|
-
}
|
|
61
|
-
switch (this.options.shape) {
|
|
62
|
-
case 'array-row-table':
|
|
63
|
-
var rowArray = (0, _rowUtils.convertToArrayRow)(row, this._headers);
|
|
64
|
-
this.addArrayRow(rowArray, cursor);
|
|
65
|
-
break;
|
|
66
|
-
case 'object-row-table':
|
|
67
|
-
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
|
|
68
|
-
this.objectRows[this.length] = row;
|
|
69
|
-
this.length++;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
47
|
+
}
|
|
48
|
+
addObjectRow(row, cursor) {
|
|
49
|
+
if (Number.isFinite(cursor)) {
|
|
50
|
+
this.cursor = cursor;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
shape: this.options.shape,
|
|
85
|
-
batchType: 'data',
|
|
86
|
-
data: rows,
|
|
87
|
-
length: this.length,
|
|
88
|
-
schema: this.schema,
|
|
89
|
-
cursor: this.cursor
|
|
90
|
-
};
|
|
52
|
+
switch (this.options.shape) {
|
|
53
|
+
case 'array-row-table':
|
|
54
|
+
const rowArray = (0, _rowUtils.convertToArrayRow)(row, this._headers);
|
|
55
|
+
this.addArrayRow(rowArray, cursor);
|
|
56
|
+
break;
|
|
57
|
+
case 'object-row-table':
|
|
58
|
+
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
|
|
59
|
+
this.objectRows[this.length] = row;
|
|
60
|
+
this.length++;
|
|
61
|
+
break;
|
|
91
62
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
63
|
+
}
|
|
64
|
+
getBatch() {
|
|
65
|
+
let rows = this.arrayRows || this.objectRows;
|
|
66
|
+
if (!rows) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
rows = rows.slice(0, this.length);
|
|
70
|
+
this.arrayRows = null;
|
|
71
|
+
this.objectRows = null;
|
|
72
|
+
return {
|
|
73
|
+
shape: this.options.shape,
|
|
74
|
+
batchType: 'data',
|
|
75
|
+
data: rows,
|
|
76
|
+
length: this.length,
|
|
77
|
+
schema: this.schema,
|
|
78
|
+
cursor: this.cursor
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
95
82
|
exports.default = RowTableBatchAggregator;
|
|
96
83
|
//# sourceMappingURL=row-table-batch-aggregator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row-table-batch-aggregator.js","names":["_rowUtils","require","DEFAULT_ROW_COUNT","RowTableBatchAggregator","schema","options","
|
|
1
|
+
{"version":3,"file":"row-table-batch-aggregator.js","names":["_rowUtils","require","DEFAULT_ROW_COUNT","RowTableBatchAggregator","constructor","schema","options","_defineProperty2","default","Array","isArray","_headers","key","index","name","rowCount","length","addArrayRow","row","cursor","Number","isFinite","shape","rowObject","convertToObjectRow","addObjectRow","arrayRows","rowArray","convertToArrayRow","objectRows","getBatch","rows","slice","batchType","data","exports"],"sources":["../../../../src/lib/batches/row-table-batch-aggregator.ts"],"sourcesContent":["import type {Schema} from '../schema/schema';\nimport type {TableBatch} from '../../category/table/table-types';\n// import type {ArrayRowTableBatch, ObjectRowTableBatch} from '../../category/table';\nimport {convertToArrayRow, convertToObjectRow} from '../utils/row-utils';\nimport {TableBatchAggregator, TableBatchOptions} from './table-batch-aggregator';\n\nconst DEFAULT_ROW_COUNT = 100;\n\nexport default class RowTableBatchAggregator implements TableBatchAggregator {\n schema: Schema;\n options: TableBatchOptions;\n\n length: number = 0;\n objectRows: {[columnName: string]: any} | null = null;\n arrayRows: any[] | null = null;\n cursor: number = 0;\n private _headers: string[] = [];\n\n constructor(schema: Schema, options: TableBatchOptions) {\n this.options = options;\n this.schema = schema;\n\n // schema is an array if there're no headers\n // object if there are headers\n if (!Array.isArray(schema)) {\n this._headers = [];\n for (const key in schema) {\n this._headers[schema[key].index] = schema[key].name;\n }\n }\n }\n\n rowCount(): number {\n return this.length;\n }\n\n addArrayRow(row: any[], cursor?: number): void {\n if (Number.isFinite(cursor)) {\n this.cursor = cursor as number;\n }\n\n // eslint-disable-next-line default-case\n switch (this.options.shape) {\n case 'object-row-table':\n const rowObject = convertToObjectRow(row, this._headers);\n this.addObjectRow(rowObject, cursor);\n break;\n case 'array-row-table':\n this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);\n this.arrayRows[this.length] = row;\n this.length++;\n break;\n }\n }\n\n addObjectRow(row: {[columnName: string]: any}, cursor?: number): void {\n if (Number.isFinite(cursor)) {\n this.cursor = cursor as number;\n }\n\n // eslint-disable-next-line default-case\n switch (this.options.shape) {\n case 'array-row-table':\n const rowArray = convertToArrayRow(row, this._headers);\n this.addArrayRow(rowArray, cursor);\n break;\n case 'object-row-table':\n this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);\n this.objectRows[this.length] = row;\n this.length++;\n break;\n }\n }\n\n getBatch(): TableBatch | null {\n let rows = this.arrayRows || this.objectRows;\n if (!rows) {\n return null;\n }\n\n rows = rows.slice(0, this.length);\n this.arrayRows = null;\n this.objectRows = null;\n\n return {\n shape: this.options.shape,\n batchType: 'data',\n data: rows,\n length: this.length,\n schema: this.schema,\n cursor: this.cursor\n };\n }\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AAGA,MAAMC,iBAAiB,GAAG,GAAG;AAEd,MAAMC,uBAAuB,CAAiC;EAU3EC,WAAWA,CAACC,MAAc,EAAEC,OAA0B,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,kBANvC,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,sBAC+B,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA,qBAC3B,IAAI;IAAA,IAAAD,gBAAA,CAAAC,OAAA,kBACb,CAAC;IAAA,IAAAD,gBAAA,CAAAC,OAAA,oBACW,EAAE;IAG7B,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACD,MAAM,GAAGA,MAAM;IAIpB,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;MAC1B,IAAI,CAACM,QAAQ,GAAG,EAAE;MAClB,KAAK,MAAMC,GAAG,IAAIP,MAAM,EAAE;QACxB,IAAI,CAACM,QAAQ,CAACN,MAAM,CAACO,GAAG,C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