Skip to content
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

ARROW-6692: [Rust] [DataFusion] Update examples to use physical query plan #5581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions rust/datafusion/examples/csv_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ extern crate datafusion;
use arrow::array::{BinaryArray, Float64Array};
use arrow::datatypes::{DataType, Field, Schema};

use datafusion::error::Result;
use datafusion::execution::context::ExecutionContext;

/// This example demonstrates executing a simple query against an Arrow data source (CSV) and
/// fetching results
fn main() {
fn main() -> Result<()> {
// create local execution context
let mut ctx = ExecutionContext::new();

Expand Down Expand Up @@ -59,16 +60,18 @@ fn main() {
true,
);

// simple projection and selection
let 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
let relation = ctx.sql(&sql, 1024 * 1024).unwrap();
// create the query plan
let plan = ctx.create_logical_plan(&sql)?;
let plan = ctx.optimize(&plan)?;
let plan = ctx.create_physical_plan(&plan, 1024 * 1024)?;

// display the relation
let mut results = relation.borrow_mut();
// execute the query
let results = ctx.collect(plan.as_ref())?;

while let Some(batch) = results.next().unwrap() {
// iterate over the results
results.iter().for_each(|batch| {
println!(
"RecordBatch has {} rows and {} columns",
batch.num_rows(),
Expand Down Expand Up @@ -98,5 +101,7 @@ fn main() {

println!("{}, Min: {}, Max: {}", c1_value, min.value(i), max.value(i),);
}
}
});

Ok(())
}
23 changes: 14 additions & 9 deletions rust/datafusion/examples/parquet_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ extern crate datafusion;

use arrow::array::{BinaryArray, Float64Array, Int32Array};

use datafusion::error::Result;
use datafusion::execution::context::ExecutionContext;

/// This example demonstrates executing a simple query against an Arrow data source (Parquet) and
/// fetching results
fn main() {
fn main() -> Result<()> {
// create local execution context
let mut ctx = ExecutionContext::new();

Expand All @@ -35,19 +36,21 @@ fn main() {
ctx.register_parquet(
"alltypes_plain",
&format!("{}/alltypes_plain.parquet", testdata),
)
.unwrap();
)?;

// simple selection
let sql = "SELECT int_col, double_col, date_string_col FROM alltypes_plain WHERE id > 1 AND tinyint_col < double_col";

// execute the query
let relation = ctx.sql(&sql, 1024 * 1024).unwrap();
// create the query plan
let plan = ctx.create_logical_plan(&sql)?;
let plan = ctx.optimize(&plan)?;
let plan = ctx.create_physical_plan(&plan, 1024 * 1024)?;

// display the relation
let mut results = relation.borrow_mut();
// execute the query
let results = ctx.collect(plan.as_ref())?;

while let Some(batch) = results.next().unwrap() {
// iterate over the results
results.iter().for_each(|batch| {
println!(
"RecordBatch has {} rows and {} columns",
batch.num_rows(),
Expand Down Expand Up @@ -82,5 +85,7 @@ fn main() {
double.value(i)
);
}
}
});

Ok(())
}