mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.5k stars 65 forks source link

handling of missing column name #57

Closed pkoppstein closed 3 years ago

pkoppstein commented 3 years ago

It's my understanding that the -f JSON option should output JSON, but consider:

csvq -i tsv  "select * from g"
+-------------+----+------+----+-------+-----+-------------+----------+-------------+---------------+----------+
|      #      | ST |  YR  | CH | DNAME | DID |     uid     |   NAME   | DetailedPID | SimplifiedPID |          |
+-------------+----+------+----+-------+-----+-------------+----------+-------------+---------------+----------+
| ak1995l001r | AK | 1995 | 9  | NULL  | 004 | AK1995L001  | Robinson |    NULL     | D             | K001803  |
+-------------+----+------+----+-------+-----+-------------+----------+-------------+---------------+----------+
$ csvq -f JSON -i tsv  "select * from g"
panic: interface conversion: json.PathExpression is nil, not json.ObjectPath

Adding the -a command-line option makes no difference.

Adding the missing column name resolves the issue, but it would be more helpful if the error message was more informative, and it would be even more helpful if a default column name were (or could be) provided.

My apologies in advance if I've missed something in the documentation.

Thank you.

mithrandie commented 3 years ago

Unlike the case where there is no value, an empty string may have its own meaning, so I don’t intend to implement a default column name for an empty string for now.

However, the occurrence of panic is an unexpected behavior. I’ll fix it so that it handles correctly. Thanks for reporting.

mithrandie commented 3 years ago

In the version 1.15.2, empty key names are allowed in JSON output as well as other output formats.

As with other column names, there can only be one column with an empty key name in a table.

pkoppstein commented 3 years ago

I see that in fact more than one column header can now be missing! Perfect. Thank you.