Skip to content

Commit

Permalink
Make DataFrame API consuming (apache#4621) (apache#4624)
Browse files Browse the repository at this point in the history
* Make DataFrame API consuming (apache#4621)

* Fix doc

* More methods

* Fix doc
  • Loading branch information
tustvold authored Dec 15, 2022
1 parent 3611d91 commit 5c558e9
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 253 deletions.
2 changes: 1 addition & 1 deletion datafusion-examples/examples/custom_datasource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn search_accounts(
)?
.build()?;

let mut dataframe = DataFrame::new(ctx.state, &logical_plan)
let mut dataframe = DataFrame::new(ctx.state, logical_plan)
.select_columns(&["id", "bank_account"])?;

if let Some(f) = filter {
Expand Down
5 changes: 2 additions & 3 deletions datafusion-examples/examples/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use datafusion::arrow::datatypes::{DataType, Field, Schema};
use datafusion::error::Result;
use datafusion::prelude::*;
use std::fs;
use std::sync::Arc;

/// This example demonstrates executing a simple query against an Arrow data source (Parquet) and
/// fetching results, using the DataFrame trait
Expand Down Expand Up @@ -64,7 +63,7 @@ a2,"08 9, 2013",2,1376006400,4.5"#;
}

// Example to read data from a csv file with inferred schema
async fn example_read_csv_file_with_inferred_schema() -> Arc<DataFrame> {
async fn example_read_csv_file_with_inferred_schema() -> DataFrame {
let path = "example.csv";
// Create a csv file using the predefined function
create_csv_file(path.to_string());
Expand All @@ -75,7 +74,7 @@ async fn example_read_csv_file_with_inferred_schema() -> Arc<DataFrame> {
}

// Example to read csv file with a defined schema for the csv file
async fn example_read_csv_file_with_schema() -> Arc<DataFrame> {
async fn example_read_csv_file_with_schema() -> DataFrame {
let path = "example.csv";
// Create a csv file using the predefined function
create_csv_file(path.to_string());
Expand Down
2 changes: 1 addition & 1 deletion datafusion-examples/examples/deserialize_to_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Data {
.sql("SELECT int_col, double_col FROM alltypes_plain")
.await?;

df.show().await?;
df.clone().show().await?;

df.collect().await?
};
Expand Down
4 changes: 2 additions & 2 deletions datafusion-examples/examples/flight_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ impl FlightService for FlightServiceImpl {
let df = ctx.sql(sql).await.map_err(to_tonic_err)?;

// execute the query
let schema = df.schema().clone().into();
let results = df.collect().await.map_err(to_tonic_err)?;
if results.is_empty() {
return Err(Status::internal("There were no results from ticket"));
}

// add an initial FlightData message that sends schema
let options = datafusion::arrow::ipc::writer::IpcWriteOptions::default();
let schema_flight_data =
SchemaAsIpc::new(&df.schema().clone().into(), &options).into();
let schema_flight_data = SchemaAsIpc::new(&schema, &options).into();

let mut flights: Vec<Result<FlightData, Status>> =
vec![Ok(schema_flight_data)];
Expand Down
Loading

0 comments on commit 5c558e9

Please sign in to comment.