-
Notifications
You must be signed in to change notification settings - Fork 73
/
scanner.coffee
217 lines (215 loc) · 9.47 KB
/
scanner.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
test = require './test'
describe 'scanner', ->
@timeout 0
it 'stream readable', (next) ->
test.client (err, client) ->
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_stream_readable_1', column:'node_column_family:', $:'v 1.3' }
{ key:'test_scanner_stream_readable_11', column:'node_column_family:', $:'v 1.1' }
{ key:'test_scanner_stream_readable_111', column:'node_column_family:', $:'v 1.2' }
{ key:'test_scanner_stream_readable_2', column:'node_column_family:', $:'v 2.2' }
], (err, success) ->
return next err if err
scanner = client
.table('node_table')
.scan
startRow: 'test_scanner_get_startRow_11'
maxVersions: 1
rows = []
scanner.on 'readable', ->
while chunk = scanner.read()
rows.push chunk
scanner.on 'error', (err) ->
next err
scanner.on 'end', ->
rows.length.should.be.above 2
next()
it 'Get startRow', (next) ->
test.client (err, client) ->
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_get_startRow_1', column:'node_column_family:', $:'v 1.3' }
{ key:'test_scanner_get_startRow_11', column:'node_column_family:', $:'v 1.1' }
{ key:'test_scanner_get_startRow_111', column:'node_column_family:', $:'v 1.2' }
{ key:'test_scanner_get_startRow_2', column:'node_column_family:', $:'v 2.2' }
], (err, success) ->
return next err if err
client
.table('node_table')
.scan
startRow: 'test_scanner_get_startRow_11'
maxVersions: 1
, (err, rows) ->
return next err if err
# http:#brunodumon.wordpress.com/2010/02/17/building-indexes-using-hbase-mapping-strings-numbers-and-dates-onto-bytes/
# Technically, you would set the start row for the scanner to France
# and stop the scanning by using a RowFilter with a BinaryPrefixComparator
rows.length.should.be.above 2
rows[0].key.should.eql 'test_scanner_get_startRow_11'
rows[0].column.should.eql 'node_column_family:'
rows[1].key.should.eql 'test_scanner_get_startRow_111'
rows[1].column.should.eql 'node_column_family:'
next()
it 'Get startRow and endRow', (next) ->
test.client (err, client) ->
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_get_startEndRow_1', column:'node_column_family:', $:'v 1.3' }
{ key:'test_scanner_get_startEndRow_11', column:'node_column_family:', $:'v 1.1' }
{ key:'test_scanner_get_startEndRow_111', column:'node_column_family:', $:'v 1.2' }
{ key:'test_scanner_get_startEndRow_2', column:'node_column_family:', $:'v 2.2' }
], (err, success) ->
return next err if err
client
.table('node_table')
.scan
startRow: 'test_scanner_get_startEndRow_11'
endRow: 'test_scanner_get_startEndRow_2'
maxVersions: 1
, (err, rows) ->
return next err if err
# http:#brunodumon.wordpress.com/2010/02/17/building-indexes-using-hbase-mapping-strings-numbers-and-dates-onto-bytes/
# Technically, you would set the start row for the scanner to France
# and stop the scanning by using a RowFilter with a BinaryPrefixComparator
rows.length.should.eql 2
rows[0].key.should.eql 'test_scanner_get_startEndRow_11'
rows[0].column.should.eql 'node_column_family:'
rows[1].key.should.eql 'test_scanner_get_startEndRow_111'
rows[1].column.should.eql 'node_column_family:'
next()
it 'Get columns', (next) ->
test.client (err, client) ->
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_get_columns_1', column:'node_column_family:c1', $:'v 1.1' }
{ key:'test_scanner_get_columns_1', column:'node_column_family:c2', $:'v 1.2' }
{ key:'test_scanner_get_columns_1', column:'node_column_family:c3', $:'v 1.3' }
{ key:'test_scanner_get_columns_1', column:'node_column_family:c4', $:'v 1.4' }
{ key:'test_scanner_get_columns_2', column:'node_column_family:c1', $:'v 2.1' }
{ key:'test_scanner_get_columns_2', column:'node_column_family:c2', $:'v 2.2' }
{ key:'test_scanner_get_columns_2', column:'node_column_family:c3', $:'v 2.3' }
{ key:'test_scanner_get_columns_2', column:'node_column_family:c4', $:'v 2.4' }
{ key:'test_scanner_get_columns_3', column:'node_column_family:c1', $:'v 3.1' }
{ key:'test_scanner_get_columns_3', column:'node_column_family:c2', $:'v 3.2' }
{ key:'test_scanner_get_columns_3', column:'node_column_family:c3', $:'v 3.3' }
{ key:'test_scanner_get_columns_3', column:'node_column_family:c4', $:'v 3.4' }
], (err, success) ->
return next err if err
client
.table('node_table')
.scan
startRow: 'test_scanner_get_columns_1'
endRow: 'test_scanner_get_columns_3'
maxVersions: 1
column: ['node_column_family:c4','node_column_family:c2']
, (err, rows) ->
return next err if err
rows.length.should.eql 4
keys = rows.map (row) -> row.key
keys.should.eql [ 'test_scanner_get_columns_1',
'test_scanner_get_columns_1',
'test_scanner_get_columns_2',
'test_scanner_get_columns_2' ]
columns = rows.map (row) -> row.column
columns.should.eql [ 'node_column_family:c2',
'node_column_family:c4',
'node_column_family:c2',
'node_column_family:c4' ]
next()
it 'Option maxVersions', (next) ->
test.client (err, client) ->
time = (new Date).getTime()
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_maxversions_1', column:'node_column_family:c', timestamp: time+1, $:'v 1.1' }
{ key:'test_scanner_maxversions_1', column:'node_column_family:c', timestamp: time+2, $:'v 1.2' }
{ key:'test_scanner_maxversions_1', column:'node_column_family:c', timestamp: time+3, $:'v 1.3' }
{ key:'test_scanner_maxversions_1', column:'node_column_family:c', timestamp: time+4, $:'v 1.4' }
], (err, success) ->
return next err if err
client
.table('node_table')
.scan
startRow: 'test_scanner_maxversions_1'
endRow: 'test_scanner_maxversions_11'
column: 'node_column_family:c'
maxVersions: 3
, (err, cells) ->
return next err if err
cells.length.should.eql 3
next()
it 'Get startTime and endTime', (next) ->
test.client (err, client) ->
client
.table('node_table')
.row()
.put [
{ key:'test_scanner_get_startTime_1', column:'node_column_family:', timestamp: 1181558248913, $:'v 1.3' }
{ key:'test_scanner_get_startTime_11', column:'node_column_family:', timestamp: 1181558248913, $:'v 1.1' }
{ key:'test_scanner_get_startTime_111', column:'node_column_family:', timestamp: 1181558248913, $:'v 1.2' }
{ key:'test_scanner_get_startTime_2', column:'node_column_family:', timestamp: 1181558248914, $:'v 2.2' }
], (err, success) ->
return next err if err
client
.table('node_table')
.scan
startTime: 1181558248913
endTime: 1181558248914
maxVersions: 1
, (err, cells) ->
return next err if err
# http:#brunodumon.wordpress.com/2010/02/17/building-indexes-using-hbase-mapping-strings-numbers-and-dates-onto-bytes/
# Technically, you would set the start row for the scanner to France
# and stop the scanning by using a RowFilter with a BinaryPrefixComparator
cells.length.should.eql 3
cells[0].key.should.eql 'test_scanner_get_startTime_1'
cells[0].timestamp.should.eql 1181558248913
cells[1].key.should.eql 'test_scanner_get_startTime_11'
cells[1].timestamp.should.eql 1181558248913
cells[2].key.should.eql 'test_scanner_get_startTime_111'
cells[2].timestamp.should.eql 1181558248913
next()
it 'fetch records in batch', (next) ->
test.client (err, client) ->
data = for i in [0...1000] # 1000000
{ key: 'test_scanner_fetch_records_in_batch', column: "node_column_family:#{i}", $: 'v 1.3' }
count = init: 0, scan: 0, readable: 0, read: 0
client.on 'request', ({options}) ->
count.init++ if /^(^|\/rest)\/node_table\/scanner$/.test options.path
count.scan++ if /^(^|\/rest)\/node_table\/scanner\//.test options.path
client
.table('node_table')
.row()
.put data, (err, success) ->
return next err if err
client
.table('node_table')
.scan
startRow: 'test_scanner_fetch_records_in_batch'
endRow: 'test_scanner_fetch_records_in_batch_'
maxVersions: 1
batch: 10
.on 'readable', ->
count.readable++
while record = @read()
count.read++
.on 'error', (err) ->
next err
.on 'end', ->
count.init.should.eql 1
count.scan.should.eql 102
# Node.js <10 = 1001, >10 = 101
count.readable.should.equalOneOf [101, 1001]
count.read.should.eql 1000
next()