Skip to content

Support JSON CLI output format#878

Merged
electrum merged 2 commits intotrinodb:masterfrom
ebyhr:client/json
Jun 3, 2019
Merged

Support JSON CLI output format#878
electrum merged 2 commits intotrinodb:masterfrom
ebyhr:client/json

Conversation

@ebyhr
Copy link
Member

@ebyhr ebyhr commented Jun 1, 2019

Fix #867

Example

$ presto --output-format JSON --execute "select * from tpch.sf1.customer limit 2" | jq
[
  {
    "custkey": 37501,
    "name": "Customer#000037501",
    "address": "Ftb6T5ImHuJ",
    "nationkey": 2,
    "phone": "12-397-688-6719",
    "acctbal": -324.85,
    "mktsegment": "HOUSEHOLD",
    "comment": "pending ideas use carefully. express, ironic platelets use among the furiously regular instructions. "
  },
  {
    "custkey": 37502,
    "name": "Customer#000037502",
    "address": "ppCVXCFV,4JJ97IibbcMB5,aPByjYL07vmOLO 3m",
    "nationkey": 18,
    "phone": "28-515-931-4624",
    "acctbal": 5179.2,
    "mktsegment": "BUILDING",
    "comment": "express deposits. pending, regular deposits wake furiously bold deposits. regular "
  }
]

$ presto --output-format JSON --execute "select * from tpch.sf1.customer limit 2" | jq '.[0].name'
"Customer#000112501"

@findepi
Copy link
Member

findepi commented Jun 1, 2019

@ebyhr thanks for your PR!

In #867 i outlined possible output layouts (single JSON object vs a stream of JSON objects; i added examples in the issue).
I imagine stream of JSON objects may be easier to process in... a streaming fashion.
What are your thoughts about this?

@ebyhr
Copy link
Member Author

ebyhr commented Jun 1, 2019

@findepi Hmm.., it's a difficult choice. How about preparing both format e.g., JSON and JSON_STREAM?

@electrum
Copy link
Member

electrum commented Jun 1, 2019

I’d keep the shorter option name for the current streaming format.

@ebyhr
Copy link
Member Author

ebyhr commented Jun 1, 2019

Changed to streaming format using JSON option. I imagined some non-jq cases and thought one json is better at first. However, I agree with the current style now.

@electrum
Copy link
Member

electrum commented Jun 1, 2019

It might be simpler and more efficient to use theJsonGenerator API, since you could loop and write the key/value pairs directly.

@ebyhr ebyhr force-pushed the client/json branch 2 times, most recently from 29a2497 to d32dce0 Compare June 2, 2019 05:30
@ebyhr
Copy link
Member Author

ebyhr commented Jun 2, 2019

Updated to JsonGenerator API.

@martint
Copy link
Member

martint commented Jun 2, 2019

There's a typo in the commit message: "formt"

@ebyhr ebyhr changed the title Support JSON CLI output formt Support JSON CLI output form Jun 2, 2019
@ebyhr
Copy link
Member Author

ebyhr commented Jun 2, 2019

Oh, sorry fixed.

@ebyhr ebyhr changed the title Support JSON CLI output form Support JSON CLI output format Jun 2, 2019
@ebyhr
Copy link
Member Author

ebyhr commented Jun 3, 2019

The travis failed by PRODUCT_TESTS_BASIC_ENVIRONMENT=true and this commit looks unrelated.

@electrum electrum merged commit daf5ce6 into trinodb:master Jun 3, 2019
@electrum
Copy link
Member

electrum commented Jun 3, 2019

Merged, thanks!

@electrum electrum added this to the 314 milestone Jun 3, 2019
@electrum electrum mentioned this pull request Jun 7, 2019
6 tasks
@ebyhr ebyhr deleted the client/json branch September 5, 2021 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add JSON CLI output format

4 participants