Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ragged-CSV auto-pad #1428

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions pkg/input/record_reader_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,22 @@ func (reader *RecordReaderCSV) getRecordBatch(
)
errorChannel <- err
return
} else {
i := int64(0)
n := lib.IntMin2(nh, nd)
for i = 0; i < n; i++ {
key := reader.header[i]
value := mlrval.FromDeferredType(csvRecord[i])
_, err := record.PutReferenceMaybeDedupe(key, value, dedupeFieldNames)
if err != nil {
errorChannel <- err
return
}
}

i := int64(0)
n := lib.IntMin2(nh, nd)
for i = 0; i < n; i++ {
key := reader.header[i]
value := mlrval.FromDeferredType(csvRecord[i])
_, err := record.PutReferenceMaybeDedupe(key, value, dedupeFieldNames)
if err != nil {
errorChannel <- err
return
}
if nh < nd {
// if header shorter than data: use 1-up itoa keys
}
if nh < nd {
// if header shorter than data: use 1-up itoa keys
for i = nh; i < nd; i++ {
key := strconv.FormatInt(i+1, 10)
value := mlrval.FromDeferredType(csvRecord[i])
_, err := record.PutReferenceMaybeDedupe(key, value, dedupeFieldNames)
Expand All @@ -271,17 +273,8 @@ func (reader *RecordReaderCSV) getRecordBatch(
return
}
}
if nh > nd {
// if header longer than data: use "" values
for i = nd; i < nh; i++ {
_, err := record.PutReferenceMaybeDedupe(reader.header[i], mlrval.VOID.Copy(), dedupeFieldNames)
if err != nil {
errorChannel <- err
return
}
}
}
}
// if nh > nd: leave it short. This is a job for unsparsify.
}

context.UpdateForInputRecord()
Expand Down
3 changes: 1 addition & 2 deletions test/cases/io-multi/0045/expout
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
},
{
"a": 4,
"b": 5,
"c": ""
"b": 5
},
{
"a": 6,
Expand Down
1 change: 0 additions & 1 deletion test/cases/io-ragged-non-rfc-csv/0001/expout
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ c 3

a 4
b 5
c

a 6
b 7
Expand Down
Loading