Skip to content

Conversation

@jimexist
Copy link
Member

@jimexist jimexist commented May 8, 2021

Which issue does this PR close?

Closes #294
should be merged after #290 and #292

Rationale for this change

So far we have csv table tsv, we can easily add json support

What changes are included in this PR?

add json support

Are there any user-facing changes?

no breaking changes, just new feature

@jimexist
Copy link
Member Author

jimexist commented May 8, 2021

❯ echo 'select 123 num union all select 234 num union all select 456 num;' | cargo run --release --bin datafusion-cli -q -- --format json
[{"num":234},{"num":123},{"num":456}]
3 row in set. Query took 0 seconds.

@jimexist
Copy link
Member Author

jimexist commented May 8, 2021

❯ cargo run --release --bin datafusion-cli -q -- --help
DataFusion 4.0.0-SNAPSHOT
DataFusion is an in-memory query engine that uses Apache Arrow as the memory model. It supports executing SQL queries
against CSV and Parquet files as well as querying directly against in-memory data.

USAGE:
    datafusion-cli [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -c, --batch-size <batch-size>    The batch size of each query, or use DataFusion default
    -p, --data-path <data-path>      Path to your data, default to current directory
    -f, --file <file>                Execute commands from file, then exit
        --format <format>            Output format (possible values: table, csv, tsv, json) [default: table]

@codecov-commenter
Copy link

codecov-commenter commented May 8, 2021

Codecov Report

Merging #295 (d82ad13) into master (ee69ac8) will increase coverage by 0.11%.
The diff coverage is 98.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #295      +/-   ##
==========================================
+ Coverage   76.08%   76.19%   +0.11%     
==========================================
  Files         141      141              
  Lines       23734    23786      +52     
==========================================
+ Hits        18057    18123      +66     
+ Misses       5677     5663      -14     
Impacted Files Coverage Δ
datafusion-cli/src/main.rs 0.00% <ø> (ø)
datafusion-cli/src/format/print_format.rs 90.41% <98.07%> (+90.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee69ac8...d82ad13. Read the comment docs.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great -- thanks @jimexist


let batches = vec![batch];
let r = print_batches_to_json(&batches).unwrap();
assert_eq!("[{\"a\":1,\"b\":4,\"c\":7},{\"a\":2,\"b\":5,\"c\":8},{\"a\":3,\"b\":6,\"c\":9}]", r);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 for the tests

@alamb alamb merged commit 7133c33 into apache:master May 11, 2021
@jimexist jimexist deleted the add-json-mode branch May 11, 2021 12:25
@houqp houqp added datafusion enhancement New feature or request labels Jul 29, 2021
H0TB0X420 pushed a commit to H0TB0X420/datafusion that referenced this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add json print format to datafusion cli

5 participants