1
1
package simdjson
2
2
3
3
import (
4
- "bytes"
5
4
"encoding/binary"
6
5
"fmt"
7
6
"io/ioutil"
@@ -186,7 +185,7 @@ func TestDemoNdjson(t *testing.T) {
186
185
}
187
186
188
187
func TestNdjsonCountWhere (t * testing.T ) {
189
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
188
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
190
189
191
190
pj := internalParsedJson {}
192
191
pj .initialize (len (ndjson ) * 3 / 2 )
@@ -199,7 +198,12 @@ func TestNdjsonCountWhere(t *testing.T) {
199
198
}
200
199
201
200
func TestNdjsonCountWhere2 (t * testing.T ) {
202
- ndjson := getPatchedNdjson ("testdata/RC_2009-01.json.zst" )
201
+ ndjson := loadFile ("testdata/RC_2009-01.json.zst" )
202
+ // Test trimming
203
+ b := make ([]byte , 0 , len (ndjson )+ 4 )
204
+ b = append (b , '\n' , '\n' )
205
+ b = append (b , ndjson ... )
206
+ b = append (b , '\n' , '\n' )
203
207
pj , err := ParseND (ndjson , nil )
204
208
if err != nil {
205
209
t .Fatal (err )
@@ -210,13 +214,13 @@ func TestNdjsonCountWhere2(t *testing.T) {
210
214
}
211
215
}
212
216
213
- func getPatchedNdjson (filename string ) []byte {
217
+ func loadFile (filename string ) []byte {
214
218
if ! strings .HasSuffix (filename , ".zst" ) {
215
219
ndjson , err := ioutil .ReadFile (filename )
216
220
if err != nil {
217
221
panic ("Failed to load file" )
218
222
}
219
- return bytes . ReplaceAll ( ndjson , [] byte ( " \n " ), [] byte ( "{" ))
223
+ return ndjson
220
224
}
221
225
var f * os.File
222
226
var err error
@@ -250,12 +254,12 @@ func getPatchedNdjson(filename string) []byte {
250
254
if err != nil {
251
255
panic ("Failed to load file" )
252
256
}
253
- return bytes . ReplaceAll ( ndjson , [] byte ( " \n " ), [] byte ( "{" ))
257
+ return ndjson
254
258
}
255
259
256
260
func BenchmarkNdjsonStage1 (b * testing.B ) {
257
261
258
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
262
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
259
263
260
264
pj := internalParsedJson {}
261
265
@@ -271,7 +275,7 @@ func BenchmarkNdjsonStage1(b *testing.B) {
271
275
}
272
276
273
277
func BenchmarkNdjsonStage2 (b * testing.B ) {
274
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
278
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
275
279
pj := internalParsedJson {}
276
280
pj .initialize (len (ndjson ) * 3 / 2 )
277
281
@@ -296,7 +300,7 @@ func count_raw_tape(tape []uint64) (count int) {
296
300
297
301
func BenchmarkNdjsonColdCountStar (b * testing.B ) {
298
302
299
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
303
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
300
304
301
305
b .SetBytes (int64 (len (ndjson )))
302
306
b .ReportAllocs ()
@@ -443,7 +447,7 @@ func countObjects(data ParsedJson) (count int) {
443
447
}
444
448
445
449
func BenchmarkNdjsonColdCountStarWithWhere (b * testing.B ) {
446
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
450
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
447
451
const want = 110349
448
452
runtime .GC ()
449
453
pj := internalParsedJson {}
@@ -482,7 +486,7 @@ func BenchmarkNdjsonColdCountStarWithWhere(b *testing.B) {
482
486
}
483
487
484
488
func BenchmarkNdjsonWarmCountStar (b * testing.B ) {
485
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
489
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
486
490
487
491
pj := internalParsedJson {}
488
492
pj .initialize (len (ndjson ) * 3 / 2 )
@@ -498,7 +502,7 @@ func BenchmarkNdjsonWarmCountStar(b *testing.B) {
498
502
}
499
503
500
504
func BenchmarkNdjsonWarmCountStarWithWhere (b * testing.B ) {
501
- ndjson := getPatchedNdjson ("testdata/parking-citations-1M.json.zst" )
505
+ ndjson := loadFile ("testdata/parking-citations-1M.json.zst" )
502
506
503
507
pj := internalParsedJson {}
504
508
pj .initialize (len (ndjson ) * 3 / 2 )
0 commit comments