-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gracefully handle misaligned header and values in
xsv
parser (#3874)
The `xsv` parser (and by extension the `csv`, `tsv`, and `ssv` parsers) previously skipped lines that had a mismatch between the number of values contained and the number of fields defined in the header. This is now handled in a more lenient way in both directions: 1. If the header contains more fields than a row contains data, the remaining fields are filled in as `null` values. 2. If a row contains more values than the header had fields defined for, we dynamically expand the header with fields nammed `unnamed1`, `unnammed2`, and so forth. This is hidden behind the option `--auto-expand`. These two examples show the new behavior: ``` ❯ echo "1,2,3,4,5" | tenzir -q 'read csv --header "foo,bar,baz" --auto-expand' { "foo": 1, "bar": 2, "baz": 3, "unnamed1": 4, "unnamed2": 5 } ``` ``` ❯ echo "1" | tenzir -q 'read csv --header "foo,bar,baz"' { "foo": 1, "bar": null, "baz": null } ``` Fixes tenzir/issues#1500
- Loading branch information
Showing
10 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
The `xsv` parser (and by extension the `csv`, `tsv`, and `ssv` parsers) skipped | ||
lines that had a mismatch between the number of values contained and the number | ||
of fields defined in the header. Instead, it now fills in `null` values for | ||
missing values and, if the new `--auto-expand` option is set, also adds new | ||
header fields for excess values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tenzir/integration/data/reference/pipelines_local/test_read_xsv_auto_expand/step_00.ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo": 1, "bar": 2, "baz": 3} |
1 change: 1 addition & 0 deletions
1
tenzir/integration/data/reference/pipelines_local/test_read_xsv_auto_expand/step_01.ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo": 1, "bar": 2, "baz": null} |
4 changes: 4 additions & 0 deletions
4
tenzir/integration/data/reference/pipelines_local/test_read_xsv_auto_expand/step_02.ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"foo": 1, "bar": 2, "baz": 3} | ||
warning: skips 2 excess values in line | ||
= hint: use `--auto-expand` to add fields for excess values | ||
= note: from `csv` parser |
1 change: 1 addition & 0 deletions
1
tenzir/integration/data/reference/pipelines_local/test_read_xsv_auto_expand/step_03.ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo": 1, "bar": 2, "baz": 3, "unnamed1": 4, "unnamed2": 5} |
1 change: 1 addition & 0 deletions
1
tenzir/integration/data/reference/pipelines_local/test_read_xsv_auto_expand/step_04.ref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"foo": 1, "unnamed1": 2, "baz": 3, "unnamed2": 4, "unnamed3": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters