The DataFusion CLI is a command-line interactive SQL utility that allows queries to be executed against CSV and Parquet files. It is a convenient way to try DataFusion out with your own data sources.
Use the following commands to clone this repository and run the CLI. This will require the Rust toolchain to be installed. Rust can be installed from https://rustup.rs/.
git clone https://github.com/apache/arrow-datafusion
cd arrow-datafusion/datafusion-cli
cargo run --release
Use the following commands to clone this repository and build a Docker image containing the CLI tool. Note that there is .dockerignore
file in the root of the repository that may need to be deleted in order for this to work.
git clone https://github.com/apache/arrow-datafusion
cd arrow-datafusion
docker build -f datafusion-cli/Dockerfile . --tag datafusion-cli
docker run -it -v $(your_data_location):/data datafusion-cli
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 [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
-q, --quiet Reduce printing other than the results and work quietly
-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 [default: table] [possible values: csv, tsv, table, json, ndjson]
Type exit
or quit
to exit the CLI.
Parquet data sources can be registered by executing a CREATE EXTERNAL TABLE
SQL statement. It is not necessary to provide schema information for Parquet files.
CREATE EXTERNAL TABLE taxi
STORED AS PARQUET
LOCATION '/mnt/nyctaxi/tripdata.parquet';
CSV data sources can be registered by executing a CREATE EXTERNAL TABLE
SQL statement. It is necessary to provide schema information for CSV files since DataFusion does not automatically infer the schema when using SQL to query CSV files.
CREATE EXTERNAL TABLE test (
c1 VARCHAR NOT NULL,
c2 INT NOT NULL,
c3 SMALLINT NOT NULL,
c4 SMALLINT NOT NULL,
c5 INT NOT NULL,
c6 BIGINT NOT NULL,
c7 SMALLINT NOT NULL,
c8 INT NOT NULL,
c9 BIGINT NOT NULL,
c10 VARCHAR NOT NULL,
c11 FLOAT NOT NULL,
c12 DOUBLE NOT NULL,
c13 VARCHAR NOT NULL
)
STORED AS CSV
WITH HEADER ROW
LOCATION '/path/to/aggregate_test_100.csv';