-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ballista examples #775
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e2d0730
Draft Ballista README and examples
81a0d89
Add SQL example
andygrove 2fd3e83
improve docs
andygrove 6b8d751
fix port in exampls
andygrove 0365451
Add ASF header to ballista-exampls README
andygrove c62b8dc
Update ballista/README.md
andygrove f66a881
Change examples to binaries
andygrove b577c54
merge
andygrove File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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 = "ballista-examples" | ||
description = "Ballista usage examples" | ||
version = "0.5.0-SNAPSHOT" | ||
homepage = "https://github.com/apache/arrow-datafusion" | ||
repository = "https://github.com/apache/arrow-datafusion" | ||
authors = ["Apache Arrow <[email protected]>"] | ||
license = "Apache-2.0" | ||
keywords = [ "arrow", "distributed", "query", "sql" ] | ||
edition = "2018" | ||
publish = false | ||
|
||
|
||
[dev-dependencies] | ||
arrow-flight = { version = "5.0" } | ||
datafusion = { path = "../datafusion" } | ||
ballista = { path = "../ballista/rust/client" } | ||
prost = "0.7" | ||
tonic = "0.4" | ||
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync"] } | ||
futures = "0.3" | ||
num_cpus = "1.13.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!--- | ||
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. | ||
--> | ||
|
||
# Ballista Examples | ||
|
||
This directory contains examples for executing distributed queries with Ballista. | ||
|
||
For background information on the Ballista architecture, refer to | ||
the [Ballista README](../ballista/README.md). | ||
|
||
## Start a standalone cluster | ||
|
||
From the root of the arrow-datafusion project, build release binaries. | ||
|
||
```bash | ||
cargo build --release | ||
``` | ||
|
||
Start a Ballista scheduler process in a new terminal session. | ||
|
||
```bash | ||
RUST_LOG=info ./target/release/ballista-scheduler | ||
``` | ||
|
||
Start one or more Ballista executor processes in new terminal sessions. When starting more than one | ||
executor, a unique port number must be specified for each executor. | ||
|
||
```bash | ||
RUST_LOG=info ./target/release/ballista-executor -c 4 | ||
``` | ||
|
||
## Running the examples | ||
|
||
Refer to the instructions in [DEVELOPERS.md](../DEVELOPERS.md) to define the `ARROW_TEST_DATA` and | ||
`PARQUET_TEST_DATA` environment variables so that the examples can find the test data files. | ||
|
||
The examples can be run using the `cargo run --example` syntax. | ||
|
||
```bash | ||
cargo run --release --example ballista-dataframe | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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. | ||
|
||
use ballista::prelude::*; | ||
use datafusion::arrow::util::pretty; | ||
use datafusion::prelude::{col, lit}; | ||
|
||
/// This example demonstrates executing a simple query against an Arrow data source (Parquet) and | ||
/// fetching results, using the DataFrame trait | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let config = BallistaConfig::builder() | ||
.set("ballista.shuffle.partitions", "4") | ||
.build()?; | ||
let ctx = BallistaContext::remote("localhost", 50050, &config); | ||
|
||
let testdata = datafusion::arrow::util::test_util::parquet_test_data(); | ||
|
||
let filename = &format!("{}/alltypes_plain.parquet", testdata); | ||
|
||
// define the query using the DataFrame trait | ||
let df = ctx | ||
.read_parquet(filename)? | ||
.select_columns(&["id", "bool_col", "timestamp_col"])? | ||
.filter(col("id").gt(lit(1)))?; | ||
|
||
// execute the query - note that calling collect on the DataFrame | ||
// trait will execute the query with DataFusion so we have to call | ||
// collect on the BallistaContext instead and pass it the DataFusion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// logical plan | ||
let mut stream = ctx.collect(&df.to_logical_plan()).await?; | ||
|
||
// print the results | ||
let mut results = vec![]; | ||
while let Some(batch) = stream.next().await { | ||
let batch = batch?; | ||
results.push(batch); | ||
} | ||
pretty::print_batches(&results)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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. | ||
|
||
use ballista::prelude::*; | ||
use datafusion::arrow::util::pretty; | ||
use datafusion::prelude::CsvReadOptions; | ||
|
||
/// This example demonstrates executing a simple query against an Arrow data source (CSV) and | ||
/// fetching results, using SQL | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let config = BallistaConfig::builder() | ||
.set("ballista.shuffle.partitions", "4") | ||
.build()?; | ||
let ctx = BallistaContext::remote("localhost", 50050, &config); | ||
|
||
let testdata = datafusion::arrow::util::test_util::arrow_test_data(); | ||
|
||
// register csv file with the execution context | ||
ctx.register_csv( | ||
"aggregate_test_100", | ||
&format!("{}/csv/aggregate_test_100.csv", testdata), | ||
CsvReadOptions::new(), | ||
)?; | ||
|
||
// execute the query | ||
let df = ctx.sql( | ||
"SELECT c1, MIN(c12), MAX(c12) \ | ||
FROM aggregate_test_100 \ | ||
WHERE c11 > 0.1 AND c11 < 0.9 \ | ||
GROUP BY c1", | ||
)?; | ||
|
||
// execute the query - note that calling collect on the DataFrame | ||
// trait will execute the query with DataFusion so we have to call | ||
// collect on the BallistaContext instead and pass it the DataFusion | ||
// logical plan | ||
let mut stream = ctx.collect(&df.to_logical_plan()).await?; | ||
|
||
// print the results | ||
let mut results = vec![]; | ||
while let Some(batch) = stream.next().await { | ||
let batch = batch?; | ||
results.push(batch); | ||
} | ||
pretty::print_batches(&results)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is worth adding
bin
targets here?As it is I can't run these examples:
Maybe something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the same pattern that we use in
datafusion-examples
where we usecargo run --example
rather thancargo run --bin
.It is a little odd that we package the examples in their own crate, so maybe packaging them as binaries makes more sense now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main motivation from extracting them into a separate folder/crate for datafusion-examples was to reduce the nr of dependencies and compilation time.
Maybe bin works just as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this to use
--bin
now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉