@@ -14,6 +14,7 @@ const genericPool = require('generic-pool');
1414const { BaseDriver } = require ( '@cubejs-backend/base-driver' ) ;
1515const Connection = require ( 'jshs2/lib/Connection' ) ;
1616const IDLFactory = require ( 'jshs2/lib/common/IDLFactory' ) ;
17+
1718const {
1819 HS2Util,
1920 IDLContainer,
@@ -22,8 +23,8 @@ const {
2223} = jshs2 ;
2324
2425const newIDL = [
25- " 2.1.1" ,
26- " 2.2.3" ,
26+ ' 2.1.1' ,
27+ ' 2.2.3' ,
2728 '2.3.4' ,
2829] ;
2930
@@ -47,20 +48,11 @@ IDLFactory.extractConfig = (config) => {
4748
4849const TSaslTransport = require ( './TSaslTransport' ) ;
4950
50- /**
51- * Hive driver class.
52- */
5351class HiveDriver extends BaseDriver {
54- /**
55- * Returns default concurrency value.
56- */
5752 static getDefaultConcurrency ( ) {
5853 return 2 ;
5954 }
6055
61- /**
62- * Class constructor.
63- */
6456 constructor ( config = { } ) {
6557 super ( {
6658 testConnectionTimeout : config . testConnectionTimeout ,
@@ -99,7 +91,7 @@ class HiveDriver extends BaseDriver {
9991 ) ;
10092 const hiveConnection = new HiveConnection ( configuration , idl ) ;
10193 hiveConnection . cursor = await hiveConnection . connect ( ) ;
102- hiveConnection . cursor . getOperationStatus = function ( ) {
94+ hiveConnection . cursor . getOperationStatus = function getOperationStatus ( ) {
10395 return new Promise ( ( resolve , reject ) => {
10496 const serviceType = this . Conn . IDL . ServiceType ;
10597 const request = new serviceType . TGetOperationStatusReq ( {
@@ -114,7 +106,7 @@ class HiveDriver extends BaseDriver {
114106 res . operationState === serviceType . TOperationState . ERROR_STATE
115107 ) {
116108 // eslint-disable-next-line no-unused-vars
117- const [ errorMessage , infoMessage , message ] = HS2Util . getThriftErrorMessage (
109+ const [ _errorMessage , _infoMessage , message ] = HS2Util . getThriftErrorMessage (
118110 res . status , 'ExecuteStatement operation fail'
119111 ) ;
120112
@@ -145,7 +137,7 @@ class HiveDriver extends BaseDriver {
145137 // eslint-disable-next-line no-underscore-dangle
146138 const conn = await this . pool . _factory . create ( ) ;
147139 try {
148- return await this . query ( 'SELECT 1' , [ ] , conn ) ;
140+ return await this . handleQuery ( 'SELECT 1' , [ ] , conn ) ;
149141 } finally {
150142 // eslint-disable-next-line no-underscore-dangle
151143 await this . pool . _factory . destroy ( conn ) ;
@@ -158,12 +150,17 @@ class HiveDriver extends BaseDriver {
158150 } ) ;
159151 }
160152
161- async query ( query , values , conn ) {
153+ async query ( query , values , _opts ) {
154+ return this . handleQuery ( query , values ) ;
155+ }
156+
157+ async handleQuery ( query , values , conn ) {
162158 values = values || [ ] ;
163159 const sql = SqlString . format ( query , values ) ;
164160 const connection = conn || await this . pool . acquire ( ) ;
165161 try {
166162 const execResult = await connection . cursor . execute ( sql ) ;
163+ // eslint-disable-next-line no-constant-condition
167164 while ( true ) {
168165 const status = await connection . cursor . getOperationStatus ( ) ;
169166 if ( HS2Util . isFinish ( connection . cursor , status ) ) {
@@ -176,6 +173,7 @@ class HiveDriver extends BaseDriver {
176173 let allRows = [ ] ;
177174 if ( execResult . hasResultSet ) {
178175 const schema = await connection . cursor . getSchema ( ) ;
176+ // eslint-disable-next-line no-constant-condition
179177 while ( true ) {
180178 const results = await connection . cursor . fetchBlock ( ) ;
181179 allRows . push ( ...( results . rows ) ) ;
@@ -198,12 +196,12 @@ class HiveDriver extends BaseDriver {
198196 }
199197
200198 async tablesSchema ( ) {
201- const tables = await this . query ( `show tables in ${ this . config . dbName } ` ) ;
199+ const tables = await this . handleQuery ( `show tables in ${ this . config . dbName } ` ) ;
202200
203201 return {
204202 [ this . config . dbName ] : ( await Promise . all ( tables . map ( async table => {
205203 const tableName = table . tab_name || table . tableName ;
206- const columns = await this . query ( `describe ${ this . config . dbName } .${ tableName } ` ) ;
204+ const columns = await this . handleQuery ( `describe ${ this . config . dbName } .${ tableName } ` ) ;
207205 return {
208206 [ tableName ] : columns . map ( c => ( { name : c . col_name , type : c . data_type } ) )
209207 } ;
0 commit comments