Skip to content

Commit 1f20225

Browse files
committed
fix(hive-driver): SparkSQL compatibility
1 parent 5a5fffd commit 1f20225

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

packages/cubejs-hive-driver/driver/HiveDriver.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,32 @@ class HiveDriver extends BaseDriver {
6262
);
6363
const hiveConnection = new HiveConnection(configuration, idl);
6464
hiveConnection.cursor = await hiveConnection.connect();
65+
hiveConnection.cursor.getOperationStatus = function () {
66+
return new Promise((resolve, reject) => {
67+
const serviceType = this.Conn.IDL.ServiceType;
68+
const request = new serviceType.TGetOperationStatusReq({
69+
operationHandle: this.OperationHandle,
70+
});
71+
72+
this.Client.GetOperationStatus(request, (err, res) => {
73+
if (err) {
74+
reject(new Error(err));
75+
} else if (
76+
res.status.statusCode === serviceType.TStatusCode.ERROR_STATUS ||
77+
res.operationState === serviceType.TOperationState.ERROR_STATE
78+
) {
79+
// eslint-disable-next-line no-unused-vars
80+
const [errorMessage, infoMessage, message] = HS2Util.getThriftErrorMessage(
81+
res.status, 'ExecuteStatement operation fail'
82+
);
83+
84+
reject(new Error(res.errorMessage || message));
85+
} else {
86+
resolve(res.operationState);
87+
}
88+
});
89+
});
90+
};
6591
return hiveConnection;
6692
},
6793
destroy: (connection) => connection.close()
@@ -119,7 +145,7 @@ class HiveDriver extends BaseDriver {
119145
}
120146
allRows = allRows.map(
121147
row => schema
122-
.map((column, i) => ({ [column.columnName.replace(/^_u(.+?)\./, '')]: row[i] }))
148+
.map((column, i) => ({ [column.columnName.replace(/^_u(.+?)\./, '')]: row[i] === 'NULL' ? null : row[i] })) // TODO NULL
123149
.reduce((a, b) => ({ ...a, ...b }), {})
124150
);
125151
}
@@ -136,9 +162,10 @@ class HiveDriver extends BaseDriver {
136162

137163
return {
138164
[this.config.dbName]: (await Promise.all(tables.map(async table => {
139-
const columns = await this.query(`describe ${this.config.dbName}.${table.tab_name}`);
165+
const tableName = table.tab_name || table.tableName;
166+
const columns = await this.query(`describe ${this.config.dbName}.${tableName}`);
140167
return {
141-
[table.tab_name]: columns.map(c => ({ name: c.col_name, type: c.data_type }))
168+
[tableName]: columns.map(c => ({ name: c.col_name, type: c.data_type }))
142169
};
143170
}))).reduce((a, b) => ({ ...a, ...b }), {})
144171
};

0 commit comments

Comments
 (0)