Skip to content

Commit 6c9d5ec

Browse files
authored
Generate DBFS, Jobs, and Libraries APIs (#25)
* Import generated code * Fix undefined access * Pin Jobs API calls to 2.1
1 parent 7fc48a3 commit 6c9d5ec

File tree

4 files changed

+903
-195
lines changed

4 files changed

+903
-195
lines changed

packages/databricks-sdk-js/src/apis/dbfs.ts

Lines changed: 167 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,191 @@
22

33
import {ApiClient} from "../api-client";
44

5-
export interface DbfsPutRequest {
5+
import * as delegate from "./delegate";
6+
7+
//
8+
// Enums.
9+
//
10+
11+
//
12+
// Subtypes used in request/response types.
13+
//
14+
15+
export interface FileInfo {
16+
path?: string;
17+
is_dir?: boolean;
18+
file_size?: number;
19+
modification_time?: number;
20+
}
21+
22+
//
23+
// Request/response types.
24+
//
25+
26+
export interface ReadRequest {
27+
path: string;
28+
offset?: number;
29+
length?: number;
30+
}
31+
32+
export interface ReadResponse {
33+
bytes_read?: number;
34+
data?: string;
35+
}
36+
37+
export interface GetStatusRequest {
638
path: string;
7-
contents: string;
8-
overwrite: boolean;
939
}
1040

11-
export interface DbfsPutResponse {}
41+
export interface GetStatusResponse {
42+
path?: string;
43+
is_dir?: boolean;
44+
file_size?: number;
45+
modification_time?: number;
46+
}
1247

13-
export interface DbfsDeleteRequest {
48+
export interface ListStatusRequest {
1449
path: string;
1550
}
1651

17-
export interface DbfsDeleteResponse {
18-
error_code?: string;
19-
message?: string;
52+
export interface ListStatusResponse {
53+
files?: Array<FileInfo>;
2054
}
2155

56+
export interface PutRequest {
57+
path: string;
58+
contents?: string;
59+
overwrite?: boolean;
60+
}
61+
62+
export interface PutResponse {}
63+
64+
export interface MkDirsRequest {
65+
path: string;
66+
}
67+
68+
export interface MkDirsResponse {}
69+
70+
export interface MoveRequest {
71+
source_path: string;
72+
destination_path: string;
73+
}
74+
75+
export interface MoveResponse {}
76+
77+
export interface DeleteRequest {
78+
path: string;
79+
recursive?: boolean;
80+
}
81+
82+
export interface DeleteResponse {}
83+
84+
export interface CreateRequest {
85+
path: string;
86+
overwrite?: boolean;
87+
}
88+
89+
export interface CreateResponse {
90+
handle?: number;
91+
}
92+
93+
export interface AddBlockRequest {
94+
handle: number;
95+
data: string;
96+
}
97+
98+
export interface AddBlockResponse {}
99+
100+
export interface CloseRequest {
101+
handle: number;
102+
}
103+
104+
export interface CloseResponse {}
105+
22106
export class DbfsService {
23-
constructor(readonly client: ApiClient) {}
107+
readonly client: ApiClient;
108+
109+
constructor(client: ApiClient) {
110+
this.client = client;
111+
}
24112

25-
async put(req: DbfsPutRequest): Promise<DbfsPutResponse> {
113+
async read(request: ReadRequest): Promise<ReadResponse> {
114+
return (await this.client.request(
115+
"/api/2.0/dbfs/read",
116+
"GET",
117+
request
118+
)) as ReadResponse;
119+
}
120+
121+
async getStatus(request: GetStatusRequest): Promise<GetStatusResponse> {
122+
return (await this.client.request(
123+
"/api/2.0/dbfs/get-status",
124+
"GET",
125+
request
126+
)) as GetStatusResponse;
127+
}
128+
129+
async list(request: ListStatusRequest): Promise<ListStatusResponse> {
130+
return (await this.client.request(
131+
"/api/2.0/dbfs/list",
132+
"GET",
133+
request
134+
)) as ListStatusResponse;
135+
}
136+
137+
async put(request: PutRequest): Promise<PutResponse> {
26138
return (await this.client.request(
27139
"/api/2.0/dbfs/put",
28140
"POST",
29-
req
30-
)) as DbfsPutResponse;
141+
request
142+
)) as PutResponse;
143+
}
144+
145+
async mkdirs(request: MkDirsRequest): Promise<MkDirsResponse> {
146+
return (await this.client.request(
147+
"/api/2.0/dbfs/mkdirs",
148+
"POST",
149+
request
150+
)) as MkDirsResponse;
151+
}
152+
153+
async move(request: MoveRequest): Promise<MoveResponse> {
154+
return (await this.client.request(
155+
"/api/2.0/dbfs/move",
156+
"POST",
157+
request
158+
)) as MoveResponse;
31159
}
32160

33-
async delete(req: DbfsDeleteRequest): Promise<DbfsDeleteResponse> {
161+
async delete(request: DeleteRequest): Promise<DeleteResponse> {
34162
return (await this.client.request(
35163
"/api/2.0/dbfs/delete",
36164
"POST",
37-
req
38-
)) as DbfsDeleteResponse;
165+
request
166+
)) as DeleteResponse;
167+
}
168+
169+
async create(request: CreateRequest): Promise<CreateResponse> {
170+
return (await this.client.request(
171+
"/api/2.0/dbfs/create",
172+
"POST",
173+
request
174+
)) as CreateResponse;
175+
}
176+
177+
async addBlock(request: AddBlockRequest): Promise<AddBlockResponse> {
178+
return (await this.client.request(
179+
"/api/2.0/dbfs/add-block",
180+
"POST",
181+
request
182+
)) as AddBlockResponse;
183+
}
184+
185+
async close(request: CloseRequest): Promise<CloseResponse> {
186+
return (await this.client.request(
187+
"/api/2.0/dbfs/close",
188+
"POST",
189+
request
190+
)) as CloseResponse;
39191
}
40192
}

packages/databricks-sdk-js/src/apis/jobs.integ.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe(__filename, function () {
2828
overwrite: true,
2929
});
3030

31-
let res = await jobsService.submit({
31+
let res = await jobsService.submitRun({
3232
tasks: [
3333
{
3434
task_key: "hello_world",
@@ -41,26 +41,26 @@ describe(__filename, function () {
4141
});
4242

4343
// console.log(res);
44-
let runId = res.run_id;
44+
let runId = res.run_id!;
4545

4646
while (true) {
4747
await sleep(3000);
4848
let run = await jobsService.getRun({run_id: runId});
49-
let state = run.state.life_cycle_state;
49+
let state = run.state!.life_cycle_state!;
5050

5151
// console.log(`State: ${state} - URL: ${run.run_page_url}`);
5252

5353
if (state === "INTERNAL_ERROR" || state === "TERMINATED") {
5454
let output = await jobsService.getRunOutput({
55-
run_id: run.tasks[0].run_id,
55+
run_id: run.tasks![0].run_id!,
5656
});
5757
// console.log(output);
5858

59-
assert.equal(output.logs.trim(), "hello from job");
59+
assert.equal(output.logs!.trim(), "hello from job");
6060
break;
6161
}
6262
}
6363

64-
dbfsApi.delete({path: jobPath});
64+
await dbfsApi.delete({path: jobPath});
6565
});
6666
});

0 commit comments

Comments
 (0)