miller/doc/content-for-record-heterogeneity.html
2015-09-13 18:37:12 -07:00

54 lines
2.1 KiB
HTML

POKI_PUT_TOC_HERE
We think of CSV tables as rectangular: if there are 17 columns in the header then there are 17 columns for every row, else the data have a formatting error.
<p/>But heterogeneous data abound (today&rsquo;s no-SQL databases for example). Miller handles this.
<h1>For I/O</h1>
<h2>CSV and pretty-print</h2>
Miller simply prints a newline and a new header when there is a schema change. When there is no schema change, you get CSV per se as a special case. Likewise, Miller reads heterogeneous CSV or pretty-print input the same way. The difference between CSV and CSV-lite is that the former is RFC4180-compliant, while the latter readily handles heterogeneous data (which is non-compliant). For example:
<table><tr><td>
POKI_RUN_COMMAND{{cat data/het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr --ocsvlite cat data/het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr --opprint cat data/het.dkvp}}HERE
</td></tr></table>
<p/> You may also find Miller&rsquo;s <tt>group-like</tt> feature handy (see also
POKI_PUT_LINK_FOR_PAGE(reference.html)HERE):
<table><tr><td>
POKI_RUN_COMMAND{{mlr --ocsvlite group-like data/het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr --opprint group-like data/het.dkvp}}HERE
</td></tr></table>
<h2>Key-value-pair, vertical-tabular, and index-numbered formats</h2>
For these formats, record-heterogeneity comes naturally:
<table><tr><td>
POKI_RUN_COMMAND{{cat data/het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr --onidx --ofs ' ' cat data/het.dkvp}}HERE
</td> </tr><tr> <td>
POKI_RUN_COMMAND{{mlr --oxtab cat data/het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr --oxtab group-like data/het.dkvp}}HERE
</td></tr></table>
<h1>For processing</h1>
<p/> Miller operates on specified fields and takes the rest along: for example, if you are sorting on the
<tt>count</tt> field then all records in the input stream must have a <tt>count</tt> field but the other fields can
vary, and moreover the sorted-on field name(s) don&rsquo;t need to be in the same position on each line:
<table><tr><td>
POKI_RUN_COMMAND{{cat data/sort-het.dkvp}}HERE
</td><td>
POKI_RUN_COMMAND{{mlr sort -n count data/sort-het.dkvp}}HERE
</td></tr></table>