Skip to content

Apache DataFusion SQL Query Engine

Move datafusion-cli to new crate (#231)

Daniël Heres47bd3faddb41
diff --git a/.dockerignore b/.dockerignore
index 8cd6a89645..533221e2b4 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,28 +1,2 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Turn .dockerignore to .dockerallow by excluding everything and explicitly
-# allowing specific files and directories. This enables us to quickly add
-# dependency files to the docker content without scanning the whole directory.
-# This setup requires to all of our docker containers have arrow's source
-# as a mounted directory.
-
-ci
-dev
-testing
-parquet-testing
-**/target/*
+.git
+**target
diff --git a/Cargo.toml b/Cargo.toml
index 2f34babdb2..fa36a0c0fe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,7 @@
[workspace]
members = [
"datafusion",
+ "datafusion-cli",
"datafusion-examples",
"benchmarks",
"ballista/rust/client",
diff --git a/README.md b/README.md
index f6ef7d1766..783bdd655c 100644
--- a/README.md
+++ b/README.md
@@ -132,7 +132,7 @@ datafusion = "4.0.0-SNAPSHOT"
## Using DataFusion as a binary
-DataFusion also includes a simple command-line interactive SQL utility. See the [CLI reference](docs/cli.md) for more information.
+DataFusion also includes a simple command-line interactive SQL utility. See the [CLI reference](datafusion/docs/cli.md) for more information.
# Status
diff --git a/datafusion-cli/Cargo.toml b/datafusion-cli/Cargo.toml
new file mode 100644
index 0000000000..883d0f2f4c
--- /dev/null
+++ b/datafusion-cli/Cargo.toml
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+name = "datafusion-cli"
+version = "4.0.0-SNAPSHOT"
+authors = ["Apache Arrow <[email protected]>"]
+edition = "2018"
+keywords = [ "arrow", "query", "sql", "cli", "repl" ]
+license = "Apache-2.0"
+homepage = "https://github.com/apache/arrow-datafusion"
+repository = "https://github.com/apache/arrow-datafusion"
+
+
+[dependencies]
+clap = "2.33"
+rustyline = "8.0"
+tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync"] }
+datafusion = { path = "../datafusion" }
diff --git a/datafusion/Dockerfile b/datafusion-cli/Dockerfile
similarity index 83%
rename from datafusion/Dockerfile
rename to datafusion-cli/Dockerfile
index 97e82b4bbc..32bd38b941 100644
--- a/datafusion/Dockerfile
+++ b/datafusion-cli/Dockerfile
@@ -15,11 +15,14 @@
# specific language governing permissions and limitations
# under the License.
-FROM rustlang/rust:nightly
+FROM rust:latest
+
+
+COPY ./datafusion ./usr/src/datafusion
+COPY ./datafusion-cli ./usr/src/datafusion-cli
+
+WORKDIR /usr/src/datafusion-cli
+RUN cargo install --path .
-COPY format /arrow/format/
-COPY rust /arrow/rust/
-WORKDIR /arrow/rust/datafusion
-RUN cargo install --bin datafusion-cli --path .
CMD ["datafusion-cli", "--data-path", "/data"]
diff --git a/datafusion/src/bin/repl.rs b/datafusion-cli/src/main.rs
similarity index 88%
rename from datafusion/src/bin/repl.rs
rename to datafusion-cli/src/main.rs
index a6aec204c0..dd7265e1f7 100644
--- a/datafusion/src/bin/repl.rs
+++ b/datafusion-cli/src/main.rs
@@ -17,8 +17,8 @@
#![allow(bare_trait_objects)]
-use arrow::util::pretty;
use clap::{crate_version, App, Arg};
+use datafusion::arrow::util::pretty;
use datafusion::error::Result;
use datafusion::execution::context::{ExecutionConfig, ExecutionContext};
use rustyline::Editor;
@@ -44,7 +44,7 @@ pub async fn main() {
)
.arg(
Arg::with_name("batch-size")
- .help("The batch size of each query, default value is 1048576")
+ .help("The batch size of each query, or use DataFusion default")
.short("c")
.long("batch-size")
.takes_value(true),
@@ -56,16 +56,17 @@ pub async fn main() {
env::set_current_dir(&p).unwrap();
};
- let batch_size = matches
+ let mut execution_config = ExecutionConfig::new().with_information_schema(true);
+
+ if let Some(batch_size) = matches
.value_of("batch-size")
- .map(|size| size.parse::<usize>().unwrap())
- .unwrap_or(1_048_576);
-
- let mut ctx = ExecutionContext::with_config(
- ExecutionConfig::new()
- .with_batch_size(batch_size)
- .with_information_schema(true),
- );
+ .and_then(|size| size.parse::<usize>().ok())
+ {
+ execution_config = execution_config.with_batch_size(batch_size);
+ };
+
+ let mut ctx =
+ ExecutionContext::with_config(execution_config.with_information_schema(true));
let mut rl = Editor::<()>::new();
rl.load_history(".history").ok();
diff --git a/datafusion/Cargo.toml b/datafusion/Cargo.toml
index 1c2c860c55..e35b8feea7 100644
--- a/datafusion/Cargo.toml
+++ b/datafusion/Cargo.toml
@@ -36,13 +36,8 @@ edition = "2018"
name = "datafusion"
path = "src/lib.rs"
-[[bin]]
-name = "datafusion-cli"
-path = "src/bin/main.rs"
-
[features]
-default = ["cli", "crypto_expressions", "regex_expressions", "unicode_expressions"]
-cli = ["rustyline"]
+default = ["crypto_expressions", "regex_expressions", "unicode_expressions"]
simd = ["arrow/simd"]
crypto_expressions = ["md-5", "sha2"]
regex_expressions = ["regex", "lazy_static"]
@@ -54,8 +49,6 @@ hashbrown = "0.11"
arrow = { git = "https://github.com/apache/arrow-rs", rev = "d008f31b107c1030a1f5144c164e8ca8bf543576", features = ["prettyprint"] }
parquet = { git = "https://github.com/apache/arrow-rs", rev = "d008f31b107c1030a1f5144c164e8ca8bf543576", features = ["arrow"] }
sqlparser = "0.9.0"
-clap = "2.33"
-rustyline = {version = "7.0", optional = true}
paste = "^1.0"
num_cpus = "1.13.0"
chrono = "0.4"
diff --git a/datafusion/docs/cli.md b/datafusion/docs/cli.md
index aeacdeee04..27605b2e98 100644
--- a/datafusion/docs/cli.md
+++ b/datafusion/docs/cli.md
@@ -26,9 +26,9 @@ The DataFusion CLI is a command-line interactive SQL utility that allows queries
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/](https://rustup.rs/).
```sh
-git clone https://github.com/apache/arrow
-cd arrow/rust/datafusion
-cargo run --bin datafusion-cli --release
+git clone https://github.com/apache/arrow-datafusion
+cd arrow-datafusion/datafusion-cli
+cargo run --release
```
## Run using Docker
@@ -36,9 +36,9 @@ cargo run --bin datafusion-cli --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.
```sh
-git clone https://github.com/apache/arrow
-cd arrow
-docker build -f rust/datafusion/Dockerfile . --tag datafusion-cli
+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
```
diff --git a/datafusion/src/bin/main.rs b/datafusion/src/bin/main.rs
deleted file mode 100644
index deb5b796b2..0000000000
--- a/datafusion/src/bin/main.rs
+++ /dev/null
@@ -1,25 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-// Only bring in dependencies for the repl when the cli feature is enabled.
-#[cfg(feature = "cli")]
-mod repl;
-
-pub fn main() {
- #[cfg(feature = "cli")]
- repl::main()
-}