@@ -20,6 +20,7 @@ const connect = (info) => {
20
20
21
21
const close = ( ) => {
22
22
if ( state . client ) {
23
+ state . client . shutdown ( ) ;
23
24
state . client = null ;
24
25
}
25
26
} ;
@@ -73,7 +74,7 @@ const getColumnInfo = (keyspace, table) => {
73
74
} ;
74
75
75
76
const prepareConnectionDataItem = ( keyspace , tables ) => {
76
- let connectionDataItem = {
77
+ const connectionDataItem = {
77
78
dbName : keyspace ,
78
79
dbCollections : tables
79
80
} ;
@@ -93,10 +94,24 @@ const getTableSchema = (columns, udtHash) => {
93
94
return { properties : schema } ;
94
95
} ;
95
96
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
+ } ) ) ;
100
115
} ;
101
116
102
117
@@ -148,7 +163,7 @@ const handlePartitionKeys = (partitionKeys) => {
148
163
149
164
const handleClusteringKeys = ( table ) => {
150
165
return ( table . clusteringKeys || [ ] ) . map ( ( item , index ) => {
151
- let clusteringOrder = table . clusteringOrder ? table . clusteringOrder [ index ] : '' ;
166
+ const clusteringOrder = table . clusteringOrder ? table . clusteringOrder [ index ] : '' ;
152
167
return {
153
168
name : item . name ,
154
169
type : getKeyOrder ( clusteringOrder )
@@ -243,8 +258,6 @@ const handleUDA = (uda) => {
243
258
return udaData ;
244
259
} ;
245
260
246
-
247
-
248
261
const getPackageData = ( data , includeEmptyCollection ) => {
249
262
let packageData = {
250
263
dbName : data . keyspaceName ,
@@ -280,16 +293,14 @@ const filterKeyspaces = (keyspaces, systemKeyspaces) => {
280
293
return _ . difference ( keyspaces , systemKeyspaces || [ ] ) ;
281
294
} ;
282
295
283
- /*
296
+
284
297
const getSampleDocSize = ( count , recordSamplingSettings ) => {
285
- let per = recordSamplingSettings.relative.value;
298
+ const per = recordSamplingSettings . relative . value ;
286
299
return ( recordSamplingSettings . active === 'absolute' )
287
300
? recordSamplingSettings . absolute . value
288
301
: Math . round ( count / 100 * per ) ;
289
302
} ;
290
303
291
- */
292
-
293
304
module . exports = {
294
305
connect,
295
306
close,
0 commit comments