@dremio/js-sdk 0.3.0 → 0.4.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/cloud/ai/AiResource.d.ts +24 -0
- package/dist/cloud/ai/AiResource.js +55 -0
- package/dist/cloud/ai/AiResource.js.map +1 -0
- package/dist/cloud/index.d.ts +5 -0
- package/dist/cloud/resources.d.ts +6 -0
- package/dist/cloud/resources.js +2 -0
- package/dist/cloud/resources.js.map +1 -1
- package/dist/enterprise/index.d.ts +1 -0
- package/dist/enterprise/resources.d.ts +1 -0
- package/dist/oss/catalog/CatalogReferences/BaseCatalogReference.d.ts +1 -1
- package/dist/oss/catalog/CatalogReferences/BaseCatalogReference.js +4 -7
- package/dist/oss/catalog/CatalogReferences/BaseCatalogReference.js.map +1 -1
- package/dist/oss/catalog/CatalogReferences/utils/catalogPathToString.d.ts +1 -0
- package/dist/oss/catalog/CatalogReferences/utils/catalogPathToString.js +18 -0
- package/dist/oss/catalog/CatalogReferences/utils/catalogPathToString.js.map +1 -0
- package/dist/oss/index.d.ts +1 -0
- package/dist/oss/jobs/Job.d.ts +1 -1
- package/dist/oss/jobs/Job.js +9 -4
- package/dist/oss/jobs/Job.js.map +1 -1
- package/dist/oss/jobs/JobsResource.d.ts +5 -1
- package/dist/oss/jobs/JobsResource.js +24 -19
- package/dist/oss/jobs/JobsResource.js.map +1 -1
- package/dist/oss/resources.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Err, Ok } from "ts-results-es";
|
|
2
|
+
import type { ResourceConfig, V3Config } from "../../common/Config.ts";
|
|
3
|
+
import type { SignalParam } from "../../common/Params.ts";
|
|
4
|
+
export declare class AiResource {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(config: ResourceConfig & V3Config);
|
|
7
|
+
autoProduceQuery: (project_id: string) => ({ datasetPaths, text }: {
|
|
8
|
+
datasetPaths: Set<string>;
|
|
9
|
+
text: string;
|
|
10
|
+
}, { signal }?: SignalParam) => Promise<Ok<string> | Err<{
|
|
11
|
+
readonly detail: "Please clarify your request and try again.";
|
|
12
|
+
readonly title: "SQL could not be generated from the input text.";
|
|
13
|
+
readonly type: "https://api.dremio.dev/problems/auto-produce-sql/clarify-request";
|
|
14
|
+
}> | Err<{
|
|
15
|
+
readonly detail: string;
|
|
16
|
+
readonly title: "An unexpected error occurred while processing this request.";
|
|
17
|
+
readonly type: "https://api.dremio.dev/problems/unexpected-error";
|
|
18
|
+
}>>;
|
|
19
|
+
}
|
|
20
|
+
export declare const clarifyRequestErr: {
|
|
21
|
+
readonly detail: "Please clarify your request and try again.";
|
|
22
|
+
readonly title: "SQL could not be generated from the input text.";
|
|
23
|
+
readonly type: "https://api.dremio.dev/problems/auto-produce-sql/clarify-request";
|
|
24
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import { Err, Ok } from "ts-results-es";
|
|
17
|
+
import { HttpError } from "../../common/HttpError.js";
|
|
18
|
+
import { isProblem } from "../../common/Problem.js";
|
|
19
|
+
export class AiResource {
|
|
20
|
+
#config;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.#config = config;
|
|
23
|
+
}
|
|
24
|
+
autoProduceQuery = (project_id) => ({ datasetPaths, text }, { signal } = {}) => this.#config
|
|
25
|
+
.v3Request("gen-ai/auto-produce-query", {
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
datasetIdentifiers: Array.from(datasetPaths).map((datasetPath) => ({
|
|
28
|
+
datasetPath,
|
|
29
|
+
})),
|
|
30
|
+
projectId: project_id,
|
|
31
|
+
userInputtedText: text,
|
|
32
|
+
}),
|
|
33
|
+
headers: {
|
|
34
|
+
Accept: "application/json",
|
|
35
|
+
"Content-Type": "application/json",
|
|
36
|
+
},
|
|
37
|
+
method: "POST",
|
|
38
|
+
signal,
|
|
39
|
+
})
|
|
40
|
+
.then((res) => res.json())
|
|
41
|
+
.then((response) => Ok(response.sql))
|
|
42
|
+
.catch((e) => {
|
|
43
|
+
if (e instanceof HttpError && isProblem(e.body)) {
|
|
44
|
+
if (e.body.detail?.includes("INVALID_ARGUMENT: SQL could not be generated. Please clarify your request."))
|
|
45
|
+
return Err(clarifyRequestErr);
|
|
46
|
+
}
|
|
47
|
+
return Err(e);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export const clarifyRequestErr = {
|
|
51
|
+
detail: "Please clarify your request and try again.",
|
|
52
|
+
title: "SQL could not be generated from the input text.",
|
|
53
|
+
type: "https://api.dremio.dev/problems/auto-produce-sql/clarify-request",
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=AiResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AiResource.js","sourceRoot":"","sources":["../../../src/cloud/ai/AiResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAgB,MAAM,yBAAyB,CAAC;AAGlE,MAAM,OAAO,UAAU;IACZ,OAAO,CAA4B;IAE5C,YAAY,MAAiC;QAC3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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 { Err, Ok } from \"ts-results-es\";\nimport type { ResourceConfig, V3Config } from \"../../common/Config.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { HttpError } from \"../../common/HttpError.ts\";\nimport { isProblem, type Problem } from \"../../common/Problem.ts\";\nimport type { unexpectedError } from \"../../common/problems.ts\";\n\nexport class AiResource {\n readonly #config: ResourceConfig & V3Config;\n\n constructor(config: ResourceConfig & V3Config) {\n this.#config = config;\n }\n\n autoProduceQuery =\n (project_id: string) =>\n (\n { datasetPaths, text }: { datasetPaths: Set<string>; text: string },\n { signal }: SignalParam = {},\n ) =>\n this.#config\n .v3Request(\"gen-ai/auto-produce-query\", {\n body: JSON.stringify({\n datasetIdentifiers: Array.from(datasetPaths).map((datasetPath) => ({\n datasetPath,\n })),\n projectId: project_id,\n userInputtedText: text,\n }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n signal,\n })\n .then((res) => res.json() as Promise<{ sql: string }>)\n .then((response) => Ok(response.sql))\n .catch((e: unknown) => {\n if (e instanceof HttpError && isProblem(e.body)) {\n if (\n e.body.detail?.includes(\n \"INVALID_ARGUMENT: SQL could not be generated. Please clarify your request.\",\n )\n )\n return Err(clarifyRequestErr);\n }\n return Err(e as ReturnType<typeof unexpectedError>);\n });\n}\n\nexport const clarifyRequestErr = {\n detail: \"Please clarify your request and try again.\",\n title: \"SQL could not be generated from the input text.\",\n type: \"https://api.dremio.dev/problems/auto-produce-sql/clarify-request\",\n} as const satisfies Problem;\n"]}
|
package/dist/cloud/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const Dremio: (config: Config) => {
|
|
|
16
16
|
v3Request: (path: string, init?: RequestInit) => Promise<Response>;
|
|
17
17
|
};
|
|
18
18
|
_sonarV3Request: (projectId: string) => (path: string, init?: RequestInit) => Promise<Response>;
|
|
19
|
+
ai: import("./ai/AiResource.ts").AiResource;
|
|
19
20
|
arctic: import("moize").Moized<(projectId: string) => {
|
|
20
21
|
_createFromEntity: (entity: import("./arctic/ArcticCatalog.ts").ArcticCatalogEntity) => import("./interfaces.ts").ArcticCatalog;
|
|
21
22
|
list: () => {
|
|
@@ -217,6 +218,7 @@ export declare const Dremio: (config: Config) => {
|
|
|
217
218
|
}>>;
|
|
218
219
|
jobs: import("moize").Moized<(projectId: string) => {
|
|
219
220
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
221
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
220
222
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
221
223
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
222
224
|
}, Partial<{
|
|
@@ -232,16 +234,19 @@ export declare const Dremio: (config: Config) => {
|
|
|
232
234
|
maxSize: number;
|
|
233
235
|
onCacheAdd: import("moize").OnCacheOperation<(projectId: string) => {
|
|
234
236
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
237
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
235
238
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
236
239
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
237
240
|
}>;
|
|
238
241
|
onCacheChange: import("moize").OnCacheOperation<(projectId: string) => {
|
|
239
242
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
243
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
240
244
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
241
245
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
242
246
|
}>;
|
|
243
247
|
onCacheHit: import("moize").OnCacheOperation<(projectId: string) => {
|
|
244
248
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
249
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
245
250
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
246
251
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
247
252
|
}>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ResourceConfig, SonarV3Config, V3Config } from "../common/Config.ts";
|
|
2
2
|
import moize from "moize";
|
|
3
|
+
import { AiResource } from "./ai/AiResource.ts";
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
* @hidden
|
|
6
7
|
*/
|
|
7
8
|
export declare const Resources: (config: (projectId?: string) => ResourceConfig & SonarV3Config & V3Config) => {
|
|
9
|
+
ai: AiResource;
|
|
8
10
|
arctic: moize.Moized<(projectId: string) => {
|
|
9
11
|
_createFromEntity: (entity: import("./arctic/ArcticCatalog.ts").ArcticCatalogEntity) => import("./interfaces.ts").ArcticCatalog;
|
|
10
12
|
list: () => {
|
|
@@ -206,6 +208,7 @@ export declare const Resources: (config: (projectId?: string) => ResourceConfig
|
|
|
206
208
|
}>>;
|
|
207
209
|
jobs: moize.Moized<(projectId: string) => {
|
|
208
210
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
211
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
209
212
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
210
213
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
211
214
|
}, Partial<{
|
|
@@ -221,16 +224,19 @@ export declare const Resources: (config: (projectId?: string) => ResourceConfig
|
|
|
221
224
|
maxSize: number;
|
|
222
225
|
onCacheAdd: moize.OnCacheOperation<(projectId: string) => {
|
|
223
226
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
227
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
224
228
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
225
229
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
226
230
|
}>;
|
|
227
231
|
onCacheChange: moize.OnCacheOperation<(projectId: string) => {
|
|
228
232
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
233
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
229
234
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
230
235
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
231
236
|
}>;
|
|
232
237
|
onCacheHit: moize.OnCacheOperation<(projectId: string) => {
|
|
233
238
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
239
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
234
240
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
235
241
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
236
242
|
}>;
|
package/dist/cloud/resources.js
CHANGED
|
@@ -23,11 +23,13 @@ import { CloudUsersResource } from "./users/CloudUsersResource.js";
|
|
|
23
23
|
import { JobsResource } from "../oss/jobs/JobsResource.js";
|
|
24
24
|
import moize from "moize";
|
|
25
25
|
import { OAuthApplicationsResource } from "./oauth/OAuthApplicationsResource.js";
|
|
26
|
+
import { AiResource } from "./ai/AiResource.js";
|
|
26
27
|
/**
|
|
27
28
|
* @internal
|
|
28
29
|
* @hidden
|
|
29
30
|
*/
|
|
30
31
|
export const Resources = (config) => ({
|
|
32
|
+
ai: new AiResource(config()),
|
|
31
33
|
arctic: moize.default((projectId) => ArcticResource(config(projectId))),
|
|
32
34
|
catalog: moize.default((projectId) => EnterpriseCatalogResource(config(projectId))),
|
|
33
35
|
engines: moize.default((projectId) => EnginesResource(config(projectId))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/cloud/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EA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CAAC;IAC5B,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/E,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,yBAAyB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3F,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACjF,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3E,iBAAiB,EAAE,yBAAyB,CAAC,MAAM,EAAE,CAAC;IACtD,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC;IACpC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7E,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,yBAAyB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3F,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;CACnF,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 { ResourceConfig, SonarV3Config, V3Config } from \"../common/Config.ts\";\nimport { ArcticResource } from \"./arctic/ArcticResource.ts\";\nimport { EnterpriseCatalogResource } from \"../enterprise/catalog/EnterpriseCatalogResource.ts\";\nimport { RolesResource } from \"../enterprise/roles/RolesResource.ts\";\nimport { EnterpriseScriptsResource } from \"../enterprise/scripts/EnterpriseScriptsResource.ts\";\nimport { EnginesResource } from \"./engines/EnginesResource.ts\";\nimport { ProjectsResource } from \"./projects/ProjectsResource.ts\";\nimport { CloudUsersResource } from \"./users/CloudUsersResource.ts\";\nimport { JobsResource } from \"../oss/jobs/JobsResource.ts\";\nimport moize from \"moize\";\nimport { OAuthApplicationsResource } from \"./oauth/OAuthApplicationsResource.ts\";\nimport { AiResource } from \"./ai/AiResource.ts\";\n\n/**\n * @internal\n * @hidden\n */\nexport const Resources = (\n config: (projectId?: string) => ResourceConfig & SonarV3Config & V3Config,\n) => ({\n ai: new AiResource(config()),\n arctic: moize.default((projectId: string) => ArcticResource(config(projectId))),\n catalog: moize.default((projectId: string) => EnterpriseCatalogResource(config(projectId))),\n engines: moize.default((projectId: string) => EnginesResource(config(projectId))),\n jobs: moize.default((projectId: string) => JobsResource(config(projectId))),\n oauthApplications: OAuthApplicationsResource(config()),\n projects: ProjectsResource(config()),\n roles: moize.default((projectId: string) => RolesResource(config(projectId))),\n scripts: moize.default((projectId: string) => EnterpriseScriptsResource(config(projectId))),\n users: moize.default((projectId: string) => CloudUsersResource(config(projectId))),\n});\n"]}
|
|
@@ -29,6 +29,7 @@ export declare const Dremio: (config: Config) => {
|
|
|
29
29
|
engines: import("./engines/EnginesResource.ts").EnginesResource;
|
|
30
30
|
jobs: {
|
|
31
31
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
32
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
32
33
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
33
34
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
34
35
|
};
|
|
@@ -16,6 +16,7 @@ export declare const Resources: (config: ResourceConfig & SonarV2Config & SonarV
|
|
|
16
16
|
engines: EnginesResource;
|
|
17
17
|
jobs: {
|
|
18
18
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
19
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
19
20
|
observe: (id: string) => import("rxjs").Observable<import("../oss/jobs/Job.ts").JobResult>;
|
|
20
21
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("../oss/jobs/Job.ts").JobResult>;
|
|
21
22
|
};
|
|
@@ -8,7 +8,7 @@ export declare abstract class BaseCatalogReference {
|
|
|
8
8
|
abstract catalogObject(): Promise<Result<CatalogObject, unknown>>;
|
|
9
9
|
constructor(properties: BaseCatalogReferenceProperties);
|
|
10
10
|
get name(): string;
|
|
11
|
-
pathString
|
|
11
|
+
pathString(SEPARATOR?: string): string;
|
|
12
12
|
}
|
|
13
13
|
export type BaseCatalogReferenceProperties = {
|
|
14
14
|
id: string;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { catalogPathToString } from "./utils/catalogPathToString.js";
|
|
16
17
|
export class BaseCatalogReference {
|
|
17
18
|
id;
|
|
18
19
|
path;
|
|
@@ -23,12 +24,8 @@ export class BaseCatalogReference {
|
|
|
23
24
|
get name() {
|
|
24
25
|
return this.path.at(-1);
|
|
25
26
|
}
|
|
26
|
-
pathString =
|
|
27
|
+
pathString(SEPARATOR = ".") {
|
|
28
|
+
return catalogPathToString(this.path, SEPARATOR);
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
|
-
const requiresQuotes = /\W/;
|
|
29
|
-
const pathString = (getPath) => (SEPARATOR = ".") => {
|
|
30
|
-
return getPath()
|
|
31
|
-
.map((part) => (requiresQuotes.test(part) ? `"${part}"` : part))
|
|
32
|
-
.join(SEPARATOR);
|
|
33
|
-
};
|
|
34
31
|
//# sourceMappingURL=BaseCatalogReference.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCatalogReference.js","sourceRoot":"","sources":["../../../../src/oss/catalog/CatalogReferences/BaseCatalogReference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"BaseCatalogReference.js","sourceRoot":"","sources":["../../../../src/oss/catalog/CatalogReferences/BaseCatalogReference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAIrE,MAAM,OAAgB,oBAAoB;IAC/B,EAAE,CAAuC;IACzC,IAAI,CAAyC;IAItD,YAAY,UAA0C;QACpD,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;IAC3B,CAAC;IAED,UAAU,CAAC,YAAoB,GAAG;QAChC,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;CACF","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 { Result } from \"ts-results-es\";\nimport type { CatalogObject } from \"../CatalogObjects/index.ts\";\nimport { catalogPathToString } from \"./utils/catalogPathToString.ts\";\n\nexport type RetrieveByPath = (path: string[]) => Promise<Result<CatalogObject, unknown>>;\n\nexport abstract class BaseCatalogReference {\n readonly id: BaseCatalogReferenceProperties[\"id\"];\n readonly path: BaseCatalogReferenceProperties[\"path\"];\n abstract readonly type: string;\n abstract catalogObject(): Promise<Result<CatalogObject, unknown>>;\n\n constructor(properties: BaseCatalogReferenceProperties) {\n this.id = properties.id;\n this.path = properties.path;\n }\n\n get name() {\n return this.path.at(-1)!;\n }\n\n pathString(SEPARATOR: string = \".\") {\n return catalogPathToString(this.path, SEPARATOR);\n }\n}\n\nexport type BaseCatalogReferenceProperties = { id: string; path: string[] };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const catalogPathToString: (path: string[], SEPARATOR?: string) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 const catalogPathToString = (path, SEPARATOR = ".") => path.map((part) => (requiresQuotes.test(part) ? `"${part}"` : part)).join(SEPARATOR);
|
|
17
|
+
const requiresQuotes = /\W/;
|
|
18
|
+
//# sourceMappingURL=catalogPathToString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalogPathToString.js","sourceRoot":"","sources":["../../../../../src/oss/catalog/CatalogReferences/utils/catalogPathToString.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAc,EAAE,YAAoB,GAAG,EAAE,EAAE,CAC7E,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAEvF,MAAM,cAAc,GAAG,IAAI,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\nexport const catalogPathToString = (path: string[], SEPARATOR: string = \".\") =>\n path.map((part) => (requiresQuotes.test(part) ? `\"${part}\"` : part)).join(SEPARATOR);\n\nconst requiresQuotes = /\\W/;\n"]}
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare const Dremio: (config: Config) => {
|
|
|
28
28
|
};
|
|
29
29
|
jobs: {
|
|
30
30
|
create: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
31
|
+
createAndRetrieve: (query: import("../common/Query.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
31
32
|
observe: (id: string) => import("rxjs").Observable<import("./jobs/Job.ts").JobResult>;
|
|
32
33
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("./jobs/Job.ts").JobResult>;
|
|
33
34
|
};
|
package/dist/oss/jobs/Job.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class Job {
|
|
|
30
30
|
};
|
|
31
31
|
readonly totalRows: number;
|
|
32
32
|
}, void, unknown>;
|
|
33
|
-
slice: <T extends Record<string, unknown> = Record<string, unknown>>(start?: number, end?: number) => Promise<T[]
|
|
33
|
+
slice: <T extends Record<string, unknown> = Record<string, unknown>>(start?: number, end?: number) => Promise<Err<unknown> | Ok<T[]>>;
|
|
34
34
|
};
|
|
35
35
|
cancel(): Promise<Err<any> | Ok<undefined>>;
|
|
36
36
|
}
|
package/dist/oss/jobs/Job.js
CHANGED
|
@@ -112,11 +112,16 @@ export class Job {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
async #slice(start = 0, end = Infinity) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
try {
|
|
116
|
+
const rows = [];
|
|
117
|
+
for await (const batch of this.#jsonBatches({ limit: end - start, offset: start })) {
|
|
118
|
+
rows.push(...batch.rows);
|
|
119
|
+
}
|
|
120
|
+
return Ok(rows);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
return Err(e);
|
|
118
124
|
}
|
|
119
|
-
return rows;
|
|
120
125
|
}
|
|
121
126
|
async cancel() {
|
|
122
127
|
return this.#config
|
package/dist/oss/jobs/Job.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts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zD,EAAE;IACF,OAAO,EAAE,IAAsB;IAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;IAC3B,yBAAyB,EAAE,MAAM,CAAC,yBAAyB;QACzD,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC;QAC5C,CAAC,CAAC,IAAI;IACR,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC7D,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,2BAA2B,CAAC;QAC9C,CAAC,CAAC,IAAI;IACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;IACzB,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI;IAC/D,KAAK,EAAE,MAAM,CAAC,QAAQ;CACvB,CAAU,CAAC;AAMd,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 type { Problem } from \"../../common/Problem.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\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\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<JobResult>,\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\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 slice: this.#slice.bind(this),\n };\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\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 lastValueFrom(this.observer);\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 = await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`)\n .then((res) => res.json() as Promise<JobResultsResponse<T>>);\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 #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n ) {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>({ limit: end - start, offset: start })) {\n rows.push(...batch.rows);\n }\n return rows;\n }\n\n async cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .then(() => Ok(undefined))\n .catch((e) => Err(e));\n }\n}\n\nexport const jobEntityToProperties = (\n id: string,\n entity: {\n jobState:\n | \"NOT_SUBMITTED\"\n | \"STARTING\"\n | \"RUNNING\"\n | \"COMPLETED\"\n | \"CANCELED\"\n | \"FAILED\"\n | \"CANCELLATION_REQUESTED\"\n | \"PLANNING\"\n | \"PENDING\"\n | \"METADATA_RETRIEVAL\"\n | \"QUEUED\"\n | \"ENGINE_START\"\n | \"EXECUTION_PLANNING\"\n | \"INVALID_STATE\";\n rowCount: number | null;\n errorMessage: string;\n startedAt: string | null;\n endedAt: string | null;\n acceleration: {\n reflectionRelationships: {\n datasetId: string;\n reflectionId: string;\n relationship: string;\n }[];\n };\n queryType:\n | \"UI_RUN\"\n | \"UI_PREVIEW\"\n | \"UI_INTERNAL_PREVIEW\"\n | \"UI_INTERNAL_RUN\"\n | \"UI_EXPORT\"\n | \"ODBC\"\n | \"JDBC\"\n | \"REST\"\n | \"ACCELERATOR_CREATE\"\n | \"ACCELERATOR_DROP\"\n | \"UNKNOWN\"\n | \"PREPARE_INTERNAL\"\n | \"ACCELERATOR_EXPLAIN\"\n | \"UI_INITIAL_PREVIEW\";\n resourceSchedulingStartedAt: string | null;\n resourceSchedulingEndedAt: string | null;\n cancellationReason: string | null;\n },\n) =>\n ({\n acceleration: entity.acceleration,\n cancellationReason: entity.cancellationReason,\n endedAt: entity.endedAt ? new Date(entity.endedAt) : null,\n id,\n problem: null as Problem | null,\n queryType: entity.queryType,\n resourceSchedulingEndedAt: entity.resourceSchedulingEndedAt\n ? new Date(entity.resourceSchedulingEndedAt)\n : null,\n resourceSchedulingStartedAt: entity.resourceSchedulingStartedAt\n ? new Date(entity.resourceSchedulingStartedAt)\n : null,\n rowCount: entity.rowCount,\n startedAt: entity.startedAt ? new Date(entity.startedAt) : null,\n state: entity.jobState,\n }) as const;\n\ntype JobProperties = ReturnType<typeof jobEntityToProperties>;\n\nexport type JobResult = Result<Job, unknown>;\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|
|
1
|
+
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,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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C,yBAAyB,CAAC;QAC5C,CAAC,CAAC,IAAI;IACR,2BAA2B,EAAE,MAAM,CAAC,2BAA2B;QAC7D,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,2BAA2B,CAAC;QAC9C,CAAC,CAAC,IAAI;IACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;IACzB,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI;IAC/D,KAAK,EAAE,MAAM,CAAC,QAAQ;CACvB,CAAU,CAAC;AAMd,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 type { Problem } from \"../../common/Problem.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\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\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<JobResult>,\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\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 slice: this.#slice.bind(this),\n };\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\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 lastValueFrom(this.observer);\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 = await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`)\n .then((res) => res.json() as Promise<JobResultsResponse<T>>);\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 #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>({ limit: end - start, offset: start })) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n async cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .then(() => Ok(undefined))\n .catch((e) => Err(e));\n }\n}\n\nexport const jobEntityToProperties = (\n id: string,\n entity: {\n jobState:\n | \"NOT_SUBMITTED\"\n | \"STARTING\"\n | \"RUNNING\"\n | \"COMPLETED\"\n | \"CANCELED\"\n | \"FAILED\"\n | \"CANCELLATION_REQUESTED\"\n | \"PLANNING\"\n | \"PENDING\"\n | \"METADATA_RETRIEVAL\"\n | \"QUEUED\"\n | \"ENGINE_START\"\n | \"EXECUTION_PLANNING\"\n | \"INVALID_STATE\";\n rowCount: number | null;\n errorMessage: string;\n startedAt: string | null;\n endedAt: string | null;\n acceleration: {\n reflectionRelationships: {\n datasetId: string;\n reflectionId: string;\n relationship: string;\n }[];\n };\n queryType:\n | \"UI_RUN\"\n | \"UI_PREVIEW\"\n | \"UI_INTERNAL_PREVIEW\"\n | \"UI_INTERNAL_RUN\"\n | \"UI_EXPORT\"\n | \"ODBC\"\n | \"JDBC\"\n | \"REST\"\n | \"ACCELERATOR_CREATE\"\n | \"ACCELERATOR_DROP\"\n | \"UNKNOWN\"\n | \"PREPARE_INTERNAL\"\n | \"ACCELERATOR_EXPLAIN\"\n | \"UI_INITIAL_PREVIEW\";\n resourceSchedulingStartedAt: string | null;\n resourceSchedulingEndedAt: string | null;\n cancellationReason: string | null;\n },\n) =>\n ({\n acceleration: entity.acceleration,\n cancellationReason: entity.cancellationReason,\n endedAt: entity.endedAt ? new Date(entity.endedAt) : null,\n id,\n problem: null as Problem | null,\n queryType: entity.queryType,\n resourceSchedulingEndedAt: entity.resourceSchedulingEndedAt\n ? new Date(entity.resourceSchedulingEndedAt)\n : null,\n resourceSchedulingStartedAt: entity.resourceSchedulingStartedAt\n ? new Date(entity.resourceSchedulingStartedAt)\n : null,\n rowCount: entity.rowCount,\n startedAt: entity.startedAt ? new Date(entity.startedAt) : null,\n state: entity.jobState,\n }) as const;\n\ntype JobProperties = ReturnType<typeof jobEntityToProperties>;\n\nexport type JobResult = Result<Job, unknown>;\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { SonarV3Config } from "../../common/Config.ts";
|
|
2
|
-
import { type JobResult } from "./Job.ts";
|
|
2
|
+
import { Job, type JobResult } from "./Job.ts";
|
|
3
3
|
import { Query } from "../../common/Query.ts";
|
|
4
4
|
import { Err, Ok } from "ts-results-es";
|
|
5
5
|
import type { SignalParam } from "../../common/Params.ts";
|
|
6
6
|
export declare const JobsResource: (config: SonarV3Config) => {
|
|
7
7
|
create: (query: Query) => Promise<Err<unknown> | Ok<string>>;
|
|
8
|
+
/**
|
|
9
|
+
* A convenience method to combine job creation and retrieval
|
|
10
|
+
*/
|
|
11
|
+
createAndRetrieve: (query: Query) => Promise<import("ts-results-es").Result<Job, unknown>>;
|
|
8
12
|
observe: (id: string) => import("rxjs").Observable<JobResult>;
|
|
9
13
|
retrieve: (id: string, { signal }?: SignalParam) => Promise<JobResult>;
|
|
10
14
|
};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { Job, jobEntityToProperties } from "./Job.js";
|
|
17
17
|
import { Query } from "../../common/Query.js";
|
|
18
|
-
import { Err, Ok } from "ts-results-es";
|
|
18
|
+
import { Err, Ok, AsyncResult } from "ts-results-es";
|
|
19
19
|
import { concatMap, shareReplay, takeWhile, timer } from "rxjs";
|
|
20
20
|
import { fromAbortable } from "../../common/fromAbortable.js";
|
|
21
21
|
export const JobsResource = (config) => {
|
|
@@ -43,30 +43,35 @@ export const JobsResource = (config) => {
|
|
|
43
43
|
bufferSize: 1,
|
|
44
44
|
refCount: true,
|
|
45
45
|
}));
|
|
46
|
+
const create = (query) => {
|
|
47
|
+
return config
|
|
48
|
+
.sonarV3Request(`sql`, {
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
context: query.context,
|
|
51
|
+
sql: query.sql,
|
|
52
|
+
}),
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
},
|
|
57
|
+
keepalive: true,
|
|
58
|
+
method: "POST",
|
|
59
|
+
})
|
|
60
|
+
.then((res) => res.json())
|
|
61
|
+
.then((response) => Ok(response.id))
|
|
62
|
+
.catch((e) => Err(e));
|
|
63
|
+
};
|
|
46
64
|
const retrieve = (id, { signal } = {}) => config
|
|
47
65
|
.sonarV3Request(`job/${id}`, { signal })
|
|
48
66
|
.then((res) => res.json())
|
|
49
67
|
.then((properties) => Ok(new Job(jobEntityToProperties(id, properties), config, observe)))
|
|
50
68
|
.catch((e) => Err(e));
|
|
51
69
|
return {
|
|
52
|
-
create
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
sql: query.sql,
|
|
58
|
-
}),
|
|
59
|
-
headers: {
|
|
60
|
-
Accept: "application/json",
|
|
61
|
-
"Content-Type": "application/json",
|
|
62
|
-
},
|
|
63
|
-
keepalive: true,
|
|
64
|
-
method: "POST",
|
|
65
|
-
})
|
|
66
|
-
.then((res) => res.json())
|
|
67
|
-
.then((response) => Ok(response.id))
|
|
68
|
-
.catch((e) => Err(e));
|
|
69
|
-
},
|
|
70
|
+
create,
|
|
71
|
+
/**
|
|
72
|
+
* A convenience method to combine job creation and retrieval
|
|
73
|
+
*/
|
|
74
|
+
createAndRetrieve: (query) => new AsyncResult(create(query)).andThen((jobId) => retrieve(jobId)).promise,
|
|
70
75
|
observe,
|
|
71
76
|
retrieve,
|
|
72
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JobsResource.js","sourceRoot":"","sources":["../../../src/oss/jobs/JobsResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAkB,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"JobsResource.js","sourceRoot":"","sources":["../../../src/oss/jobs/JobsResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAkB,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAqB,EAAE,EAAE;I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,EAAE,CAChF,MAAM;SACH,cAAc,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;SACvC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACzB,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,qBAAqB,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;SACzF,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO;QACL,MAAM;QACN;;WAEG;QACH,iBAAiB,EAAE,CAAC,KAAY,EAAE,EAAE,CAClC,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;QAC5E,OAAO;QACP,QAAQ;KACT,CAAC;AACJ,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 { SonarV3Config } from \"../../common/Config.ts\";\nimport { Job, jobEntityToProperties, type JobResult } from \"./Job.ts\";\nimport { Query } from \"../../common/Query.ts\";\nimport { Err, Ok, AsyncResult } from \"ts-results-es\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { concatMap, shareReplay, takeWhile, timer } from \"rxjs\";\nimport { fromAbortable } from \"../../common/fromAbortable.ts\";\n\nexport const JobsResource = (config: SonarV3Config) => {\n const observe = (id: string) =>\n /**\n * Check every 1000ms for job status changes. 1000ms may seem too frequent,\n * but it helps keep the client feeling snappy, especially for jobs that complete quickly.\n */\n timer(0, 1000).pipe(\n /**\n * Use `concatMap` instead of `switchMap` to avoid a situation where the call takes longer than\n * 1000ms (possibly due to network conditions or API slowdowns) which would cause switchMap to\n * constantly cancel unfinished requests (in which case, no requests would ever complete)\n */\n concatMap(() => fromAbortable(({ signal }) => retrieve(id, { signal }))),\n /**\n * Continue polling until the job has reached a settled state\n */\n takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true),\n /**\n * Reuse the same polling for multiple subscribers, buffering only the latest result.\n * Make sure to unsubscribe from the source to stop polling when there are no subscribers (refCount: true)\n */\n shareReplay({\n bufferSize: 1,\n refCount: true,\n }),\n );\n const create = (query: Query) => {\n return config\n .sonarV3Request(`sql`, {\n body: JSON.stringify({\n context: query.context,\n sql: query.sql,\n }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .then((res) => res.json() as Promise<{ id: string }>)\n .then((response) => Ok(response.id))\n .catch((e: unknown) => Err(e));\n };\n const retrieve = (id: string, { signal }: SignalParam = {}): Promise<JobResult> =>\n config\n .sonarV3Request(`job/${id}`, { signal })\n .then((res) => res.json())\n .then((properties) => Ok(new Job(jobEntityToProperties(id, properties), config, observe)))\n .catch((e: unknown) => Err(e));\n return {\n create,\n /**\n * A convenience method to combine job creation and retrieval\n */\n createAndRetrieve: (query: Query) =>\n new AsyncResult(create(query)).andThen((jobId) => retrieve(jobId)).promise,\n observe,\n retrieve,\n };\n};\n"]}
|
package/dist/oss/resources.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const Resources: (config: ResourceConfig & SonarV2Config & SonarV
|
|
|
14
14
|
};
|
|
15
15
|
jobs: {
|
|
16
16
|
create: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Err<unknown> | import("ts-results-es").Ok<string>>;
|
|
17
|
+
createAndRetrieve: (query: import("./index.ts").Query) => Promise<import("ts-results-es").Result<import("./interfaces.ts").Job, unknown>>;
|
|
17
18
|
observe: (id: string) => import("rxjs").Observable<import("./jobs/Job.ts").JobResult>;
|
|
18
19
|
retrieve: (id: string, { signal }?: import("../common/Params.ts").SignalParam) => Promise<import("./jobs/Job.ts").JobResult>;
|
|
19
20
|
};
|