Skip to content

Commit 85fba07

Browse files
committed
Support empty lines for NDJSON
1 parent 36b7c31 commit 85fba07

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

ndjson_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,32 @@ func TestDemoNdjson(t *testing.T) {
260260
verifyDemoNdjson(pj, t, 0)
261261
}
262262

263+
func TestNdjsonEmptyLines(t *testing.T) {
264+
265+
ndjson_emptylines := []string{`{"zero":"emptylines"}
266+
{"c":"d"}`,
267+
`{"single":"emptyline"}
268+
269+
{"c":"d"}`,
270+
`{"dual":"emptylines"}
271+
272+
273+
{"c":"d"}`,
274+
`{"triple":"emptylines"}
275+
276+
277+
278+
{"c":"d"}`}
279+
280+
pj := internalParsedJson{}
281+
282+
for _, json := range ndjson_emptylines {
283+
if err := pj.parseMessageNdjson([]byte(json)); err != nil {
284+
t.Errorf("TestNdjsonEmptyLine: got: %v want: nil", err)
285+
}
286+
}
287+
}
288+
263289
func TestNdjsonCountWhere(t *testing.T) {
264290
ndjson := loadFile("testdata/parking-citations-1M.json.zst")
265291
pj, err := ParseND(ndjson, nil)

stage2_build_tape.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,16 @@ start_continue:
206206
if done, idx = updateChar(pj, idx); done {
207207
goto succeed
208208
} else {
209-
// For an ndjson object, wrap up current object and start new root
209+
// For an ndjson object, wrap up current object, start new root and check for minimum of 1 newline
210210
if buf[idx] != '\n' {
211211
goto fail
212212
}
213213

214-
// Peek into next character, if we are at the end, exit out
215-
if done, idx = updateChar(pj, idx); done {
216-
goto succeed
214+
// Eat any empty lines
215+
for buf[idx] == '\n' {
216+
if done, idx = updateChar(pj, idx); done {
217+
goto succeed
218+
}
217219
}
218220

219221
// Otherwise close current root

0 commit comments

Comments
 (0)