From 699c80e41da5e438b2213ffbfa18644c1a3842d2 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 5 Dec 2017 21:20:44 -0500 Subject: [PATCH] SQL-input-examples doc --- c/draft-release-notes.md | 2 + doc/10-min.html | 140 ++++++++++++++++++++++++++++++++++++ doc/content-for-10-min.html | 139 +++++++++++++++++++++++++++++++++++ 3 files changed, 281 insertions(+) diff --git a/c/draft-release-notes.md b/c/draft-release-notes.md index 69dbeb036..dadff12cd 100644 --- a/c/draft-release-notes.md +++ b/c/draft-release-notes.md @@ -26,6 +26,8 @@ an alias for `--nidx --fs tab`, and `mlr -t` is an alias for `mlr [**here**](http://johnkerl.org/miller-releases/miller-5.2.0/doc/reference-dsl.html#A_note_on_the_complexity_of_Miller’s_expression_language), since Miller has its own DSL there will always be things better expressible in a general-purpose language. The new page [**Sharing data with other languages**](http://johnkerl.org/miller-releases/miller-5.2.0/doc/data-sharing.html) shows how to seamlessly share data back and forth between Miller, Ruby, and Python. +* [**SQL-input examples](http://johnkerl.org/miller-releases/miller-5.2.0/doc/10-min.html#SQL-input_examples) contains detailed information the interplay between Miller and SQL. + * [**Issue 150**](https://github.com/johnkerl/miller/issues/150) raised a question about suppressing numeric conversion. This resulted in a new FAQ entry [**How do I suppress numeric conversion?**](http://johnkerl.org/miller/doc/faq.html#How_do_I_suppress_numeric_conversion?), as well as the diff --git a/doc/10-min.html b/doc/10-min.html index 89cc952f7..dceed948b 100644 --- a/doc/10-min.html +++ b/doc/10-min.html @@ -192,6 +192,7 @@ Miller commands were run with pretty-print-tabular output format. • Choices for printing to files
• Other-format examples
• SQL-output examples
+• SQL-input examples
• Log-processing examples
• More
@@ -843,6 +844,145 @@ standard 10009872 108

Again, all the examples in the CSV section apply here — just change the input-format flags. + +

SQL-input examples

+ +
+ +

One use of NIDX (value-only, no keys) format is for loading up SQL tables. + +

Create and load SQL table: + +

+mysql> CREATE TABLE abixy(
+  a VARCHAR(32),
+  b VARCHAR(32),
+  i BIGINT(10),
+  x DOUBLE,
+  y DOUBLE
+);
+Query OK, 0 rows affected (0.01 sec)
+
+bash$ mlr --onidx --fs comma cat data/medium > medium.nidx
+
+mysql> LOAD DATA LOCAL INFILE 'medium.nidx' REPLACE INTO TABLE abixy FIELDS TERMINATED BY ',' ;
+Query OK, 10000 rows affected (0.07 sec)
+Records: 10000  Deleted: 0  Skipped: 0  Warnings: 0
+
+mysql> SELECT COUNT(*) AS count FROM abixy;
++-------+
+| count |
++-------+
+| 10000 |
++-------+
+1 row in set (0.00 sec)
+
+mysql> SELECT * FROM abixy LIMIT 10;
++------+------+------+---------------------+---------------------+
+| a    | b    | i    | x                   | y                   |
++------+------+------+---------------------+---------------------+
+| pan  | pan  |    1 |  0.3467901443380824 |  0.7268028627434533 |
+| eks  | pan  |    2 |  0.7586799647899636 |  0.5221511083334797 |
+| wye  | wye  |    3 | 0.20460330576630303 | 0.33831852551664776 |
+| eks  | wye  |    4 | 0.38139939387114097 | 0.13418874328430463 |
+| wye  | pan  |    5 |  0.5732889198020006 |  0.8636244699032729 |
+| zee  | pan  |    6 |  0.5271261600918548 | 0.49322128674835697 |
+| eks  | zee  |    7 |  0.6117840605678454 |  0.1878849191181694 |
+| zee  | wye  |    8 |  0.5985540091064224 |   0.976181385699006 |
+| hat  | wye  |    9 | 0.03144187646093577 |  0.7495507603507059 |
+| pan  | wye  |   10 |  0.5026260055412137 |  0.9526183602969864 |
++------+------+------+---------------------+---------------------+
+
+ +

Aggregate counts within SQL: +

+mysql> SELECT a, b, COUNT(*) AS count FROM abixy GROUP BY a, b ORDER BY COUNT DESC;
++------+------+-------+
+| a    | b    | count |
++------+------+-------+
+| zee  | wye  |   455 |
+| pan  | eks  |   429 |
+| pan  | pan  |   427 |
+| wye  | hat  |   426 |
+| hat  | wye  |   423 |
+| pan  | hat  |   417 |
+| eks  | hat  |   417 |
+| pan  | zee  |   413 |
+| eks  | eks  |   413 |
+| zee  | hat  |   409 |
+| eks  | wye  |   407 |
+| zee  | zee  |   403 |
+| pan  | wye  |   395 |
+| wye  | pan  |   392 |
+| zee  | eks  |   391 |
+| zee  | pan  |   389 |
+| hat  | eks  |   389 |
+| wye  | eks  |   386 |
+| wye  | zee  |   385 |
+| hat  | zee  |   385 |
+| hat  | hat  |   381 |
+| wye  | wye  |   377 |
+| eks  | pan  |   371 |
+| hat  | pan  |   363 |
+| eks  | zee  |   357 |
++------+------+-------+
+25 rows in set (0.01 sec)
+
+ +

Aggregate counts within Miller: +

+
+$ mlr --opprint uniq -c -g a,b then sort -nr count data/medium
+a   b   count
+zee wye 455
+pan eks 429
+pan pan 427
+wye hat 426
+hat wye 423
+pan hat 417
+eks hat 417
+eks eks 413
+pan zee 413
+zee hat 409
+eks wye 407
+zee zee 403
+pan wye 395
+hat pan 363
+eks zee 357
+
+ +

Pipe SQL output to aggregate counts within Miller: +

+
+$ mysql -D miller -B -e 'select * from abixy' | mlr --itsv --opprint uniq -c -g a,b then sort -nr count
+a   b   count
+zee wye 455
+pan eks 429
+pan pan 427
+wye hat 426
+hat wye 423
+pan hat 417
+eks hat 417
+eks eks 413
+pan zee 413
+zee hat 409
+eks wye 407
+zee zee 403
+pan wye 395
+wye pan 392
+zee eks 391
+zee pan 389
+hat eks 389
+wye eks 386
+hat zee 385
+wye zee 385
+hat hat 381
+wye wye 377
+eks pan 371
+hat pan 363
+eks zee 357
+
+

Log-processing examples

diff --git a/doc/content-for-10-min.html b/doc/content-for-10-min.html index c4056d5ce..ecb47578a 100644 --- a/doc/content-for-10-min.html +++ b/doc/content-for-10-min.html @@ -344,6 +344,145 @@ standard 10009872 108

Again, all the examples in the CSV section apply here — just change the input-format flags. + +

SQL-input examples

+ +
+ +

One use of NIDX (value-only, no keys) format is for loading up SQL tables. + +

Create and load SQL table: + +

+mysql> CREATE TABLE abixy(
+  a VARCHAR(32),
+  b VARCHAR(32),
+  i BIGINT(10),
+  x DOUBLE,
+  y DOUBLE
+);
+Query OK, 0 rows affected (0.01 sec)
+
+bash$ mlr --onidx --fs comma cat data/medium > medium.nidx
+
+mysql> LOAD DATA LOCAL INFILE 'medium.nidx' REPLACE INTO TABLE abixy FIELDS TERMINATED BY ',' ;
+Query OK, 10000 rows affected (0.07 sec)
+Records: 10000  Deleted: 0  Skipped: 0  Warnings: 0
+
+mysql> SELECT COUNT(*) AS count FROM abixy;
++-------+
+| count |
++-------+
+| 10000 |
++-------+
+1 row in set (0.00 sec)
+
+mysql> SELECT * FROM abixy LIMIT 10;
++------+------+------+---------------------+---------------------+
+| a    | b    | i    | x                   | y                   |
++------+------+------+---------------------+---------------------+
+| pan  | pan  |    1 |  0.3467901443380824 |  0.7268028627434533 |
+| eks  | pan  |    2 |  0.7586799647899636 |  0.5221511083334797 |
+| wye  | wye  |    3 | 0.20460330576630303 | 0.33831852551664776 |
+| eks  | wye  |    4 | 0.38139939387114097 | 0.13418874328430463 |
+| wye  | pan  |    5 |  0.5732889198020006 |  0.8636244699032729 |
+| zee  | pan  |    6 |  0.5271261600918548 | 0.49322128674835697 |
+| eks  | zee  |    7 |  0.6117840605678454 |  0.1878849191181694 |
+| zee  | wye  |    8 |  0.5985540091064224 |   0.976181385699006 |
+| hat  | wye  |    9 | 0.03144187646093577 |  0.7495507603507059 |
+| pan  | wye  |   10 |  0.5026260055412137 |  0.9526183602969864 |
++------+------+------+---------------------+---------------------+
+
+ +

Aggregate counts within SQL: +

+mysql> SELECT a, b, COUNT(*) AS count FROM abixy GROUP BY a, b ORDER BY COUNT DESC;
++------+------+-------+
+| a    | b    | count |
++------+------+-------+
+| zee  | wye  |   455 |
+| pan  | eks  |   429 |
+| pan  | pan  |   427 |
+| wye  | hat  |   426 |
+| hat  | wye  |   423 |
+| pan  | hat  |   417 |
+| eks  | hat  |   417 |
+| pan  | zee  |   413 |
+| eks  | eks  |   413 |
+| zee  | hat  |   409 |
+| eks  | wye  |   407 |
+| zee  | zee  |   403 |
+| pan  | wye  |   395 |
+| wye  | pan  |   392 |
+| zee  | eks  |   391 |
+| zee  | pan  |   389 |
+| hat  | eks  |   389 |
+| wye  | eks  |   386 |
+| wye  | zee  |   385 |
+| hat  | zee  |   385 |
+| hat  | hat  |   381 |
+| wye  | wye  |   377 |
+| eks  | pan  |   371 |
+| hat  | pan  |   363 |
+| eks  | zee  |   357 |
++------+------+-------+
+25 rows in set (0.01 sec)
+
+ +

Aggregate counts within Miller: +

+
+$ mlr --opprint uniq -c -g a,b then sort -nr count data/medium
+a   b   count
+zee wye 455
+pan eks 429
+pan pan 427
+wye hat 426
+hat wye 423
+pan hat 417
+eks hat 417
+eks eks 413
+pan zee 413
+zee hat 409
+eks wye 407
+zee zee 403
+pan wye 395
+hat pan 363
+eks zee 357
+
+ +

Pipe SQL output to aggregate counts within Miller: +

+
+$ mysql -D miller -B -e 'select * from abixy' | mlr --itsv --opprint uniq -c -g a,b then sort -nr count
+a   b   count
+zee wye 455
+pan eks 429
+pan pan 427
+wye hat 426
+hat wye 423
+pan hat 417
+eks hat 417
+eks eks 413
+pan zee 413
+zee hat 409
+eks wye 407
+zee zee 403
+pan wye 395
+wye pan 392
+zee eks 391
+zee pan 389
+hat eks 389
+wye eks 386
+hat zee 385
+wye zee 385
+hat hat 381
+wye wye 377
+eks pan 371
+hat pan 363
+eks zee 357
+
+

Log-processing examples