@loaders.gl/core 5.0.0-beta.5 → 5.0.0-beta.7
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/cluster-source.cjs +45 -1
- package/dist/cluster-source.cjs.map +1 -1
- package/dist/dist.min.js +2 -2
- package/dist/federated-table-scan-source.cjs +279 -201
- package/dist/federated-table-scan-source.cjs.map +3 -3
- package/dist/index.cjs +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +233 -12
- package/dist/loader-utils/index.cjs.map +2 -2
- package/dist/loader-utils/index.d.ts +8 -4
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +3 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/files/http-file-transport.d.ts +4 -0
- package/dist/loader-utils/lib/files/http-file-transport.d.ts.map +1 -1
- package/dist/loader-utils/lib/files/http-file-transport.js +45 -1
- package/dist/loader-utils/lib/files/http-file-transport.js.map +1 -1
- package/dist/loader-utils/lib/files/http-file-types.d.ts +2 -0
- package/dist/loader-utils/lib/files/http-file-types.d.ts.map +1 -1
- package/dist/loader-utils/lib/files/read-range-response.d.ts +3 -0
- package/dist/loader-utils/lib/files/read-range-response.d.ts.map +1 -0
- package/dist/loader-utils/lib/files/read-range-response.js +62 -0
- package/dist/loader-utils/lib/files/read-range-response.js.map +1 -0
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts +38 -0
- package/dist/loader-utils/lib/scan-utils/logical-table-query.d.ts.map +1 -0
- package/dist/loader-utils/lib/scan-utils/logical-table-query.js +96 -0
- package/dist/loader-utils/lib/scan-utils/logical-table-query.js.map +1 -0
- package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.d.ts → query-options.d.ts} +5 -8
- package/dist/loader-utils/lib/scan-utils/query-options.d.ts.map +1 -0
- package/dist/loader-utils/lib/scan-utils/{experimental-scan-options.js → query-options.js} +1 -1
- package/dist/loader-utils/lib/scan-utils/query-options.js.map +1 -0
- package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts +12 -17
- package/dist/loader-utils/lib/scan-utils/scan-query-metadata.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js +5 -5
- package/dist/loader-utils/lib/scan-utils/scan-query-metadata.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts +33 -3
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts +2 -2
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.js +11 -3
- package/dist/loader-utils/lib/scan-utils/table-scan-batch.js.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts +4 -0
- package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.js +50 -1
- package/dist/loader-utils/lib/sources/data-source.js.map +1 -1
- package/dist/loader-utils/lib/sources/table-source-collection.d.ts +30 -0
- package/dist/loader-utils/lib/sources/table-source-collection.d.ts.map +1 -0
- package/dist/loader-utils/lib/sources/table-source-collection.js +5 -0
- package/dist/loader-utils/lib/sources/table-source-collection.js.map +1 -0
- package/dist/loader-utils/loader-types.d.ts +5 -5
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- package/dist/scan/arrow-execution/expressions.cjs +110 -0
- package/dist/scan/arrow-execution/expressions.cjs.map +7 -0
- package/dist/scan/arrow-execution/expressions.d.ts +9 -0
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -0
- package/dist/scan/arrow-execution/expressions.js +60 -0
- package/dist/scan/arrow-execution/expressions.js.map +1 -0
- package/dist/scan/arrow-execution/filter-arrow-table.cjs +266 -0
- package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +7 -0
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts +18 -0
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -0
- package/dist/scan/arrow-execution/filter-arrow-table.js +230 -0
- package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -0
- package/dist/scan/arrow-execution/project-arrow-table.cjs +70 -0
- package/dist/scan/arrow-execution/project-arrow-table.cjs.map +7 -0
- package/dist/scan/arrow-execution/project-arrow-table.d.ts +8 -0
- package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +1 -0
- package/dist/scan/arrow-execution/project-arrow-table.js +39 -0
- package/dist/scan/arrow-execution/project-arrow-table.js.map +1 -0
- package/dist/scan/arrow-execution.cjs +34 -0
- package/dist/scan/arrow-execution.cjs.map +7 -0
- package/dist/scan/arrow-execution.d.ts +4 -0
- package/dist/scan/arrow-execution.d.ts.map +1 -0
- package/dist/scan/arrow-execution.js +6 -0
- package/dist/scan/arrow-execution.js.map +1 -0
- package/dist/scan/arrow-query.cjs.map +1 -1
- package/dist/scan/arrow-query.d.ts +1 -1
- package/dist/scan/arrow-query.d.ts.map +1 -1
- package/dist/scan/catalog-query-source.cjs +122 -0
- package/dist/scan/catalog-query-source.cjs.map +7 -0
- package/dist/scan/catalog-query-source.d.ts +6 -0
- package/dist/scan/catalog-query-source.d.ts.map +1 -0
- package/dist/scan/catalog-query-source.js +115 -0
- package/dist/scan/catalog-query-source.js.map +1 -0
- package/dist/scan/federated-table-scan-source.cjs +4 -4
- package/dist/scan/federated-table-scan-source.cjs.map +2 -2
- package/dist/scan/federated-table-scan-source.d.ts +1 -1
- package/dist/scan/federated-table-scan-source.d.ts.map +1 -1
- package/dist/scan/federated-table-scan-source.js +4 -4
- package/dist/scan/federated-table-scan-source.js.map +1 -1
- package/dist/scan/index.cjs +188 -4
- package/dist/scan/index.cjs.map +4 -4
- package/dist/scan/index.d.ts +9 -2
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +4 -0
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/parse-sql-predicate.cjs +3 -294
- package/dist/scan/parse-sql-predicate.cjs.map +3 -3
- package/dist/scan/parse-sql-predicate.d.ts +6 -9
- package/dist/scan/parse-sql-predicate.d.ts.map +1 -1
- package/dist/scan/parse-sql-predicate.js +5 -314
- package/dist/scan/parse-sql-predicate.js.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.cjs +65 -0
- package/dist/scan/query-arrow-table-in-batches.cjs.map +7 -0
- package/dist/scan/query-arrow-table-in-batches.d.ts +8 -0
- package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -0
- package/dist/scan/query-arrow-table-in-batches.js +44 -0
- package/dist/scan/query-arrow-table-in-batches.js.map +1 -0
- package/dist/scan/query-arrow-table.cjs +52 -179
- package/dist/scan/query-arrow-table.cjs.map +3 -3
- package/dist/scan/query-arrow-table.d.ts +4 -37
- package/dist/scan/query-arrow-table.d.ts.map +1 -1
- package/dist/scan/query-arrow-table.js +37 -188
- package/dist/scan/query-arrow-table.js.map +1 -1
- package/dist/scan/query.cjs +344 -0
- package/dist/scan/query.cjs.map +7 -0
- package/dist/scan/query.d.ts +42 -0
- package/dist/scan/query.d.ts.map +1 -0
- package/dist/scan/query.js +367 -0
- package/dist/scan/query.js.map +1 -0
- package/dist/scan/resolve-query-source.cjs +59 -0
- package/dist/scan/resolve-query-source.cjs.map +7 -0
- package/dist/scan/resolve-query-source.d.ts +6 -0
- package/dist/scan/resolve-query-source.d.ts.map +1 -0
- package/dist/scan/resolve-query-source.js +37 -0
- package/dist/scan/resolve-query-source.js.map +1 -0
- package/dist/scan/sql-catalog.cjs +110 -0
- package/dist/scan/sql-catalog.cjs.map +7 -0
- package/dist/scan/sql-catalog.d.ts +47 -0
- package/dist/scan/sql-catalog.d.ts.map +1 -0
- package/dist/scan/sql-catalog.js +97 -0
- package/dist/scan/sql-catalog.js.map +1 -0
- package/dist/scan/table-query.cjs.map +2 -2
- package/dist/scan/table-query.d.ts +4 -1
- package/dist/scan/table-query.d.ts.map +1 -1
- package/dist/scan/table-query.js.map +1 -1
- package/dist/vector-table-scan-source.cjs +288 -193
- package/dist/vector-table-scan-source.cjs.map +3 -3
- package/dist/worker-utils/index.cjs +2 -1
- package/dist/worker-utils/index.cjs.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/library-utils/library-utils.js +1 -1
- package/dist/worker-utils/lib/library-utils/library-utils.js.map +1 -1
- package/package.json +17 -7
- package/src/loader-utils/index.ts +30 -6
- package/src/loader-utils/lib/files/http-file-transport.ts +65 -1
- package/src/loader-utils/lib/files/http-file-types.ts +2 -0
- package/src/loader-utils/lib/files/read-range-response.ts +66 -0
- package/src/loader-utils/lib/scan-utils/logical-table-query.ts +164 -0
- package/src/loader-utils/lib/scan-utils/query-options.ts +44 -0
- package/src/loader-utils/lib/scan-utils/scan-query-metadata.ts +17 -26
- package/src/loader-utils/lib/scan-utils/table-query.ts +49 -8
- package/src/loader-utils/lib/scan-utils/table-scan-batch.ts +25 -9
- package/src/loader-utils/lib/sources/data-source.ts +54 -1
- package/src/loader-utils/lib/sources/table-source-collection.ts +38 -0
- package/src/loader-utils/loader-types.ts +5 -5
- package/src/scan/arrow-execution/expressions.ts +86 -0
- package/src/scan/arrow-execution/filter-arrow-table.ts +309 -0
- package/src/scan/arrow-execution/project-arrow-table.ts +53 -0
- package/src/scan/arrow-execution.ts +7 -0
- package/src/scan/arrow-query.ts +3 -0
- package/src/scan/catalog-query-source.ts +132 -0
- package/src/scan/federated-table-scan-source.ts +19 -19
- package/src/scan/index.ts +28 -4
- package/src/scan/parse-sql-predicate.ts +14 -367
- package/src/scan/query-arrow-table-in-batches.ts +58 -0
- package/src/scan/query-arrow-table.ts +60 -237
- package/src/scan/query.ts +480 -0
- package/src/scan/resolve-query-source.ts +47 -0
- package/src/scan/sql-catalog.ts +167 -0
- package/src/scan/table-query.ts +6 -1
- package/src/worker-utils/lib/library-utils/library-utils.ts +1 -1
- package/dist/loader-utils/lib/scan-utils/experimental-scan-options.d.ts.map +0 -1
- package/dist/loader-utils/lib/scan-utils/experimental-scan-options.js.map +0 -1
- package/src/loader-utils/lib/scan-utils/experimental-scan-options.ts +0 -46
|
@@ -787,10 +787,246 @@ var SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES = Object.freeze({
|
|
|
787
787
|
});
|
|
788
788
|
|
|
789
789
|
// dist/scan/query-arrow-table.js
|
|
790
|
+
var arrow6 = __toESM(require("apache-arrow"), 1);
|
|
791
|
+
|
|
792
|
+
// dist/scan/arrow-execution/project-arrow-table.js
|
|
793
|
+
var arrow3 = __toESM(require("apache-arrow"), 1);
|
|
794
|
+
function projectArrowTable(source, selections) {
|
|
795
|
+
const outputNames = /* @__PURE__ */ new Set();
|
|
796
|
+
const indices = [];
|
|
797
|
+
const fields = selections.map((selection) => {
|
|
798
|
+
const column = typeof selection === "string" ? selection : selection.column;
|
|
799
|
+
const name = typeof selection === "string" ? selection : selection.as === void 0 ? column : selection.as;
|
|
800
|
+
const index = source.schema.fields.findIndex((field) => field.name === column);
|
|
801
|
+
if (index < 0)
|
|
802
|
+
throw new Error(`Arrow projection column not found: ${column}`);
|
|
803
|
+
if (typeof name !== "string" || typeof selection !== "string" && selection.as !== void 0 && !name.length || outputNames.has(name)) {
|
|
804
|
+
throw new Error(`Invalid or duplicate Arrow projection output name: ${name}`);
|
|
805
|
+
}
|
|
806
|
+
outputNames.add(name);
|
|
807
|
+
indices.push(index);
|
|
808
|
+
return source.schema.fields[index].clone({ name });
|
|
809
|
+
});
|
|
810
|
+
const schema = new arrow3.Schema(fields, source.schema.metadata);
|
|
811
|
+
const batches = source.batches.map((batch) => new arrow3.RecordBatch(schema, arrow3.makeData({
|
|
812
|
+
type: new arrow3.Struct(fields),
|
|
813
|
+
length: batch.numRows,
|
|
814
|
+
children: indices.map((index) => batch.data.children[index])
|
|
815
|
+
}), batch.metadata));
|
|
816
|
+
return new arrow3.Table(schema, batches);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// dist/scan/arrow-execution/filter-arrow-table.js
|
|
790
820
|
var arrow4 = __toESM(require("apache-arrow"), 1);
|
|
821
|
+
function filterArrowTable(source, predicate, options = {}) {
|
|
822
|
+
validateColumnarPredicate(predicate, new Set(source.schema.fields.map((field) => field.name)));
|
|
823
|
+
const columnNames = getColumnarPredicateColumns(predicate);
|
|
824
|
+
return filterArrowRows(source, (batch) => {
|
|
825
|
+
const columns = getPredicateColumns(new arrow4.Table(source.schema, [batch]), columnNames);
|
|
826
|
+
return (rowIndex) => evaluatePredicate(predicate, columns, rowIndex) === true;
|
|
827
|
+
}, options);
|
|
828
|
+
}
|
|
829
|
+
function filterArrowRows(source, selectBatch, options = {}) {
|
|
830
|
+
var _a, _b, _c;
|
|
831
|
+
let remaining = options.limit ?? Infinity;
|
|
832
|
+
if (remaining !== Infinity && (!Number.isSafeInteger(remaining) || remaining < 0)) {
|
|
833
|
+
throw new Error("Arrow filter limit must be a non-negative safe integer.");
|
|
834
|
+
}
|
|
835
|
+
(_a = options.signal) == null ? void 0 : _a.throwIfAborted();
|
|
836
|
+
const batches = [];
|
|
837
|
+
for (const batch of source.batches) {
|
|
838
|
+
if (remaining === 0)
|
|
839
|
+
break;
|
|
840
|
+
(_b = options.signal) == null ? void 0 : _b.throwIfAborted();
|
|
841
|
+
const data = new arrow4.Table(source.schema, [batch]);
|
|
842
|
+
const selectRow = selectBatch(batch);
|
|
843
|
+
const indices = [];
|
|
844
|
+
for (let rowIndex = 0; rowIndex < batch.numRows && indices.length < remaining; rowIndex++) {
|
|
845
|
+
(_c = options.signal) == null ? void 0 : _c.throwIfAborted();
|
|
846
|
+
if (selectRow(rowIndex))
|
|
847
|
+
indices.push(rowIndex);
|
|
848
|
+
}
|
|
849
|
+
remaining -= indices.length;
|
|
850
|
+
if (indices.length === 0)
|
|
851
|
+
continue;
|
|
852
|
+
if (indices.length === batch.numRows) {
|
|
853
|
+
batches.push(batch);
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (indices[indices.length - 1] - indices[0] + 1 === indices.length) {
|
|
857
|
+
batches.push(batch.slice(indices[0], indices[indices.length - 1] + 1));
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
const vectors = Object.fromEntries(source.schema.fields.map((field) => {
|
|
861
|
+
const vector = data.getChild(field.name);
|
|
862
|
+
return [
|
|
863
|
+
field.name,
|
|
864
|
+
arrow4.vectorFromArray(indices.map((index) => vector.get(index)), field.type)
|
|
865
|
+
];
|
|
866
|
+
}));
|
|
867
|
+
const gathered = new arrow4.Table(source.schema, vectors);
|
|
868
|
+
batches.push(...gathered.batches.map((output) => new arrow4.RecordBatch(source.schema, output.data, batch.metadata)));
|
|
869
|
+
}
|
|
870
|
+
return new arrow4.Table(source.schema, batches);
|
|
871
|
+
}
|
|
872
|
+
function getPredicateColumns(sourceTable, columnNames) {
|
|
873
|
+
const columns = {};
|
|
874
|
+
for (const columnName of columnNames) {
|
|
875
|
+
const column = sourceTable.getChild(columnName);
|
|
876
|
+
if (!column) {
|
|
877
|
+
throw new Error(`Arrow query column not found: ${columnName}`);
|
|
878
|
+
}
|
|
879
|
+
columns[columnName] = column;
|
|
880
|
+
}
|
|
881
|
+
return columns;
|
|
882
|
+
}
|
|
883
|
+
function evaluatePredicate(predicate, columns, rowIndex) {
|
|
884
|
+
if (isLogicalPredicate(predicate)) {
|
|
885
|
+
const values = predicate.args.map((child) => evaluatePredicate(child, columns, rowIndex));
|
|
886
|
+
return predicate.op === "and" ? evaluateAnd(values) : evaluateOr(values);
|
|
887
|
+
}
|
|
888
|
+
if (isNotPredicate(predicate)) {
|
|
889
|
+
const value2 = evaluatePredicate(predicate.args[0], columns, rowIndex);
|
|
890
|
+
return value2 === null ? null : !value2;
|
|
891
|
+
}
|
|
892
|
+
const value = getColumnValue(columns, predicate.args[0].property, rowIndex);
|
|
893
|
+
if (isNullPredicate(predicate)) {
|
|
894
|
+
return value === null || value === void 0;
|
|
895
|
+
}
|
|
896
|
+
if (isInPredicate(predicate)) {
|
|
897
|
+
return evaluateIn(value, predicate.args[1]);
|
|
898
|
+
}
|
|
899
|
+
return evaluateComparison(value, predicate);
|
|
900
|
+
}
|
|
901
|
+
function getColumnValue(columns, columnName, rowIndex) {
|
|
902
|
+
const path = typeof columnName === "string" ? [columnName] : columnName;
|
|
903
|
+
const column = columns[path[0]];
|
|
904
|
+
if (!column) {
|
|
905
|
+
throw new Error(`Arrow query could not read predicate column "${columnName}".`);
|
|
906
|
+
}
|
|
907
|
+
let value = column.get(rowIndex);
|
|
908
|
+
for (const property of path.slice(1)) {
|
|
909
|
+
if (value === null || value === void 0)
|
|
910
|
+
return null;
|
|
911
|
+
value = value[property];
|
|
912
|
+
}
|
|
913
|
+
return value;
|
|
914
|
+
}
|
|
915
|
+
function evaluateAnd(values) {
|
|
916
|
+
if (values.includes(false)) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
return values.includes(null) ? null : true;
|
|
920
|
+
}
|
|
921
|
+
function evaluateOr(values) {
|
|
922
|
+
if (values.includes(true)) {
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
return values.includes(null) ? null : false;
|
|
926
|
+
}
|
|
927
|
+
function evaluateIn(value, candidates) {
|
|
928
|
+
if (value === null || value === void 0) {
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
for (const candidate of candidates) {
|
|
932
|
+
if (compareValues(value, candidate) === 0) {
|
|
933
|
+
return true;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return false;
|
|
937
|
+
}
|
|
938
|
+
function evaluateComparison(value, predicate) {
|
|
939
|
+
if (value === null || value === void 0) {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
const comparison = compareValues(value, predicate.args[1]);
|
|
943
|
+
switch (predicate.op) {
|
|
944
|
+
case "=":
|
|
945
|
+
return comparison === 0;
|
|
946
|
+
case "<>":
|
|
947
|
+
return comparison !== 0;
|
|
948
|
+
case "<":
|
|
949
|
+
return comparison < 0;
|
|
950
|
+
case "<=":
|
|
951
|
+
return comparison <= 0;
|
|
952
|
+
case ">":
|
|
953
|
+
return comparison > 0;
|
|
954
|
+
case ">=":
|
|
955
|
+
return comparison >= 0;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function compareValues(left, right) {
|
|
959
|
+
if (isColumnarPredicateParameter(right)) {
|
|
960
|
+
throw new Error(`Arrow query parameter ":${right.parameter}" must be bound before query execution.`);
|
|
961
|
+
}
|
|
962
|
+
if (left instanceof Date && right instanceof Date) {
|
|
963
|
+
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
964
|
+
}
|
|
965
|
+
if (typeof left === "number" && right instanceof Date) {
|
|
966
|
+
return compareArrowQueryNumbers(left, right.getTime());
|
|
967
|
+
}
|
|
968
|
+
if (left instanceof Uint8Array && right instanceof Uint8Array) {
|
|
969
|
+
return compareBinary(left, right);
|
|
970
|
+
}
|
|
971
|
+
if (typeof left === "bigint" && typeof right === "bigint") {
|
|
972
|
+
return left === right ? 0 : left < right ? -1 : 1;
|
|
973
|
+
}
|
|
974
|
+
if (typeof left === "bigint" && typeof right === "number" || typeof left === "number" && typeof right === "bigint") {
|
|
975
|
+
const numericValue = typeof left === "number" ? left : right;
|
|
976
|
+
if (!Number.isFinite(numericValue))
|
|
977
|
+
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
978
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
979
|
+
}
|
|
980
|
+
if (typeof left === "number" && typeof right === "number") {
|
|
981
|
+
return compareArrowQueryNumbers(left, right);
|
|
982
|
+
}
|
|
983
|
+
if (typeof left === "string" && typeof right === "string") {
|
|
984
|
+
return left === right ? 0 : left < right ? -1 : 1;
|
|
985
|
+
}
|
|
986
|
+
if (typeof left === "boolean" && typeof right === "boolean") {
|
|
987
|
+
return Number(left) - Number(right);
|
|
988
|
+
}
|
|
989
|
+
throw new Error(`Arrow query cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)} values.`);
|
|
990
|
+
}
|
|
991
|
+
function compareArrowQueryNumbers(left, right) {
|
|
992
|
+
if (!Number.isFinite(left) || !Number.isFinite(right)) {
|
|
993
|
+
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
994
|
+
}
|
|
995
|
+
return left === right ? 0 : left < right ? -1 : 1;
|
|
996
|
+
}
|
|
997
|
+
function compareBinary(left, right) {
|
|
998
|
+
const commonLength = Math.min(left.length, right.length);
|
|
999
|
+
for (let index = 0; index < commonLength; index++) {
|
|
1000
|
+
if (left[index] !== right[index]) {
|
|
1001
|
+
return left[index] < right[index] ? -1 : 1;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return left.length === right.length ? 0 : left.length < right.length ? -1 : 1;
|
|
1005
|
+
}
|
|
1006
|
+
function getArrowQueryValueType(value) {
|
|
1007
|
+
if (value instanceof Date) {
|
|
1008
|
+
return "Date";
|
|
1009
|
+
}
|
|
1010
|
+
if (value instanceof Uint8Array) {
|
|
1011
|
+
return "Uint8Array";
|
|
1012
|
+
}
|
|
1013
|
+
return typeof value;
|
|
1014
|
+
}
|
|
1015
|
+
function isLogicalPredicate(predicate) {
|
|
1016
|
+
return predicate.op === "and" || predicate.op === "or";
|
|
1017
|
+
}
|
|
1018
|
+
function isNotPredicate(predicate) {
|
|
1019
|
+
return predicate.op === "not";
|
|
1020
|
+
}
|
|
1021
|
+
function isNullPredicate(predicate) {
|
|
1022
|
+
return predicate.op === "isNull";
|
|
1023
|
+
}
|
|
1024
|
+
function isInPredicate(predicate) {
|
|
1025
|
+
return predicate.op === "in";
|
|
1026
|
+
}
|
|
791
1027
|
|
|
792
1028
|
// dist/scan/rows-to-arrow.js
|
|
793
|
-
var
|
|
1029
|
+
var arrow5 = __toESM(require("apache-arrow"), 1);
|
|
794
1030
|
function convertRowsToArrowTable(rows) {
|
|
795
1031
|
const table = rows.length > 0 ? makeTableFromData(rows) : { shape: "object-row-table", schema: { fields: [], metadata: {} }, data: rows };
|
|
796
1032
|
const schema = deducePrimitiveAwareSchema(table);
|
|
@@ -798,13 +1034,13 @@ function convertRowsToArrowTable(rows) {
|
|
|
798
1034
|
return {
|
|
799
1035
|
shape: "arrow-table",
|
|
800
1036
|
schema,
|
|
801
|
-
data: new
|
|
1037
|
+
data: new arrow5.Table(new arrow5.Schema([]))
|
|
802
1038
|
};
|
|
803
1039
|
}
|
|
804
1040
|
return {
|
|
805
1041
|
shape: "arrow-table",
|
|
806
1042
|
schema,
|
|
807
|
-
data:
|
|
1043
|
+
data: arrow5.tableFromJSON(table.data)
|
|
808
1044
|
};
|
|
809
1045
|
}
|
|
810
1046
|
function deducePrimitiveAwareSchema(table) {
|
|
@@ -930,12 +1166,26 @@ function planTableQuery2(sourceColumnNames, options = {}) {
|
|
|
930
1166
|
}
|
|
931
1167
|
return planTableQuery(sourceColumnNames, options);
|
|
932
1168
|
}
|
|
933
|
-
function getSQLPredicateColumnNames(predicate) {
|
|
934
|
-
return getColumnarPredicateColumns(predicate);
|
|
935
|
-
}
|
|
936
1169
|
|
|
937
1170
|
// dist/scan/query-arrow-table.js
|
|
938
1171
|
function explainArrowTableQuery(sourceTable, options = {}) {
|
|
1172
|
+
if (options.select !== void 0) {
|
|
1173
|
+
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1174
|
+
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1175
|
+
}
|
|
1176
|
+
const projected = projectArrowTable(sourceTable.data, options.select);
|
|
1177
|
+
const columns = [
|
|
1178
|
+
...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
|
|
1179
|
+
];
|
|
1180
|
+
const { select, ...remainingOptions } = options;
|
|
1181
|
+
const explanation = explainArrowTableQuery(sourceTable, { ...remainingOptions, columns });
|
|
1182
|
+
const outputColumns = Object.freeze(projected.schema.fields.map((field) => field.name));
|
|
1183
|
+
return Object.freeze({
|
|
1184
|
+
...explanation,
|
|
1185
|
+
outputColumns,
|
|
1186
|
+
plan: Object.freeze(explanation.plan.map((step) => step.kind === "project" ? Object.freeze({ ...step, columns: outputColumns, select }) : step))
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
939
1189
|
if (options.predicate) {
|
|
940
1190
|
validateSQLPredicate(options.predicate);
|
|
941
1191
|
}
|
|
@@ -944,6 +1194,18 @@ function explainArrowTableQuery(sourceTable, options = {}) {
|
|
|
944
1194
|
function queryArrowTable(sourceTable, options = {}) {
|
|
945
1195
|
var _a, _b;
|
|
946
1196
|
throwIfAborted(options.signal);
|
|
1197
|
+
if (options.select !== void 0) {
|
|
1198
|
+
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1199
|
+
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1200
|
+
}
|
|
1201
|
+
projectArrowTable(sourceTable.data, options.select);
|
|
1202
|
+
const columns = [
|
|
1203
|
+
...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
|
|
1204
|
+
];
|
|
1205
|
+
const { select, ...remainingOptions } = options;
|
|
1206
|
+
const result = queryArrowTable(sourceTable, { ...remainingOptions, columns });
|
|
1207
|
+
return wrapArrowTable(projectArrowTable(result.data, select));
|
|
1208
|
+
}
|
|
947
1209
|
if (options.join) {
|
|
948
1210
|
validateArrowJoinQuery(sourceTable, options);
|
|
949
1211
|
}
|
|
@@ -959,33 +1221,14 @@ function queryArrowTable(sourceTable, options = {}) {
|
|
|
959
1221
|
const sourceData = sourceTable.data;
|
|
960
1222
|
const plan = planTableQuery2(sourceData.schema.fields.map((field) => field.name), options);
|
|
961
1223
|
const scannedData = sourceData.select([...getScanStep(plan).columns]);
|
|
962
|
-
const projectedData = scannedData.select([...getProjectStep(plan).columns]);
|
|
963
1224
|
const predicate = (_a = getFilterStep(plan)) == null ? void 0 : _a.predicate;
|
|
964
1225
|
const limit = ((_b = getLimitStep(plan)) == null ? void 0 : _b.limit) ?? Number.POSITIVE_INFINITY;
|
|
965
1226
|
if (!predicate) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
const predicateColumns = getPredicateColumns(scannedData, getSQLPredicateColumnNames(predicate));
|
|
969
|
-
const matchingRowIndices = [];
|
|
970
|
-
for (let rowIndex = 0; rowIndex < scannedData.numRows && matchingRowIndices.length < limit; rowIndex++) {
|
|
971
|
-
throwIfAborted(options.signal);
|
|
972
|
-
if (evaluatePredicate(predicate, predicateColumns, rowIndex) === true) {
|
|
973
|
-
matchingRowIndices.push(rowIndex);
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
if (matchingRowIndices.length === 0) {
|
|
977
|
-
return wrapArrowTable(projectedData.slice(0, 0));
|
|
1227
|
+
const projectedData = projectArrowTable(scannedData, getProjectStep(plan).columns);
|
|
1228
|
+
return wrapArrowTable(projectedData.numRows === 0 ? projectedData : projectedData.slice(0, limit));
|
|
978
1229
|
}
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
const sourceColumn = projectedData.getChild(field.name);
|
|
982
|
-
if (!sourceColumn) {
|
|
983
|
-
throw new Error(`Arrow query could not read column "${field.name}".`);
|
|
984
|
-
}
|
|
985
|
-
const values = matchingRowIndices.map((rowIndex) => sourceColumn.get(rowIndex));
|
|
986
|
-
outputColumns[field.name] = arrow4.vectorFromArray(values, sourceColumn.type);
|
|
987
|
-
}
|
|
988
|
-
return wrapArrowTable(new arrow4.Table(projectedData.schema, outputColumns));
|
|
1230
|
+
const filteredData = filterArrowTable(scannedData, predicate, { limit, signal: options.signal });
|
|
1231
|
+
return wrapArrowTable(projectArrowTable(filteredData, getProjectStep(plan).columns));
|
|
989
1232
|
}
|
|
990
1233
|
function queryArrowTableRelational(sourceTable, options) {
|
|
991
1234
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -1117,7 +1360,7 @@ function queryArrowJoin(sourceTable, options) {
|
|
|
1117
1360
|
const limitedRows = outputRows.slice(0, options.limit);
|
|
1118
1361
|
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceTable.data, outputColumns, options, new Map(rightResult.data.schema.fields.map((field) => [
|
|
1119
1362
|
`${rightPrefix}${field.name}`,
|
|
1120
|
-
new
|
|
1363
|
+
new arrow6.Field(`${rightPrefix}${field.name}`, field.type, field.nullable, field.metadata)
|
|
1121
1364
|
])));
|
|
1122
1365
|
}
|
|
1123
1366
|
function validateArrowJoinQuery(sourceTable, options) {
|
|
@@ -1224,16 +1467,16 @@ function compareRows(left, right, orderBy) {
|
|
|
1224
1467
|
}
|
|
1225
1468
|
function compareSortValues(left, right) {
|
|
1226
1469
|
if (left instanceof Date && right instanceof Date)
|
|
1227
|
-
return
|
|
1470
|
+
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
1228
1471
|
if (typeof left === "bigint" && typeof right === "bigint")
|
|
1229
1472
|
return left === right ? 0 : left < right ? -1 : 1;
|
|
1230
1473
|
if (typeof left === "number" && typeof right === "number")
|
|
1231
|
-
return
|
|
1474
|
+
return compareArrowQueryNumbers(left, right);
|
|
1232
1475
|
if (typeof left === "string" && typeof right === "string")
|
|
1233
1476
|
return left === right ? 0 : left < right ? -1 : 1;
|
|
1234
1477
|
if (typeof left === "boolean" && typeof right === "boolean")
|
|
1235
1478
|
return Number(left) - Number(right);
|
|
1236
|
-
throw new Error(`Arrow relational order cannot compare ${
|
|
1479
|
+
throw new Error(`Arrow relational order cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)}.`);
|
|
1237
1480
|
}
|
|
1238
1481
|
function aggregateRows(rows, groupBy, aggregates) {
|
|
1239
1482
|
const groups = /* @__PURE__ */ new Map();
|
|
@@ -1279,37 +1522,37 @@ function createEmptyRelationalResult(sourceData, outputColumns, options, additio
|
|
|
1279
1522
|
return additionalField;
|
|
1280
1523
|
const expression = expressions.get(columnName);
|
|
1281
1524
|
if (expression)
|
|
1282
|
-
return new
|
|
1525
|
+
return new arrow6.Field(columnName, getExpressionType(expression, sourceFields), true);
|
|
1283
1526
|
const aggregate = aggregates.get(columnName);
|
|
1284
1527
|
if (aggregate)
|
|
1285
|
-
return new
|
|
1286
|
-
return new
|
|
1528
|
+
return new arrow6.Field(columnName, getAggregateType(aggregate, sourceFields), true);
|
|
1529
|
+
return new arrow6.Field(columnName, new arrow6.Utf8(), true);
|
|
1287
1530
|
});
|
|
1288
1531
|
const columns = {};
|
|
1289
1532
|
for (const field of fields)
|
|
1290
|
-
columns[field.name] =
|
|
1291
|
-
return wrapArrowTable(new
|
|
1533
|
+
columns[field.name] = arrow6.vectorFromArray([], field.type);
|
|
1534
|
+
return wrapArrowTable(new arrow6.Table(new arrow6.Schema(fields), columns));
|
|
1292
1535
|
}
|
|
1293
1536
|
function getExpressionType(expression, sourceFields) {
|
|
1294
1537
|
var _a;
|
|
1295
1538
|
if (expression.expression.op === "literal") {
|
|
1296
1539
|
const value = expression.expression.value;
|
|
1297
1540
|
if (typeof value === "boolean")
|
|
1298
|
-
return new
|
|
1541
|
+
return new arrow6.Bool();
|
|
1299
1542
|
if (typeof value === "number")
|
|
1300
|
-
return new
|
|
1301
|
-
return new
|
|
1543
|
+
return new arrow6.Float64();
|
|
1544
|
+
return new arrow6.Utf8();
|
|
1302
1545
|
}
|
|
1303
1546
|
if (expression.expression.op === "column") {
|
|
1304
|
-
return ((_a = sourceFields.get(expression.expression.column)) == null ? void 0 : _a.type) || new
|
|
1547
|
+
return ((_a = sourceFields.get(expression.expression.column)) == null ? void 0 : _a.type) || new arrow6.Utf8();
|
|
1305
1548
|
}
|
|
1306
|
-
return new
|
|
1549
|
+
return new arrow6.Float64();
|
|
1307
1550
|
}
|
|
1308
1551
|
function getAggregateType(aggregate, sourceFields) {
|
|
1309
1552
|
var _a;
|
|
1310
1553
|
if (aggregate.function === "count")
|
|
1311
|
-
return new
|
|
1312
|
-
return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new
|
|
1554
|
+
return new arrow6.Int32();
|
|
1555
|
+
return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new arrow6.Float64() : new arrow6.Float64();
|
|
1313
1556
|
}
|
|
1314
1557
|
function evaluateAggregate(aggregate, rows) {
|
|
1315
1558
|
if (aggregate.function === "count")
|
|
@@ -1331,154 +1574,6 @@ function evaluateAggregate(aggregate, rows) {
|
|
|
1331
1574
|
return Math.max(...numericValues);
|
|
1332
1575
|
}
|
|
1333
1576
|
}
|
|
1334
|
-
function getPredicateColumns(sourceTable, columnNames) {
|
|
1335
|
-
const columns = {};
|
|
1336
|
-
for (const columnName of columnNames) {
|
|
1337
|
-
const column = sourceTable.getChild(columnName);
|
|
1338
|
-
if (!column) {
|
|
1339
|
-
throw new Error(`Arrow query column not found: ${columnName}`);
|
|
1340
|
-
}
|
|
1341
|
-
columns[columnName] = column;
|
|
1342
|
-
}
|
|
1343
|
-
return columns;
|
|
1344
|
-
}
|
|
1345
|
-
function evaluatePredicate(predicate, columns, rowIndex) {
|
|
1346
|
-
if (isLogicalPredicate(predicate)) {
|
|
1347
|
-
const values = predicate.args.map((child) => evaluatePredicate(child, columns, rowIndex));
|
|
1348
|
-
return predicate.op === "and" ? evaluateAnd(values) : evaluateOr(values);
|
|
1349
|
-
}
|
|
1350
|
-
if (isNotPredicate(predicate)) {
|
|
1351
|
-
const value2 = evaluatePredicate(predicate.args[0], columns, rowIndex);
|
|
1352
|
-
return value2 === null ? null : !value2;
|
|
1353
|
-
}
|
|
1354
|
-
const value = getColumnValue(columns, predicate.args[0].property, rowIndex);
|
|
1355
|
-
if (isNullPredicate(predicate)) {
|
|
1356
|
-
return value === null;
|
|
1357
|
-
}
|
|
1358
|
-
if (isInPredicate(predicate)) {
|
|
1359
|
-
return evaluateIn(value, predicate.args[1]);
|
|
1360
|
-
}
|
|
1361
|
-
return evaluateComparison(value, predicate);
|
|
1362
|
-
}
|
|
1363
|
-
function getColumnValue(columns, columnName, rowIndex) {
|
|
1364
|
-
const column = columns[columnName];
|
|
1365
|
-
if (!column) {
|
|
1366
|
-
throw new Error(`Arrow query could not read predicate column "${columnName}".`);
|
|
1367
|
-
}
|
|
1368
|
-
return column.get(rowIndex);
|
|
1369
|
-
}
|
|
1370
|
-
function evaluateAnd(values) {
|
|
1371
|
-
if (values.includes(false)) {
|
|
1372
|
-
return false;
|
|
1373
|
-
}
|
|
1374
|
-
return values.includes(null) ? null : true;
|
|
1375
|
-
}
|
|
1376
|
-
function evaluateOr(values) {
|
|
1377
|
-
if (values.includes(true)) {
|
|
1378
|
-
return true;
|
|
1379
|
-
}
|
|
1380
|
-
return values.includes(null) ? null : false;
|
|
1381
|
-
}
|
|
1382
|
-
function evaluateIn(value, candidates) {
|
|
1383
|
-
if (value === null || value === void 0) {
|
|
1384
|
-
return null;
|
|
1385
|
-
}
|
|
1386
|
-
for (const candidate of candidates) {
|
|
1387
|
-
if (compareValues(value, candidate) === 0) {
|
|
1388
|
-
return true;
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
return false;
|
|
1392
|
-
}
|
|
1393
|
-
function evaluateComparison(value, predicate) {
|
|
1394
|
-
if (value === null || value === void 0) {
|
|
1395
|
-
return null;
|
|
1396
|
-
}
|
|
1397
|
-
const comparison = compareValues(value, predicate.args[1]);
|
|
1398
|
-
switch (predicate.op) {
|
|
1399
|
-
case "=":
|
|
1400
|
-
return comparison === 0;
|
|
1401
|
-
case "<>":
|
|
1402
|
-
return comparison !== 0;
|
|
1403
|
-
case "<":
|
|
1404
|
-
return comparison < 0;
|
|
1405
|
-
case "<=":
|
|
1406
|
-
return comparison <= 0;
|
|
1407
|
-
case ">":
|
|
1408
|
-
return comparison > 0;
|
|
1409
|
-
case ">=":
|
|
1410
|
-
return comparison >= 0;
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
function compareValues(left, right) {
|
|
1414
|
-
if (isSQLPredicateParameter(right)) {
|
|
1415
|
-
throw new Error(`Arrow query parameter ":${right.parameter}" must be bound before query execution.`);
|
|
1416
|
-
}
|
|
1417
|
-
if (left instanceof Date && right instanceof Date) {
|
|
1418
|
-
return compareNumbers(left.getTime(), right.getTime());
|
|
1419
|
-
}
|
|
1420
|
-
if (typeof left === "number" && right instanceof Date) {
|
|
1421
|
-
return compareNumbers(left, right.getTime());
|
|
1422
|
-
}
|
|
1423
|
-
if (left instanceof Uint8Array && right instanceof Uint8Array) {
|
|
1424
|
-
return compareBinary(left, right);
|
|
1425
|
-
}
|
|
1426
|
-
if (typeof left === "bigint" && typeof right === "bigint") {
|
|
1427
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1428
|
-
}
|
|
1429
|
-
if (typeof left === "bigint" && typeof right === "number" && Number.isSafeInteger(right)) {
|
|
1430
|
-
return compareValues(left, BigInt(right));
|
|
1431
|
-
}
|
|
1432
|
-
if (typeof left === "number" && typeof right === "bigint" && Number.isSafeInteger(left)) {
|
|
1433
|
-
return compareValues(BigInt(left), right);
|
|
1434
|
-
}
|
|
1435
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
1436
|
-
return compareNumbers(left, right);
|
|
1437
|
-
}
|
|
1438
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
1439
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1440
|
-
}
|
|
1441
|
-
if (typeof left === "boolean" && typeof right === "boolean") {
|
|
1442
|
-
return Number(left) - Number(right);
|
|
1443
|
-
}
|
|
1444
|
-
throw new Error(`Arrow query cannot compare ${getValueType(left)} with ${getValueType(right)} values.`);
|
|
1445
|
-
}
|
|
1446
|
-
function compareNumbers(left, right) {
|
|
1447
|
-
if (!Number.isFinite(left) || !Number.isFinite(right)) {
|
|
1448
|
-
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
1449
|
-
}
|
|
1450
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1451
|
-
}
|
|
1452
|
-
function compareBinary(left, right) {
|
|
1453
|
-
const commonLength = Math.min(left.length, right.length);
|
|
1454
|
-
for (let index = 0; index < commonLength; index++) {
|
|
1455
|
-
if (left[index] !== right[index]) {
|
|
1456
|
-
return left[index] < right[index] ? -1 : 1;
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
return left.length === right.length ? 0 : left.length < right.length ? -1 : 1;
|
|
1460
|
-
}
|
|
1461
|
-
function getValueType(value) {
|
|
1462
|
-
if (value instanceof Date) {
|
|
1463
|
-
return "Date";
|
|
1464
|
-
}
|
|
1465
|
-
if (value instanceof Uint8Array) {
|
|
1466
|
-
return "Uint8Array";
|
|
1467
|
-
}
|
|
1468
|
-
return typeof value;
|
|
1469
|
-
}
|
|
1470
|
-
function isLogicalPredicate(predicate) {
|
|
1471
|
-
return predicate.op === "and" || predicate.op === "or";
|
|
1472
|
-
}
|
|
1473
|
-
function isNotPredicate(predicate) {
|
|
1474
|
-
return predicate.op === "not";
|
|
1475
|
-
}
|
|
1476
|
-
function isNullPredicate(predicate) {
|
|
1477
|
-
return predicate.op === "isNull";
|
|
1478
|
-
}
|
|
1479
|
-
function isInPredicate(predicate) {
|
|
1480
|
-
return predicate.op === "in";
|
|
1481
|
-
}
|
|
1482
1577
|
function getScanStep(plan) {
|
|
1483
1578
|
const step = plan.find((candidate) => candidate.kind === "scan");
|
|
1484
1579
|
if (!step) {
|