Skip to content

Commit 06eb49f

Browse files
committed
v0.1.12 with JSON sampling
1 parent 48d1725 commit 06eb49f

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Cassandra",
3-
"version": "0.1.11",
4-
"versionDate": "2018-08-18",
3+
"version": "0.1.12",
4+
"versionDate": "2018-08-22",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "2.1.x",

reverse_engineering/api.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const async = require('async');
44
const cassandra = require('./cassandraHelper');
55
const systemKeyspaces = require('./package').systemKeyspaces;
66

7-
87
module.exports = {
98
connect: function(connectionInfo, logger, cb){
109
logger.clear();
@@ -53,9 +52,7 @@ module.exports = {
5352

5453
const tables = data.collectionData.collections;
5554
const keyspacesNames = data.collectionData.dataBaseNames;
56-
const fieldInference = data.fieldInference;
5755
const includeEmptyCollection = data.includeEmptyCollection;
58-
const includeSystemCollection = data.includeSystemCollection;
5956
const recordSamplingSettings = data.recordSamplingSettings;
6057

6158
async.map(keyspacesNames, (keyspaceName, keyspaceCallback) => {
@@ -110,11 +107,11 @@ module.exports = {
110107
return packageData;
111108
})
112109
.then(packageData => {
113-
return packageData && columns && columns.length ? cassandra.scanRecords(keyspaceName, tableName) : null;
110+
return packageData && columns && columns.length ? cassandra.scanRecords(keyspaceName, tableName, recordSamplingSettings) : null;
114111
})
115112
.then(columns => {
116113
if (columns) {
117-
packageData.documents = columns.rows;
114+
packageData.documents = columns;
118115
}
119116
return tableCallback(null, packageData);
120117
})

reverse_engineering/cassandraHelper.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const connect = (info) => {
2020

2121
const close = () => {
2222
if (state.client) {
23+
state.client.shutdown();
2324
state.client = null;
2425
}
2526
};
@@ -73,7 +74,7 @@ const getColumnInfo = (keyspace, table) => {
7374
};
7475

7576
const prepareConnectionDataItem = (keyspace, tables) => {
76-
let connectionDataItem = {
77+
const connectionDataItem = {
7778
dbName: keyspace,
7879
dbCollections: tables
7980
};
@@ -93,10 +94,24 @@ const getTableSchema = (columns, udtHash) => {
9394
return { properties: schema };
9495
};
9596

96-
const scanRecords = (keyspace, table) => {
97-
const options = { prepare : true , fetchSize : 1000 };
98-
const query = `SELECT * FROM "${keyspace}"."${table}"`;
99-
return execute(query);
97+
const scanRecords = (keyspace, table, recordSamplingSettings) => {
98+
const defaultCount = 1000;
99+
const query = `SELECT COUNT(*) FROM "${keyspace}"."${table}"`;
100+
101+
return execute(query)
102+
.then(count => new Promise((resolve, reject) => {
103+
const rowsCount = _.get(count, 'rows[0].count.low', defaultCount);
104+
const size = getSampleDocSize(rowsCount, recordSamplingSettings)
105+
const options = { prepare : true , autoPage: true };
106+
const selQuery = `SELECT * FROM "${keyspace}"."${table}" LIMIT ${size}`;
107+
let rows = [];
108+
109+
state.client.eachRow(selQuery, [], options, function(n, row) {
110+
rows.push(row)
111+
}, (err, rs) => {
112+
return (err ? reject(err) : resolve(rows))
113+
});
114+
}));
100115
};
101116

102117

@@ -148,7 +163,7 @@ const handlePartitionKeys = (partitionKeys) => {
148163

149164
const handleClusteringKeys = (table) => {
150165
return (table.clusteringKeys || []).map((item, index) => {
151-
let clusteringOrder = table.clusteringOrder ? table.clusteringOrder[index] : '';
166+
const clusteringOrder = table.clusteringOrder ? table.clusteringOrder[index] : '';
152167
return {
153168
name: item.name,
154169
type: getKeyOrder(clusteringOrder)
@@ -243,8 +258,6 @@ const handleUDA = (uda) => {
243258
return udaData;
244259
};
245260

246-
247-
248261
const getPackageData = (data, includeEmptyCollection) => {
249262
let packageData = {
250263
dbName: data.keyspaceName,
@@ -280,16 +293,14 @@ const filterKeyspaces = (keyspaces, systemKeyspaces) => {
280293
return _.difference(keyspaces, systemKeyspaces || []);
281294
};
282295

283-
/*
296+
284297
const getSampleDocSize = (count, recordSamplingSettings) => {
285-
let per = recordSamplingSettings.relative.value;
298+
const per = recordSamplingSettings.relative.value;
286299
return (recordSamplingSettings.active === 'absolute')
287300
? recordSamplingSettings.absolute.value
288301
: Math.round( count/100 * per);
289302
};
290303

291-
*/
292-
293304
module.exports = {
294305
connect,
295306
close,

0 commit comments

Comments
 (0)