Skip to content

Commit 5c558e9

Browse files
authored
Make DataFrame API consuming (#4621) (#4624)
* Make DataFrame API consuming (#4621) * Fix doc * More methods * Fix doc
1 parent 3611d91 commit 5c558e9

11 files changed

Lines changed: 246 additions & 253 deletions

File tree

‎datafusion-examples/examples/custom_datasource.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn search_accounts(
6969
)?
7070
.build()?;
7171

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

7575
if let Some(f) = filter {

‎datafusion-examples/examples/dataframe.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use datafusion::arrow::datatypes::{DataType, Field, Schema};
1919
use datafusion::error::Result;
2020
use datafusion::prelude::*;
2121
use std::fs;
22-
use std::sync::Arc;
2322

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

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

7776
// Example to read csv file with a defined schema for the csv file
78-
async fn example_read_csv_file_with_schema() -> Arc<DataFrame> {
77+
async fn example_read_csv_file_with_schema() -> DataFrame {
7978
let path = "example.csv";
8079
// Create a csv file using the predefined function
8180
create_csv_file(path.to_string());

‎datafusion-examples/examples/deserialize_to_struct.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Data {
5757
.sql("SELECT int_col, double_col FROM alltypes_plain")
5858
.await?;
5959

60-
df.show().await?;
60+
df.clone().show().await?;
6161

6262
df.collect().await?
6363
};

‎datafusion-examples/examples/flight_server.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ impl FlightService for FlightServiceImpl {
114114
let df = ctx.sql(sql).await.map_err(to_tonic_err)?;
115115

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

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

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

0 commit comments

Comments
 (0)