@loaders.gl/core 5.0.0 → 5.0.1
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/api.cjs +4129 -0
- package/dist/api.cjs.map +6 -0
- package/dist/api.d.ts +34 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +50 -0
- package/dist/api.js.map +1 -0
- package/dist/arrow-geometry/index.cjs +5 -2
- package/dist/arrow-geometry/index.cjs.map +2 -2
- package/dist/arrow-geometry/index.d.ts +1 -0
- package/dist/arrow-geometry/index.d.ts.map +1 -1
- package/dist/arrow-geometry/index.js +1 -0
- package/dist/arrow-geometry/index.js.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs +100 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs.map +7 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts +15 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts.map +1 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js +87 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js.map +1 -0
- package/dist/dist.dev.js +458 -539
- package/dist/dist.min.js +3 -3
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +1 -1
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts.map +1 -1
- package/dist/geoarrow/index.cjs +1 -1
- package/dist/geoarrow/index.cjs.map +1 -1
- package/dist/geoarrow/index.d.ts +2 -2
- package/dist/geoarrow/index.d.ts.map +1 -1
- package/dist/geoarrow/index.js +1 -1
- package/dist/geoarrow/index.js.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
- package/dist/index.cjs +67 -4114
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -46
- package/dist/index.js.map +1 -1
- package/dist/lib/api/encode-table.d.ts +4 -4
- package/dist/lib/api/encode-table.d.ts.map +1 -1
- package/dist/lib/api/encode-table.js +21 -3
- package/dist/lib/api/encode-table.js.map +1 -1
- package/dist/lib/api/encode.d.ts +6 -6
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +46 -7
- package/dist/lib/api/encode.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +67 -24
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/index.d.ts +1 -1
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +1 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader-metadata.cjs +85 -0
- package/dist/loader-utils/json-loader-metadata.cjs.map +6 -0
- package/dist/loader-utils/json-loader-metadata.d.ts +51 -0
- package/dist/loader-utils/json-loader-metadata.d.ts.map +1 -0
- package/dist/loader-utils/json-loader-metadata.js +31 -0
- package/dist/loader-utils/json-loader-metadata.js.map +1 -0
- package/dist/loader-utils/json-loader.cjs +80 -0
- package/dist/loader-utils/json-loader.cjs.map +6 -0
- package/dist/loader-utils/json-loader.d.ts +4 -4
- package/dist/loader-utils/json-loader.d.ts.map +1 -1
- package/dist/loader-utils/json-loader.js +3 -17
- package/dist/loader-utils/json-loader.js.map +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.d.ts +2 -0
- package/dist/loader-utils/lib/request-utils/authentication.d.ts.map +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.js +12 -0
- package/dist/loader-utils/lib/request-utils/authentication.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/raster-source.d.ts +4 -0
- package/dist/loader-utils/lib/sources/raster-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/utils/utils.d.ts +1 -1
- package/dist/loader-utils/lib/sources/utils/utils.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.d.ts +2 -1
- package/dist/loader-utils/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.js +1 -1
- package/dist/loader-utils/tile-grid.js.map +1 -1
- package/dist/loader-utils/writer-types.d.ts +2 -0
- package/dist/loader-utils/writer-types.d.ts.map +1 -1
- package/dist/null-loader-metadata.cjs +89 -0
- package/dist/null-loader-metadata.cjs.map +6 -0
- package/dist/null-loader-metadata.d.ts +48 -0
- package/dist/null-loader-metadata.d.ts.map +1 -0
- package/dist/null-loader-metadata.js +30 -0
- package/dist/null-loader-metadata.js.map +1 -0
- package/dist/null-loader.cjs +84 -0
- package/dist/null-loader.cjs.map +6 -0
- package/dist/null-loader.d.ts +6 -6
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +2 -15
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +58 -28
- package/dist/null-worker.js +58 -28
- package/dist/scan/arrow-execution/expressions.d.ts +1 -1
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
- package/dist/scan/index.cjs +16 -4
- package/dist/scan/index.cjs.map +2 -2
- package/dist/scan/index.d.ts +5 -2
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +4 -2
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/plan-arrow-table-query.d.ts +1 -1
- package/dist/scan/plan-arrow-table-query.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.cjs +7 -19
- package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
- package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.js +7 -22
- package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
- package/dist/scan/query-executor.cjs +202 -0
- package/dist/scan/query-executor.cjs.map +7 -0
- package/dist/scan/query-executor.d.ts +27 -0
- package/dist/scan/query-executor.d.ts.map +1 -0
- package/dist/scan/query-executor.js +203 -0
- package/dist/scan/query-executor.js.map +1 -0
- package/dist/scan/query.cjs +92 -205
- package/dist/scan/query.cjs.map +3 -3
- package/dist/scan/query.d.ts +5 -4
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +94 -238
- package/dist/scan/query.js.map +1 -1
- package/dist/schema-utils/index.cjs +182 -0
- package/dist/schema-utils/index.cjs.map +3 -3
- package/dist/schema-utils/index.d.ts +3 -0
- package/dist/schema-utils/index.d.ts.map +1 -1
- package/dist/schema-utils/index.js +3 -0
- package/dist/schema-utils/index.js.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts +24 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js +43 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts +29 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js +89 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts +17 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js +24 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts +4 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js +51 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js.map +1 -0
- package/dist/worker-utils/index.cjs +2 -2
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/package.json +49 -23
- package/src/api.ts +99 -0
- package/src/arrow-geometry/index.ts +5 -0
- package/src/arrow-geometry/triangulate-wkb-geometry-column.ts +122 -0
- package/src/geoarrow/index.ts +2 -2
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +1 -1
- package/src/index.ts +2 -94
- package/src/lib/api/encode-table.ts +31 -6
- package/src/lib/api/encode.ts +61 -11
- package/src/loader-utils/index.ts +1 -0
- package/src/loader-utils/json-loader-metadata.ts +35 -0
- package/src/loader-utils/json-loader.ts +3 -18
- package/src/loader-utils/lib/request-utils/authentication.ts +17 -0
- package/src/loader-utils/lib/sources/raster-source.ts +4 -0
- package/src/loader-utils/tile-grid.ts +16 -1
- package/src/loader-utils/writer-types.ts +2 -0
- package/src/null-loader-metadata.ts +32 -0
- package/src/null-loader.ts +2 -17
- package/src/scan/index.ts +22 -2
- package/src/scan/query-arrow-table-in-batches.ts +7 -24
- package/src/scan/query-executor.ts +286 -0
- package/src/scan/query.ts +112 -299
- package/src/schema-utils/index.ts +14 -0
- package/src/schema-utils/lib/arrow/arrow-converter.ts +74 -0
- package/src/schema-utils/lib/arrow/convert-arrow-variable-width.ts +121 -0
- package/src/schema-utils/lib/arrow/convert-arrow.ts +52 -0
- package/src/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.ts +83 -0
- package/dist/cluster-source.cjs +0 -6360
- package/dist/cluster-source.cjs.map +0 -6
- package/dist/cluster-source.d.ts +0 -2
- package/dist/cluster-source.d.ts.map +0 -1
- package/dist/cluster-source.js +0 -2
- package/dist/cluster-source.js.map +0 -1
- package/dist/federated-table-scan-source.cjs +0 -1905
- package/dist/federated-table-scan-source.cjs.map +0 -6
- package/dist/federated-table-scan-source.d.ts +0 -2
- package/dist/federated-table-scan-source.d.ts.map +0 -1
- package/dist/federated-table-scan-source.js +0 -2
- package/dist/federated-table-scan-source.js.map +0 -1
- package/dist/geoarrow/geoarrow-builder.cjs +0 -31
- package/dist/geoarrow/geoarrow-builder.cjs.map +0 -7
- package/dist/geoarrow/geoarrow-builder.d.ts +0 -3
- package/dist/geoarrow/geoarrow-builder.d.ts.map +0 -1
- package/dist/geoarrow/geoarrow-builder.js +0 -5
- package/dist/geoarrow/geoarrow-builder.js.map +0 -1
- package/dist/vector-table-scan-source.cjs +0 -1200
- package/dist/vector-table-scan-source.cjs.map +0 -6
- package/dist/vector-table-scan-source.d.ts +0 -2
- package/dist/vector-table-scan-source.d.ts.map +0 -1
- package/dist/vector-table-scan-source.js +0 -2
- package/dist/vector-table-scan-source.js.map +0 -1
- package/src/cluster-source.ts +0 -1
- package/src/federated-table-scan-source.ts +0 -1
- package/src/geoarrow/geoarrow-builder.ts +0 -21
- package/src/vector-table-scan-source.ts +0 -1
package/src/null-loader.ts
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {NullLoaderMetadata} from './null-loader-metadata';
|
|
5
6
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/core/loader-utils';
|
|
6
7
|
import {LoaderContext} from '@loaders.gl/core/loader-utils';
|
|
7
8
|
|
|
8
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
9
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
10
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
|
-
|
|
12
9
|
export type NullLoaderOptions = LoaderOptions & {
|
|
13
10
|
null?: {};
|
|
14
11
|
};
|
|
@@ -17,15 +14,7 @@ export type NullLoaderOptions = LoaderOptions & {
|
|
|
17
14
|
* Loads any data and returns null (or optionally passes through data unparsed)
|
|
18
15
|
*/
|
|
19
16
|
export const NullLoader = {
|
|
20
|
-
|
|
21
|
-
batchType: null,
|
|
22
|
-
|
|
23
|
-
name: 'Null loader',
|
|
24
|
-
id: 'null',
|
|
25
|
-
module: 'core',
|
|
26
|
-
version: VERSION,
|
|
27
|
-
mimeTypes: ['application/x.empty'],
|
|
28
|
-
extensions: ['null'],
|
|
17
|
+
...NullLoaderMetadata,
|
|
29
18
|
parse: async (
|
|
30
19
|
arrayBuffer: ArrayBufferLike | ArrayBufferView,
|
|
31
20
|
options?: NullLoaderOptions,
|
|
@@ -36,10 +25,6 @@ export const NullLoader = {
|
|
|
36
25
|
for await (const batch of asyncIterator) {
|
|
37
26
|
yield parseSync(batch, options, context);
|
|
38
27
|
}
|
|
39
|
-
},
|
|
40
|
-
tests: [() => false],
|
|
41
|
-
options: {
|
|
42
|
-
null: {}
|
|
43
28
|
}
|
|
44
29
|
} as const satisfies LoaderWithParser<null, null, NullLoaderOptions>;
|
|
45
30
|
|
package/src/scan/index.ts
CHANGED
|
@@ -104,7 +104,27 @@ export type {
|
|
|
104
104
|
|
|
105
105
|
export {ARROW_TABLE_QUERY_CAPABILITIES, explainArrowTableQuery} from './plan-arrow-table-query';
|
|
106
106
|
export {queryArrowTable} from './query-arrow-table';
|
|
107
|
-
export
|
|
107
|
+
export {bindSQLPredicate} from './bind-sql-predicate';
|
|
108
|
+
export {
|
|
109
|
+
isSQLPredicate,
|
|
110
|
+
SQL_PREDICATE_JSON_SCHEMA,
|
|
111
|
+
validateSQLPredicate
|
|
112
|
+
} from './sql-predicate-schema';
|
|
113
|
+
export {isSQLPredicateParameter} from './sql-predicate-types';
|
|
114
|
+
export type {
|
|
115
|
+
BoundSQLPredicate,
|
|
116
|
+
SQLComparisonPredicate,
|
|
117
|
+
SQLInPredicate,
|
|
118
|
+
SQLLogicalPredicate,
|
|
119
|
+
SQLNotPredicate,
|
|
120
|
+
SQLNullPredicate,
|
|
121
|
+
SQLPredicateParameter,
|
|
122
|
+
SQLPredicateParameterValues,
|
|
123
|
+
SQLPredicateParserOptions,
|
|
124
|
+
SQLPredicateProperty,
|
|
125
|
+
SQLPredicateScalar,
|
|
126
|
+
SQLPredicateValue
|
|
127
|
+
} from './sql-predicate-types';
|
|
108
128
|
export {explainTableQuery, getSQLPredicateColumnNames, planTableQuery} from './table-query';
|
|
109
129
|
export type {
|
|
110
130
|
TableQueryPlan,
|
|
@@ -130,7 +150,7 @@ export {projectArrowTable, filterArrowTable} from './arrow-execution';
|
|
|
130
150
|
export type {ArrowFilterOptions} from './arrow-execution';
|
|
131
151
|
|
|
132
152
|
export {queryGroupedSQL} from './query-grouped-sql';
|
|
133
|
-
export {query, queryInBatches, queryProgressive} from './query';
|
|
153
|
+
export {preloadQuery, query, queryInBatches, queryProgressive} from './query';
|
|
134
154
|
export type {
|
|
135
155
|
ProgressiveAggregate,
|
|
136
156
|
ProgressiveAggregateQuery,
|
|
@@ -31,28 +31,11 @@ export async function* queryArrowTableInBatches(
|
|
|
31
31
|
validateTableQueryLimit(options.limit);
|
|
32
32
|
options.signal?.throwIfAborted();
|
|
33
33
|
if (options.limit === 0) return;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let next: IteratorResult<arrow.RecordBatch> = first;
|
|
42
|
-
!next.done;
|
|
43
|
-
next = await iterator.next()
|
|
44
|
-
) {
|
|
45
|
-
yield next.value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
yield* executeArrowQueryInBatches(readBatches(), first.value.schema, {
|
|
49
|
-
select: options.select ?? options.columns,
|
|
50
|
-
where: options.predicate,
|
|
51
|
-
limit: options.limit,
|
|
52
|
-
signal: options.signal,
|
|
53
|
-
emitEmptyBatches: true
|
|
54
|
-
});
|
|
55
|
-
} finally {
|
|
56
|
-
await iterator.return?.();
|
|
57
|
-
}
|
|
34
|
+
yield* executeArrowQueryInBatches(batches, {
|
|
35
|
+
select: options.select ?? options.columns,
|
|
36
|
+
where: options.predicate,
|
|
37
|
+
limit: options.limit,
|
|
38
|
+
signal: options.signal,
|
|
39
|
+
emitEmptyBatches: true
|
|
40
|
+
});
|
|
58
41
|
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import * as arrow from 'apache-arrow';
|
|
6
|
+
import type {TableBatch, Schema} from '@loaders.gl/core/schema';
|
|
7
|
+
import {
|
|
8
|
+
normalizeTableQuery,
|
|
9
|
+
getColumnarPredicateColumns,
|
|
10
|
+
executeTableScanBatches,
|
|
11
|
+
planTableQuery,
|
|
12
|
+
type TableQuery,
|
|
13
|
+
type TableScanReadOptions,
|
|
14
|
+
type TableScanSource,
|
|
15
|
+
type TableQueryExecutionSummary
|
|
16
|
+
} from '@loaders.gl/core/loader-utils';
|
|
17
|
+
import {
|
|
18
|
+
convertArrowToSchema,
|
|
19
|
+
convertSchemaToArrow,
|
|
20
|
+
convertTableToArrow,
|
|
21
|
+
makeArrowMetadataBatch,
|
|
22
|
+
makeArrowTableFromBatches
|
|
23
|
+
} from '@loaders.gl/core/schema-utils';
|
|
24
|
+
import {projectArrowTable, filterArrowTable} from './arrow-execution';
|
|
25
|
+
import {filterArrowRows} from './arrow-execution/filter-arrow-table';
|
|
26
|
+
import type {QueryOptions} from './query';
|
|
27
|
+
import {planQueryPushdown} from './query-pushdown';
|
|
28
|
+
import type {SQLQuery} from '@math.gl/sql/parser';
|
|
29
|
+
import type {SQLCatalogQuery} from './sql-catalog';
|
|
30
|
+
|
|
31
|
+
/** Source and query information available before the first physical read. */
|
|
32
|
+
type PreparedQuery = {
|
|
33
|
+
/** Validated logical query. */
|
|
34
|
+
logicalQuery: TableQuery | Exclude<SQLQuery, SQLCatalogQuery>;
|
|
35
|
+
/** Resolved table or scan source. */
|
|
36
|
+
source: object;
|
|
37
|
+
/** Native Arrow input when supplied by the caller. */
|
|
38
|
+
inMemory: arrow.Table | null;
|
|
39
|
+
/** Discovery result for a scan source. */
|
|
40
|
+
metadata: Awaited<ReturnType<TableScanSource['getQueryMetadata']>> | undefined;
|
|
41
|
+
/** Whether WHERE requires expression evaluation. */
|
|
42
|
+
castPredicate: boolean;
|
|
43
|
+
/** Whether this request targets catalog metadata. */
|
|
44
|
+
catalogQuery: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Executes a prepared query and updates its public completion counters. */
|
|
48
|
+
export async function* executePreparedQuery(
|
|
49
|
+
{logicalQuery, source, inMemory, metadata, castPredicate, catalogQuery}: PreparedQuery,
|
|
50
|
+
options: QueryOptions,
|
|
51
|
+
metrics: Pick<
|
|
52
|
+
{-readonly [Key in keyof TableQueryExecutionSummary]: TableQueryExecutionSummary[Key]},
|
|
53
|
+
'sourcesRead' | 'rowsRead' | 'rowsReturned' | 'batchesRead' | 'earlyTerminationReason'
|
|
54
|
+
>
|
|
55
|
+
): AsyncGenerator<arrow.RecordBatch> {
|
|
56
|
+
const sourceSchema = inMemory ? inMemory.schema : convertSchemaToArrow(metadata!.schema);
|
|
57
|
+
const names = sourceSchema.fields.map(field => field.name);
|
|
58
|
+
const {select: requestedSelect, where, ...controls} = logicalQuery;
|
|
59
|
+
const computedProjection =
|
|
60
|
+
Array.isArray(requestedSelect) &&
|
|
61
|
+
requestedSelect.some(
|
|
62
|
+
selection =>
|
|
63
|
+
selection &&
|
|
64
|
+
typeof selection === 'object' &&
|
|
65
|
+
('expression' in selection || 'array' in selection)
|
|
66
|
+
);
|
|
67
|
+
// Resolve the public scan aliases before planning either native or residual projection.
|
|
68
|
+
const select = computedProjection
|
|
69
|
+
? requestedSelect.map((item, index) =>
|
|
70
|
+
item && typeof item === 'object' && ('expression' in item || 'array' in item)
|
|
71
|
+
? {...item, as: item.as ?? `column${index + 1}`}
|
|
72
|
+
: item
|
|
73
|
+
)
|
|
74
|
+
: requestedSelect;
|
|
75
|
+
const expressionFilter =
|
|
76
|
+
where && typeof where === 'object' && 'expression' in where ? where : undefined;
|
|
77
|
+
const portablePredicate = expressionFilter ? undefined : (where as TableQuery['where']);
|
|
78
|
+
const normalized = normalizeTableQuery(names, {
|
|
79
|
+
...controls,
|
|
80
|
+
select: computedProjection ? undefined : (select as TableQuery['select']),
|
|
81
|
+
where: castPredicate ? undefined : portablePredicate
|
|
82
|
+
});
|
|
83
|
+
const expressionTools =
|
|
84
|
+
computedProjection || expressionFilter || castPredicate
|
|
85
|
+
? await import('./arrow-execution/expressions')
|
|
86
|
+
: undefined;
|
|
87
|
+
const outputColumns = computedProjection
|
|
88
|
+
? expressionTools!.getProjectionColumns(select!)
|
|
89
|
+
: normalized.select.map(selection => selection.column);
|
|
90
|
+
const expressionColumns = expressionFilter
|
|
91
|
+
? expressionTools!.getExpressionColumns(expressionFilter.expression)
|
|
92
|
+
: castPredicate && portablePredicate
|
|
93
|
+
? getColumnarPredicateColumns(portablePredicate)
|
|
94
|
+
: [];
|
|
95
|
+
const required = [...new Set([...outputColumns, ...expressionColumns])];
|
|
96
|
+
const plan = planTableQuery(names, {
|
|
97
|
+
// A literal-only projection still needs a physical column to retain row counts.
|
|
98
|
+
columns: required.length ? required : names.slice(0, 1),
|
|
99
|
+
predicate: normalized.where
|
|
100
|
+
});
|
|
101
|
+
const requiredColumns = plan[0].kind === 'scan' ? plan[0].columns : names;
|
|
102
|
+
const capabilities = (metadata?.queryCapabilities ?? metadata?.capabilities)?.table;
|
|
103
|
+
// read() must perform exact filtering when it advertises pushdown+residual, not only pruning.
|
|
104
|
+
const delegatePredicate = Boolean(
|
|
105
|
+
normalized.where &&
|
|
106
|
+
capabilities &&
|
|
107
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.predicate)
|
|
108
|
+
);
|
|
109
|
+
const residual = delegatePredicate ? undefined : normalized.where;
|
|
110
|
+
const canDelegateWindow = !residual && !expressionFilter && !castPredicate;
|
|
111
|
+
const delegateOffset = Boolean(
|
|
112
|
+
canDelegateWindow &&
|
|
113
|
+
normalized.offset !== undefined &&
|
|
114
|
+
capabilities &&
|
|
115
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.offset ?? 'unsupported')
|
|
116
|
+
);
|
|
117
|
+
const requestedRows =
|
|
118
|
+
normalized.limit === undefined
|
|
119
|
+
? undefined
|
|
120
|
+
: (delegateOffset ? 0 : (normalized.offset ?? 0)) + normalized.limit;
|
|
121
|
+
const readOptions: TableScanReadOptions = {
|
|
122
|
+
signal: options.signal,
|
|
123
|
+
...(capabilities && capabilities.projection !== 'unsupported'
|
|
124
|
+
? {columns: requiredColumns}
|
|
125
|
+
: {}),
|
|
126
|
+
...(delegatePredicate ? {predicate: normalized.where} : {}),
|
|
127
|
+
...(delegateOffset ? {offset: normalized.offset} : {}),
|
|
128
|
+
...(canDelegateWindow &&
|
|
129
|
+
requestedRows !== undefined &&
|
|
130
|
+
Number.isSafeInteger(requestedRows) &&
|
|
131
|
+
capabilities &&
|
|
132
|
+
['pushdown', 'pushdown+residual'].includes(capabilities.limit)
|
|
133
|
+
? {limit: requestedRows}
|
|
134
|
+
: {})
|
|
135
|
+
};
|
|
136
|
+
const inputSchema = readOptions.columns
|
|
137
|
+
? sourceSchema.select([...readOptions.columns])
|
|
138
|
+
: sourceSchema;
|
|
139
|
+
const readSchema = convertArrowToSchema(inputSchema);
|
|
140
|
+
const comparisonInputSchema = expressionTools ? convertSchemaToArrow(readSchema) : undefined;
|
|
141
|
+
const compiledFilter = expressionFilter
|
|
142
|
+
? expressionTools!.compileArrowExpression(expressionFilter.expression, {
|
|
143
|
+
inputSchema,
|
|
144
|
+
functions: options.functions
|
|
145
|
+
})
|
|
146
|
+
: castPredicate && portablePredicate
|
|
147
|
+
? expressionTools!.compileArrowPredicate(portablePredicate, {inputSchema})
|
|
148
|
+
: undefined;
|
|
149
|
+
if (compiledFilter && !arrow.DataType.isBool(compiledFilter.outputField.type))
|
|
150
|
+
throw new Error('SQL WHERE expression must return Boolean.');
|
|
151
|
+
const project = computedProjection
|
|
152
|
+
? expressionTools!.prepareArrowProjection(inputSchema, select!, {
|
|
153
|
+
signal: options.signal,
|
|
154
|
+
functions: options.functions
|
|
155
|
+
}).projectTable
|
|
156
|
+
: (data: arrow.Table) => projectArrowTable(data, normalized.select);
|
|
157
|
+
const empty = project(new arrow.Table(inputSchema));
|
|
158
|
+
const comparisonSchema = convertSchemaToArrow(convertArrowToSchema(empty.schema));
|
|
159
|
+
const pushedPlan =
|
|
160
|
+
!inMemory &&
|
|
161
|
+
!options.functions?.length &&
|
|
162
|
+
!catalogQuery &&
|
|
163
|
+
(source as TableScanSource).planQueryPushdown
|
|
164
|
+
? await planQueryPushdown(
|
|
165
|
+
source as TableScanSource,
|
|
166
|
+
{...logicalQuery, select},
|
|
167
|
+
capabilities,
|
|
168
|
+
comparisonSchema,
|
|
169
|
+
Boolean(computedProjection || expressionFilter),
|
|
170
|
+
inputSchema,
|
|
171
|
+
options.signal
|
|
172
|
+
)
|
|
173
|
+
: null;
|
|
174
|
+
options.signal?.throwIfAborted();
|
|
175
|
+
let emitted = false;
|
|
176
|
+
/** Adapts physical batches without pulling ahead of the query consumer. */
|
|
177
|
+
async function* inputs(): AsyncIterable<arrow.Table> {
|
|
178
|
+
metrics.sourcesRead = 1;
|
|
179
|
+
const batches: AsyncIterable<unknown> = pushedPlan
|
|
180
|
+
? pushedPlan.read({signal: options.signal})
|
|
181
|
+
: inMemory
|
|
182
|
+
? memoryBatches(inMemory)
|
|
183
|
+
: (source as TableScanSource).read(readOptions);
|
|
184
|
+
for await (const value of batches) {
|
|
185
|
+
options.signal?.throwIfAborted();
|
|
186
|
+
let batch = normalizeBatch(value, pushedPlan?.schema ?? readSchema);
|
|
187
|
+
if (
|
|
188
|
+
!pushedPlan &&
|
|
189
|
+
comparisonInputSchema &&
|
|
190
|
+
!arrow.util.compareSchemas(
|
|
191
|
+
comparisonInputSchema,
|
|
192
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
193
|
+
)
|
|
194
|
+
) {
|
|
195
|
+
// A source may return a wider or differently ordered projection than requested.
|
|
196
|
+
batch = batch.select(inputSchema.names);
|
|
197
|
+
if (
|
|
198
|
+
!arrow.util.compareSchemas(
|
|
199
|
+
comparisonInputSchema,
|
|
200
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
throw new Error('Query input schema does not match source metadata.');
|
|
204
|
+
}
|
|
205
|
+
metrics.batchesRead++;
|
|
206
|
+
metrics.rowsRead += batch.numRows;
|
|
207
|
+
yield batch;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
for await (const value of executeTableScanBatches<arrow.Table>(
|
|
211
|
+
() => inputs(),
|
|
212
|
+
{
|
|
213
|
+
predicate: pushedPlan ? undefined : residual,
|
|
214
|
+
offset: pushedPlan || delegateOffset ? undefined : normalized.offset,
|
|
215
|
+
limit: normalized.limit,
|
|
216
|
+
skipEmptyBatches: true,
|
|
217
|
+
signal: options.signal
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
filter: (batch, predicate, signal) => {
|
|
221
|
+
if (pushedPlan) return batch;
|
|
222
|
+
if (compiledFilter) {
|
|
223
|
+
return filterArrowRows(
|
|
224
|
+
batch,
|
|
225
|
+
recordBatch => {
|
|
226
|
+
const matches = compiledFilter.evaluate(recordBatch, {signal});
|
|
227
|
+
return index => matches.get(index) === true;
|
|
228
|
+
},
|
|
229
|
+
{signal}
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
return predicate ? filterArrowTable(batch, predicate, {signal}) : batch;
|
|
233
|
+
},
|
|
234
|
+
project: batch => (pushedPlan || computedProjection ? batch : project(batch))
|
|
235
|
+
}
|
|
236
|
+
)) {
|
|
237
|
+
const finishProjection = pushedPlan
|
|
238
|
+
? pushedPlan.project
|
|
239
|
+
: computedProjection
|
|
240
|
+
? project
|
|
241
|
+
: undefined;
|
|
242
|
+
const batch = finishProjection ? finishProjection(value) : value;
|
|
243
|
+
if (
|
|
244
|
+
!arrow.util.compareSchemas(
|
|
245
|
+
comparisonSchema,
|
|
246
|
+
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
throw new Error('Query output schema does not match source metadata.');
|
|
250
|
+
emitted = true;
|
|
251
|
+
metrics.rowsReturned += batch.numRows;
|
|
252
|
+
if (batch.batches.length) yield* batch.batches;
|
|
253
|
+
else yield makeArrowMetadataBatch(batch.schema);
|
|
254
|
+
}
|
|
255
|
+
// An empty schema-bearing batch makes collected and streaming empty results identical.
|
|
256
|
+
if (!emitted) {
|
|
257
|
+
if (empty.batches.length) yield* empty.batches;
|
|
258
|
+
else yield makeArrowMetadataBatch(empty.schema);
|
|
259
|
+
}
|
|
260
|
+
if (normalized.limit !== undefined && metrics.rowsReturned >= normalized.limit)
|
|
261
|
+
metrics.earlyTerminationReason = 'limit';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export {makeArrowTableFromBatches};
|
|
265
|
+
|
|
266
|
+
/** Emits original Arrow RecordBatches without copying their buffers. */
|
|
267
|
+
async function* memoryBatches(data: arrow.Table): AsyncIterable<arrow.Table> {
|
|
268
|
+
for (const batch of data.batches) yield new arrow.Table(data.schema, [batch]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Converts supported native table batches to Arrow while preserving their declared schema. */
|
|
272
|
+
function normalizeBatch(value: unknown, fallbackSchema: Schema): arrow.Table {
|
|
273
|
+
if (!value || typeof value !== 'object') throw new Error('Unsupported query batch.');
|
|
274
|
+
if ('numRows' in value) {
|
|
275
|
+
const batch = value as arrow.RecordBatch;
|
|
276
|
+
return new arrow.Table(batch.schema, [batch]);
|
|
277
|
+
}
|
|
278
|
+
if (!('shape' in value)) throw new Error('Unsupported query batch.');
|
|
279
|
+
const input = value as TableBatch;
|
|
280
|
+
const batch = {...input, schema: input.schema ?? fallbackSchema} as TableBatch;
|
|
281
|
+
if (!['object-row-table', 'array-row-table', 'columnar-table'].includes(batch.shape))
|
|
282
|
+
throw new Error(`Unsupported query batch shape: ${batch.shape}`);
|
|
283
|
+
return batch.length === 0 && batch.schema
|
|
284
|
+
? new arrow.Table(convertSchemaToArrow(batch.schema))
|
|
285
|
+
: convertTableToArrow(batch);
|
|
286
|
+
}
|