@dremio/js-sdk 0.22.0 → 0.23.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.
- package/dist/oss/jobs/Job.d.ts +5 -4
- package/dist/oss/jobs/Job.js +6 -5
- package/dist/oss/jobs/Job.js.map +1 -1
- package/dist/oss/jobs/utils/JSONValue.d.ts +3 -0
- package/dist/oss/jobs/utils/JSONValue.js +17 -0
- package/dist/oss/jobs/utils/JSONValue.js.map +1 -0
- package/dist/oss/jobs/utils/JobResultsResponse.d.ts +2 -1
- package/dist/oss/jobs/utils/JobResultsResponse.js.map +1 -1
- package/dist/oss/jobs/utils/mapRowData.d.ts +4 -0
- package/dist/oss/jobs/utils/mapRowData.js +10 -2
- package/dist/oss/jobs/utils/mapRowData.js.map +1 -1
- package/dist/oss/jobs/utils/mapRowsToColumns.d.ts +2 -1
- package/dist/oss/jobs/utils/mapRowsToColumns.js.map +1 -1
- package/package.json +1 -1
package/dist/oss/jobs/Job.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SonarV3Config } from "../../common/Config.ts";
|
|
2
2
|
import { Err, Ok, Result } from "ts-results-es";
|
|
3
3
|
import { type Observable } from "rxjs";
|
|
4
|
+
import { type MappedFieldValue } from "./utils/mapRowData.ts";
|
|
4
5
|
import type { SignalParam } from "../../common/Params.ts";
|
|
5
6
|
import type { JobProperties } from "./utils/jobEntityToProperties.ts";
|
|
6
7
|
import type { HttpError } from "../../common/HttpError.ts";
|
|
@@ -22,14 +23,14 @@ export declare class Job {
|
|
|
22
23
|
constructor(properties: JobProperties, config: SonarV3Config, observe: (id: string) => Observable<Result<Job, HttpError>>);
|
|
23
24
|
get settled(): boolean;
|
|
24
25
|
get results(): {
|
|
25
|
-
jsonBatches: <T extends Record<string,
|
|
26
|
+
jsonBatches: <T extends Record<string, MappedFieldValue> = Record<string, string | number | bigint | boolean | import("temporal-polyfill").Temporal.PlainDateTime | import("temporal-polyfill").Temporal.PlainDate | import("temporal-polyfill").Temporal.PlainTime | null>>(args?: {
|
|
26
27
|
limit?: number;
|
|
27
28
|
offset?: number;
|
|
28
29
|
}, { signal }?: SignalParam) => AsyncGenerator<{
|
|
29
|
-
readonly columns: Record<
|
|
30
|
+
readonly columns: Record<string, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
|
|
30
31
|
readonly rows: T[];
|
|
31
32
|
readonly schema: {
|
|
32
|
-
fields: import("./utils/JobResultsResponse.ts").JobResultsSchema<Extract<keyof T, string>>;
|
|
33
|
+
readonly fields: import("./utils/JobResultsResponse.ts").JobResultsSchema<Extract<keyof T, string>>;
|
|
33
34
|
};
|
|
34
35
|
readonly totalRows: number;
|
|
35
36
|
}, void, unknown>;
|
|
@@ -37,7 +38,7 @@ export declare class Job {
|
|
|
37
38
|
schema: import("./utils/JobResultsResponse.ts").JobResultsSchema<string>;
|
|
38
39
|
totalRows: number;
|
|
39
40
|
}, HttpError>>;
|
|
40
|
-
slice: <T extends Record<string,
|
|
41
|
+
slice: <T extends Record<string, MappedFieldValue> = Record<string, string | number | bigint | boolean | import("temporal-polyfill").Temporal.PlainDateTime | import("temporal-polyfill").Temporal.PlainDate | import("temporal-polyfill").Temporal.PlainTime | null>>(start?: number, end?: number, { signal }?: SignalParam) => Promise<Ok<T[]> | Err<unknown>>;
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* @returns A `Job` instance once it's reached a settled state
|
package/dist/oss/jobs/Job.js
CHANGED
|
@@ -105,18 +105,19 @@ export class Job {
|
|
|
105
105
|
const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);
|
|
106
106
|
const batch = (await this.#config
|
|
107
107
|
.sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })
|
|
108
|
-
.map((res) => res.json())
|
|
108
|
+
.map((res) => res.json())
|
|
109
|
+
.promise).unwrap();
|
|
109
110
|
offset += batch.rows.length;
|
|
110
111
|
hasMore = batch.rows.length === batch_size;
|
|
111
112
|
if (batch.rows.length) {
|
|
112
|
-
const
|
|
113
|
-
mapRowData(batch.rows,
|
|
113
|
+
const batchT = batch;
|
|
114
|
+
mapRowData(batch.rows, batchT.schema);
|
|
114
115
|
yield {
|
|
115
116
|
get columns() {
|
|
116
117
|
return mapRowsToColumns(batch);
|
|
117
118
|
},
|
|
118
|
-
rows:
|
|
119
|
-
schema,
|
|
119
|
+
rows: batchT.rows,
|
|
120
|
+
schema: { fields: batchT.schema },
|
|
120
121
|
totalRows: batch.rowCount,
|
|
121
122
|
};
|
|
122
123
|
}
|
package/dist/oss/jobs/Job.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAmB,MAAM,MAAM,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,MAAM,OAAO,GAAG;IACL,YAAY,CAAgC;IAC5C,kBAAkB,CAAsC;IACxD,YAAY,CAAU;IACtB,OAAO,CAA2B;IAClC,EAAE,CAAsB;IACxB,OAAO,CAA2B;IAClC,SAAS,CAA6B;IACtC,yBAAyB,CAA6C;IACtE,2BAA2B,CAA+C;IAC1E,QAAQ,CAA4B;IACpC,SAAS,CAA6B;IACtC,KAAK,CAAyB;IAEvB,QAAQ,CAAkB;IAC1C,OAAO,CAAgB;IAEvB,YACE,UAAyB,EACzB,MAAqB,EACrB,OAA2D;QAE3D,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C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AAC,OAAO,IAAI,CAAC,EAAE,2BAA2B,EAAE,EAAE,MAAM,EAAE,CAAC;aACrE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAiC,CAAC;aACvD,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAClB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,SAAS,EAAE,QAAQ,CAAC,QAAQ;SAC7B,CAAC,CAAC,CAAC,OAAO,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CACV,QAAgB,CAAC,EACjB,MAAc,QAAQ,EACtB,EAAE,MAAM,KAAkB,EAAE;QAE5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAQ,EAAE,CAAC;YACrB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,CACzC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EACrC,EAAE,MAAM,EAAE,CACX,EAAE,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE;YACvC,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,MAAM;SACf,CAAC;aACD,GAAG,CAAC,GAAG,EAAE,CAAC,SAAiB,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,cAAc,GAAG,GAAG,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { Err, Ok, Result } from \"ts-results-es\";\nimport { lastValueFrom, map, of, switchMap, type Observable } from \"rxjs\";\nimport type { JobResultsResponse } from \"./utils/JobResultsResponse.ts\";\nimport { mapRowsToColumns } from \"./utils/mapRowsToColumns.ts\";\nimport { mapRowData } from \"./utils/mapRowData.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport type { JobProperties } from \"./utils/jobEntityToProperties.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\n { signal }: SignalParam = {},\n ) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<T>>).promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const schema = { fields: batch.schema };\n mapRowData(batch.rows, batch.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batch.rows,\n schema,\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined as void).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|
|
1
|
+
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAmB,MAAM,MAAM,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAyB,MAAM,uBAAuB,CAAC;AAM1E,MAAM,OAAO,GAAG;IACL,YAAY,CAAgC;IAC5C,kBAAkB,CAAsC;IACxD,YAAY,CAAU;IACtB,OAAO,C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I,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE;YACvC,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,MAAM;SACf,CAAC;aACD,GAAG,CAAC,GAAG,EAAE,CAAC,SAAiB,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,cAAc,GAAG,GAAG,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { Err, Ok, Result } from \"ts-results-es\";\nimport { lastValueFrom, map, of, switchMap, type Observable } from \"rxjs\";\nimport type { JobResultsResponse } from \"./utils/JobResultsResponse.ts\";\nimport { mapRowsToColumns } from \"./utils/mapRowsToColumns.ts\";\nimport { mapRowData, type MappedFieldValue } from \"./utils/mapRowData.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport type { JobProperties } from \"./utils/jobEntityToProperties.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport type { JSONValue } from \"./utils/JSONValue.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<\n T extends Record<string, MappedFieldValue> = Record<string, MappedFieldValue>,\n >(args: { limit?: number; offset?: number } = {}, { signal }: SignalParam = {}) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<Record<string, JSONValue>>>)\n .promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const batchT = batch as unknown as JobResultsResponse<T>;\n mapRowData(batch.rows, batchT.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batchT.rows,\n schema: { fields: batchT.schema },\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, MappedFieldValue> = Record<string, MappedFieldValue>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined as void).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024-2025 Dremio Corporation
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=JSONValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONValue.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JSONValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | JSONValue[]\n | { [key: string]: JSONValue };\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JSONValue } from "./JSONValue.ts";
|
|
1
2
|
type VarcharType = {
|
|
2
3
|
name: "VARCHAR";
|
|
3
4
|
};
|
|
@@ -77,7 +78,7 @@ export type JobResultsSchema<TName extends string = string> = {
|
|
|
77
78
|
name: TName;
|
|
78
79
|
type: SimpleTypes | ComplexTypes;
|
|
79
80
|
}[];
|
|
80
|
-
export type JobResultsResponse<T extends Record<string, unknown> = Record<string,
|
|
81
|
+
export type JobResultsResponse<T extends Record<string, unknown> = Record<string, JSONValue>> = {
|
|
81
82
|
rowCount: number;
|
|
82
83
|
rows: T[];
|
|
83
84
|
schema: JobResultsSchema<Extract<keyof T, string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JobResultsResponse.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JobResultsResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\ntype VarcharType = {\n name: \"VARCHAR\";\n};\n\ntype TextType = {\n name: \"TEXT\";\n};\n\ntype BinaryType = {\n name: \"BINARY\";\n};\n\ntype VarbinaryType = {\n name: \"VARBINARY\";\n};\n\ntype FloatType = {\n name: \"FLOAT\";\n};\n\ntype DecimalType = {\n name: \"DECIMAL\";\n};\n\ntype IntegerType = {\n name: \"INTEGER\";\n};\n\ntype MixedType = {\n name: \"MIXED\";\n};\n\ntype UnionType = {\n name: \"UNION\";\n};\n\ntype DateType = {\n name: \"DATE\";\n};\n\ntype TimeType = {\n name: \"TIME\";\n};\n\ntype DatetimeType = {\n name: \"DATETIME\";\n};\n\ntype MapType = {\n name: \"MAP\";\n};\n\ntype GeoType = {\n name: \"GEO\";\n};\n\ntype OtherType = {\n name: \"OTHER\";\n};\n\ntype AnyType = {\n name: \"ANY\";\n};\n\ntype DoubleType = {\n name: \"DOUBLE\";\n};\n\ntype BigintType = {\n name: \"BIGINT\";\n};\n\ntype BooleanType = {\n name: \"BOOLEAN\";\n};\n\ntype TimestampType = {\n name: \"TIMESTAMP\";\n};\n\ntype SimpleTypes =\n | VarcharType\n | DoubleType\n | BigintType\n | BooleanType\n | TimestampType\n | TextType\n | BinaryType\n | VarbinaryType\n | FloatType\n | DecimalType\n | IntegerType\n | MixedType\n | UnionType\n | DateType\n | TimeType\n | DatetimeType\n | MapType\n | GeoType\n | OtherType\n | AnyType;\n\ntype ListType = {\n name: \"LIST\";\n subSchema: {\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype StructType = {\n name: \"STRUCT\";\n subSchema: {\n name: string;\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype ComplexTypes = ListType | StructType;\n\nexport type JobResultsSchema<TName extends string = string> = {\n name: TName;\n type: SimpleTypes | ComplexTypes;\n}[];\n\nexport type JobResultsResponse<T extends Record<string, unknown> = Record<string,
|
|
1
|
+
{"version":3,"file":"JobResultsResponse.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JobResultsResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { JSONValue } from \"./JSONValue.ts\";\n\ntype VarcharType = {\n name: \"VARCHAR\";\n};\n\ntype TextType = {\n name: \"TEXT\";\n};\n\ntype BinaryType = {\n name: \"BINARY\";\n};\n\ntype VarbinaryType = {\n name: \"VARBINARY\";\n};\n\ntype FloatType = {\n name: \"FLOAT\";\n};\n\ntype DecimalType = {\n name: \"DECIMAL\";\n};\n\ntype IntegerType = {\n name: \"INTEGER\";\n};\n\ntype MixedType = {\n name: \"MIXED\";\n};\n\ntype UnionType = {\n name: \"UNION\";\n};\n\ntype DateType = {\n name: \"DATE\";\n};\n\ntype TimeType = {\n name: \"TIME\";\n};\n\ntype DatetimeType = {\n name: \"DATETIME\";\n};\n\ntype MapType = {\n name: \"MAP\";\n};\n\ntype GeoType = {\n name: \"GEO\";\n};\n\ntype OtherType = {\n name: \"OTHER\";\n};\n\ntype AnyType = {\n name: \"ANY\";\n};\n\ntype DoubleType = {\n name: \"DOUBLE\";\n};\n\ntype BigintType = {\n name: \"BIGINT\";\n};\n\ntype BooleanType = {\n name: \"BOOLEAN\";\n};\n\ntype TimestampType = {\n name: \"TIMESTAMP\";\n};\n\ntype SimpleTypes =\n | VarcharType\n | DoubleType\n | BigintType\n | BooleanType\n | TimestampType\n | TextType\n | BinaryType\n | VarbinaryType\n | FloatType\n | DecimalType\n | IntegerType\n | MixedType\n | UnionType\n | DateType\n | TimeType\n | DatetimeType\n | MapType\n | GeoType\n | OtherType\n | AnyType;\n\ntype ListType = {\n name: \"LIST\";\n subSchema: {\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype StructType = {\n name: \"STRUCT\";\n subSchema: {\n name: string;\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype ComplexTypes = ListType | StructType;\n\nexport type JobResultsSchema<TName extends string = string> = {\n name: TName;\n type: SimpleTypes | ComplexTypes;\n}[];\n\nexport type JobResultsResponse<T extends Record<string, unknown> = Record<string, JSONValue>> = {\n rowCount: number;\n rows: T[];\n schema: JobResultsSchema<Extract<keyof T, string>>;\n};\n"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import type { JobResultsResponse } from "./JobResultsResponse.ts";
|
|
2
|
+
import { Temporal } from "temporal-polyfill";
|
|
3
|
+
declare const mapFieldValue: (fieldType: JobResultsResponse["schema"][number]["type"]["name"], fieldValue: unknown) => string | number | bigint | boolean | Temporal.PlainDateTime | Temporal.PlainDate | Temporal.PlainTime | null;
|
|
4
|
+
export type MappedFieldValue = ReturnType<typeof mapFieldValue>;
|
|
2
5
|
export declare const createRowTypeMapper: (schema: JobResultsResponse["schema"]) => (row: Record<string, unknown>) => void;
|
|
3
6
|
export declare const mapRowData: (rows: JobResultsResponse["rows"], schema: JobResultsResponse["schema"]) => void;
|
|
7
|
+
export {};
|
|
@@ -13,13 +13,21 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { Temporal } from "temporal-polyfill";
|
|
16
17
|
const mapFieldValue = (fieldType, fieldValue) => {
|
|
17
|
-
if (fieldValue === null) {
|
|
18
|
+
if (fieldValue === null || fieldValue === undefined) {
|
|
18
19
|
return null;
|
|
19
20
|
}
|
|
20
21
|
switch (fieldType) {
|
|
21
22
|
case "TIMESTAMP":
|
|
22
|
-
|
|
23
|
+
// Example: 2000-01-01 17:30:50.123
|
|
24
|
+
return Temporal.PlainDateTime.from(fieldValue.replace(" ", "T"));
|
|
25
|
+
case "DATE":
|
|
26
|
+
// Example: 2000-01-01
|
|
27
|
+
return Temporal.PlainDate.from(fieldValue);
|
|
28
|
+
case "TIME":
|
|
29
|
+
// Example: 17:30:50.235
|
|
30
|
+
return Temporal.PlainTime.from(fieldValue);
|
|
23
31
|
case "BIGINT":
|
|
24
32
|
return BigInt(fieldValue);
|
|
25
33
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapRowData.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"mapRowData.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO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AAC;QAC1E,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAgC,EAChC,MAAoC,EAC9B,EAAE;IACR,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,SAAS,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\nimport { Temporal } from \"temporal-polyfill\";\n\nconst mapFieldValue = (\n fieldType: JobResultsResponse[\"schema\"][number][\"type\"][\"name\"],\n fieldValue: unknown,\n) => {\n if (fieldValue === null || fieldValue === undefined) {\n return null;\n }\n switch (fieldType) {\n case \"TIMESTAMP\":\n // Example: 2000-01-01 17:30:50.123\n return Temporal.PlainDateTime.from((fieldValue as string).replace(\" \", \"T\"));\n case \"DATE\":\n // Example: 2000-01-01\n return Temporal.PlainDate.from(fieldValue as string);\n case \"TIME\":\n // Example: 17:30:50.235\n return Temporal.PlainTime.from(fieldValue as string);\n case \"BIGINT\":\n return BigInt(fieldValue as string | number);\n default:\n return fieldValue as string | number | boolean;\n }\n};\n\nexport type MappedFieldValue = ReturnType<typeof mapFieldValue>;\n\nexport const createRowTypeMapper = (schema: JobResultsResponse[\"schema\"]) => {\n const fieldTypes = schema.reduce((accum, field) => {\n accum.set(field.name, field.type.name);\n return accum;\n }, new Map<string, JobResultsResponse[\"schema\"][number][\"type\"][\"name\"]>());\n\n return (row: Record<string, unknown>) => {\n for (const property in row) {\n row[property] = mapFieldValue(fieldTypes.get(property)!, row[property]);\n }\n };\n};\n\nexport const mapRowData = (\n rows: JobResultsResponse[\"rows\"],\n schema: JobResultsResponse[\"schema\"],\n): void => {\n const rowMapper = createRowTypeMapper(schema);\n\n for (const row of rows) {\n rowMapper(row);\n }\n};\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { JobResultsResponse } from "./JobResultsResponse.ts";
|
|
2
|
-
|
|
2
|
+
import type { JSONValue } from "./JSONValue.ts";
|
|
3
|
+
export declare const mapRowsToColumns: <T extends Record<string, JSONValue>>(jobResults: JobResultsResponse<T>) => Record<Extract<keyof T, string>, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapRowsToColumns.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowsToColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"mapRowsToColumns.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowsToColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAIjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAiC,EACjC,EAAE;IACF,MAAM,SAAS,GAAG,4BAA4B,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1F,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACrD,KAAK,MAAM,UAAU,IAAI,GAAG,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YAClC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createColumnRecordFromSchema } from \"./createColumnRecordFromSchema.ts\";\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\nimport type { JSONValue } from \"./JSONValue.ts\";\n\nexport const mapRowsToColumns = <T extends Record<string, JSONValue>>(\n jobResults: JobResultsResponse<T>,\n) => {\n const columnMap = createColumnRecordFromSchema(jobResults.schema, jobResults.rows.length);\n\n for (const [index, row] of jobResults.rows.entries()) {\n for (const columnName in row) {\n const col = columnMap[columnName];\n col[index] = row[columnName];\n }\n }\n\n return columnMap;\n};\n"]}
|