Skip to content

Commit 65acd30

Browse files
committed
v0.1.11 - Kerberos connection - default namespace handling
1 parent 9a8917a commit 65acd30

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "HBase",
3-
"version": "0.1.10",
4-
"versionDate": "2019-01-18",
3+
"version": "0.1.11",
4+
"versionDate": "2019-01-22",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "2.3.2",

reverse_engineering/api.js

+48-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var state = {
1010
connectionInfo: {}
1111
};
1212
var clientKrb = null;
13+
const DEFAULT_NAMESPACE = 'No Namespace'
1314

1415
module.exports = {
1516
connect: function(connectionInfo, logger, cb, app){
@@ -73,7 +74,7 @@ module.exports = {
7374

7475
getNamespacesList(connectionInfo, logger).then(namespaces => {
7576
async.mapSeries(namespaces, (namespace, callback) => {
76-
getTablesList(connectionInfo, namespace)
77+
getTablesList(connectionInfo, namespace, logger)
7778
.then(res => {
7879
return callback(null, res);
7980
}, (err) => {
@@ -238,26 +239,64 @@ function fetchRequest(query, connectionInfo, logger){
238239
});
239240
}
240241

242+
const getTableNames = (connectionInfo, logger) => {
243+
let query = `${getHostURI(connectionInfo)}/`;
244+
245+
return fetchRequest(query, connectionInfo, logger).then(res => {
246+
return _.get(res, 'table', []).map(table => table.name);
247+
});
248+
};
249+
250+
const splitTableName = name => name.indexOf(':') !== -1 ? name.split(':') : ['', name];
251+
252+
const getNamespacesFromTables = (tables) => {
253+
return Promise.resolve(_.uniq(tables.map((tableName) => splitTableName(tableName || '').shift())));
254+
};
255+
241256
function getNamespacesList(connectionInfo, logger){
242257
let query = `${getHostURI(connectionInfo)}/namespaces`;
243258

244259
return fetchRequest(query, connectionInfo, logger).then(res => {
245-
return res.Namespace.filter(item => item !== 'hbase');
260+
return res.Namespace;
261+
}, err => {
262+
const areNamespacesNotAllowed = (err.code === 405);
263+
264+
if (areNamespacesNotAllowed) {
265+
return getTableNames(connectionInfo, logger).then(getNamespacesFromTables);
266+
} else {
267+
return Promise.reject(err);
268+
}
269+
}).then(res => {
270+
return res.filter(item => item !== 'hbase');
246271
});
247272
}
248273

249-
function getTablesList(connectionInfo, namespace){
274+
function getTablesList(connectionInfo, namespace, logger){
250275
let query = `${getHostURI(connectionInfo)}/namespaces/${namespace}/tables`;
251276

252-
return fetchRequest(query, connectionInfo).then(res => {
277+
return fetchRequest(query, connectionInfo, logger).then(res => {
253278
return res;
279+
}, err => {
280+
const areNamespacesNotAllowed = (err.code === 404);
281+
282+
if (areNamespacesNotAllowed) {
283+
return getTableNames(connectionInfo, logger).then(filterTables.bind(null, namespace)).then(tableNames => ({ table: tableNames }));
284+
} else {
285+
return Promise.reject(err);
286+
}
254287
});
255288
}
256289

290+
const filterTables = (namespace, tableNames) => {
291+
return tableNames.map(splitTableName)
292+
.filter(([ namespaceName ]) => namespaceName === namespace)
293+
.map(([ns, name]) => ({ name }));
294+
};
295+
257296
function prepareDataItems(namespaces, items){
258297
return items.map((item, index) => {
259298
return {
260-
dbName: namespaces[index],
299+
dbName: namespaces[index] || DEFAULT_NAMESPACE,
261300
dbCollections: item.table.map(table => {
262301
return table.name;
263302
})
@@ -266,7 +305,7 @@ function prepareDataItems(namespaces, items){
266305
}
267306

268307
function getTableSchema(namespace, table, connectionInfo){
269-
let query = `${getHostURI(connectionInfo)}/${namespace}:${table}/schema`;
308+
let query = `${getHostURI(connectionInfo)}/${getNamespaceTableName(namespace, table)}/schema`;
270309

271310
return fetchRequest(query, connectionInfo).then(res => {
272311
return res;
@@ -281,6 +320,8 @@ function getClusterVersion(connectionInfo, logger){
281320
});
282321
}
283322

323+
const getNamespaceTableName = (namespace, table) => (namespace && namespace !== DEFAULT_NAMESPACE) ? `${namespace}:${table}` : table;
324+
284325
function handleRows(rows){
285326
let data = {
286327
hashTable: {},
@@ -495,7 +536,7 @@ const getScannerBody = (recordSamplingSettings) => {
495536
};
496537

497538
const scanDocuments = (namespace, table, recordSamplingSettings, connectionInfo) => {
498-
const tableName = `${namespace}:${table}`;
539+
const tableName = getNamespaceTableName(namespace, table);
499540
let query = `${getHostURI(connectionInfo)}/${tableName}/scanner`;
500541

501542
return getRequestOptions()

reverse_engineering/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"dependencies": {
77
"async": "2.6.0",
88
"node-fetch": "2.1.1"
9-
},
10-
"installed": true
9+
}
1110
}

0 commit comments

Comments
 (0)