551 . [ Foreword] ( #foreword )
662 . [ Example] ( #example ) \
77 2.1. [ Error handling] ( #error-handling )
8- 3 . [ HiveSession] ( #hivesession )
9- 4 . [ HiveOperation] ( #hiveoperation ) \
10- 4.1. [ HiveUtils] ( #hiveutils )
8+ 3 . [ DBSQLSession] ( #dbsqlsession )
9+ 4 . [ DBSQLOperation] ( #dbsqloperation )
11105 . [ Status] ( #status )
12116 . [ Finalize] ( #finalize )
1312
@@ -23,7 +22,6 @@ If you find any mistakes, misleading or some confusion feel free to create an is
2322const { DBSQLClient } = require (' @databricks/sql' );
2423
2524const client = new DBSQLClient ();
26- const utils = DBSQLClient .utils ;
2725
2826client
2927 .connect ({
@@ -37,20 +35,17 @@ client
3735 const createTableOperation = await session .executeStatement (
3836 ' CREATE TABLE IF NOT EXISTS pokes (foo INT, bar STRING)' ,
3937 );
40- await utils . waitUntilReady (createTableOperation, false , () => {} );
38+ await createTableOperation . fetchAll ( );
4139 await createTableOperation .close ();
4240
4341 const loadDataOperation = await session .executeStatement (' INSERT INTO pokes VALUES(123, "Hello, world!"' );
44- await utils . waitUntilReady (loadDataOperation, false , () => {} );
42+ await loadDataOperation . fetchAll ( );
4543 await loadDataOperation .close ();
4644
4745 const selectDataOperation = await session .executeStatement (' SELECT * FROM pokes' , { runAsync: true });
48- await utils .waitUntilReady (selectDataOperation, false , () => {});
49- await utils .fetchAll (selectDataOperation);
46+ const result = await selectDataOperation .fetchAll (selectDataOperation);
5047 await selectDataOperation .close ();
5148
52- const result = utils .getResult (selectDataOperation).getValue ();
53-
5449 console .log (JSON .stringify (result, null , ' \t ' ));
5550
5651 await session .close ();
@@ -71,9 +66,9 @@ client.on('error', (error) => {
7166});
7267```
7368
74- ## HiveSession
69+ ## DBSQLSession
7570
76- After you connect to the server you should open session to start working with Hive server.
71+ After you connect to the server you should open session to start working with server.
7772
7873``` javascript
7974...
@@ -84,9 +79,9 @@ To open session you must provide [OpenSessionRequest](/lib/hive/Commands/OpenSes
8479
8580Into "configuration" you may set any of the configurations that required for the session of your Hive instance.
8681
87- After the session is opened you will have the [ HiveSession ] ( /lib/HiveSession .ts ) instance.
82+ After the session is opened you will have the [ DBSQLSession ] ( /lib/DBSQLSession .ts ) instance.
8883
89- Class [ HiveSession ] ( /lib/HiveSession .ts ) is a facade for API that works with [ SessionHandle] ( /lib/hive/Types/index.ts#L77 ) .
84+ Class [ DBSQLSession ] ( /lib/DBSQLSession .ts ) is a facade for API that works with [ SessionHandle] ( /lib/hive/Types/index.ts#L77 ) .
9085
9186The method you will use the most is ` executeStatement `
9287
@@ -100,81 +95,44 @@ const operation = await session.executeStatement(
10095
10196- "statement" is DDL/DML statement (CREATE TABLE, INSERT, UPDATE, SELECT, LOAD, etc.)
10297
103- - [ options] ( /lib/contracts/IHiveSession .ts#L14 )
98+ - [ options] ( /lib/contracts/IDBSQLSession .ts#L14 )
10499
105100 - runAsync allows executing operation asynchronously.
106101
107102 - confOverlay overrides session configuration properties.
108103
109104 - timeout is the maximum time to execute an operation. It has Buffer type because timestamp in Hive has capacity 64. So for such value, you should use [ node-int64] ( https://www.npmjs.com/package/node-int64 ) npm module.
110105
111- To know other methods see [ IHiveSession] ( /lib/contracts/IHiveSession.ts ) and [ examples/session.js] ( /examples/session.js ) .
112-
113- ## HiveOperation
106+ To know other methods see [ IDBSQLSession] ( /lib/contracts/IDBSQLSession.ts ) and [ examples/session.js] ( /examples/session.js ) .
114107
115- In most cases, HiveSession methods return [ HiveOperation ] ( /lib/HiveOperation.ts ) , which helps you to retrieve requested data.
108+ ## DBSQLOperation
116109
117- After you fetch the result, the operation will have [ TableSchema ] ( /lib/hive/Types/index .ts#L143 ) and data (Array< [ RowSet ] ( /lib/hive/Types/index.ts#L218 ) >) .
110+ In most cases, DBSQLSession methods return [ DBSQLOperation ] ( /lib/DBSQLOperation .ts ) , which helps you to retrieve requested data .
118111
119- ### HiveUtils
112+ After you fetch the result, the operation will have [ TableSchema ] ( /lib/hive/Types/index.ts#L143 ) and data.
120113
121- Operation is executed asynchronously, so before retrieving the result, you have to wait until it has finished state.
114+ Operation is executed asynchronously, but ` fetchChunk ` /` fetchAll ` will wait until it has finished. You can
115+ get current status of operation any time using a dedicated method:
122116
123117``` javascript
124118...
125119const response = await operation .status ();
126120const isReady = response .operationState === TCLIService_types .TOperationState .FINISHED_STATE ;
127121```
128122
129- Also, the result is fetched by portions, the size of a portion you can set by method [ setMaxRows() ] ( /lib/HiveOperation.ts#L115 ) .
123+ Also, the result is fetched by portions, the size of a portion you can pass as option to ` fetchChunk ` / ` fetchAll ` .
130124
131125``` javascript
132126...
133- operation .setMaxRows (500 );
134- const status = await operation .fetch ();
127+ const results = await operation .fetchChunk ({ maxRows: 500 });
135128```
136129
137- After you fetch all data and you have schema and set of data, you can transfrom data in readable format .
130+ Schema becomes available after you start fetching data.
138131
139132``` javascript
140133...
134+ await operation .fetchChunk ();
141135const schema = operation .getSchema ();
142- const data = operation .getData ();
143- ```
144-
145- To simplify this process, you may use [ HiveUtils] ( /lib/utils/HiveUtils.ts ) .
146-
147- ``` typescript
148- /**
149- * Executes until operation has status finished or has one of the invalid states.
150- *
151- * @param operation operation to perform
152- * @param progress flag for operation status command. If it sets true, response will include progressUpdateResponse with progress information
153- * @param callback if callback specified it will be called each time the operation status response received and it will be passed as first parameter
154- */
155- waitUntilReady (
156- operation : IOperation ,
157- progress ?: boolean ,
158- callback ?: Function
159- ): Promise < IOperation >
160-
161- /**
162- * Fetches data until operation hasMoreRows.
163- *
164- * @param operation
165- */
166- fetchAll (operation : IOperation ): Promise < IOperation >
167-
168- /**
169- * Transforms operation result
170- *
171- * @param operation operation to perform
172- * @param resultHandler you may specify your own handler. If not specified the result is transformed to JSON
173- */
174- getResult (
175- operation : IOperation ,
176- resultHandler ?: IOperationResult
177- ): IOperationResult
178136```
179137
180138_ NOTICE_
@@ -187,19 +145,13 @@ For more details see [IOperation](/lib/contracts/IOperation.ts).
187145### Example
188146
189147``` javascript
190- const { DBSQLClient } = require (' @databricks/sql' );
191- const utils = DBSQLClient .utils ;
192148...
193- await utils .waitUntilReady (
194- operation,
195- true ,
196- (stateResponse ) => {
197- console .log (stateResponse .taskStatus );
198- }
199- );
200- await utils .fetchAll (operation);
201-
202- const result = utils .getResult (operation).getValue ();
149+ const result = await operation .fetchAll ({
150+ progress: true ,
151+ callback : (stateResponse ) => {
152+ console .log (stateResponse .taskStatus );
153+ },
154+ });
203155```
204156
205157## Status
0 commit comments