Skip to content

Commit e81aba9

Browse files
authored
fix(hive-driver): Follow DriverInterface for query method, fix #6281 (#6282)
1 parent 5126d00 commit e81aba9

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

packages/cubejs-hive-driver/package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
"engines": {
1212
"node": "^14.0.0 || ^16.0.0 || >=17.0.0"
1313
},
14-
"main": "driver/HiveDriver.js",
14+
"main": "src/HiveDriver.js",
15+
"scripts": {
16+
"lint": "eslint src/* --ext .ts",
17+
"lint:fix": "eslint --fix src/* --ext .ts"
18+
},
1519
"dependencies": {
1620
"@cubejs-backend/base-driver": "^0.32.2",
21+
"@cubejs-backend/shared": "^0.32.2",
1722
"generic-pool": "^3.6.0",
1823
"jshs2": "^0.4.4",
1924
"sasl-plain": "^0.1.0",
@@ -22,7 +27,13 @@
2227
"thrift": "^0.9.3"
2328
},
2429
"license": "Apache-2.0",
30+
"devDependencies": {
31+
"@cubejs-backend/linter": "^0.32.0"
32+
},
2533
"publishConfig": {
2634
"access": "public"
35+
},
36+
"eslintConfig": {
37+
"extends": "../cubejs-linter"
2738
}
2839
}

packages/cubejs-hive-driver/driver/HiveDriver.js renamed to packages/cubejs-hive-driver/src/HiveDriver.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const genericPool = require('generic-pool');
1414
const { BaseDriver } = require('@cubejs-backend/base-driver');
1515
const Connection = require('jshs2/lib/Connection');
1616
const IDLFactory = require('jshs2/lib/common/IDLFactory');
17+
1718
const {
1819
HS2Util,
1920
IDLContainer,
@@ -22,8 +23,8 @@ const {
2223
} = jshs2;
2324

2425
const 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

4849
const TSaslTransport = require('./TSaslTransport');
4950

50-
/**
51-
* Hive driver class.
52-
*/
5351
class 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
};

packages/cubejs-hive-driver/driver/TSaslTransport.js renamed to packages/cubejs-hive-driver/src/TSaslTransport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Frame {
2929
this.fullyRead = !requireMoreData;
3030
const sourceEnd = requireMoreData ? data.length : dataEnd;
3131
data.copy(this.buffer, this.writeCursor, offset, sourceEnd);
32-
this.writeCursor = this.writeCursor + (sourceEnd - offset);
32+
this.writeCursor += (sourceEnd - offset);
3333

3434
let frames = [this];
3535

0 commit comments

Comments
 (0)