MCPcopy Create free account
hub / github.com/apache/datafusion / nyc

Function nyc

datafusion/core/tests/sql/mod.rs:298–351  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

296
297#[tokio::test]
298async fn nyc() -> Result<()> {
299 // schema for nyxtaxi csv files
300 let schema = Schema::new(vec![
301 Field::new("VendorID", DataType::Utf8, true),
302 Field::new("tpep_pickup_datetime", DataType::Utf8, true),
303 Field::new("tpep_dropoff_datetime", DataType::Utf8, true),
304 Field::new("passenger_count", DataType::Utf8, true),
305 Field::new("trip_distance", DataType::Float64, true),
306 Field::new("RatecodeID", DataType::Utf8, true),
307 Field::new("store_and_fwd_flag", DataType::Utf8, true),
308 Field::new("PULocationID", DataType::Utf8, true),
309 Field::new("DOLocationID", DataType::Utf8, true),
310 Field::new("payment_type", DataType::Utf8, true),
311 Field::new("fare_amount", DataType::Float64, true),
312 Field::new("extra", DataType::Float64, true),
313 Field::new("mta_tax", DataType::Float64, true),
314 Field::new("tip_amount", DataType::Float64, true),
315 Field::new("tolls_amount", DataType::Float64, true),
316 Field::new("improvement_surcharge", DataType::Float64, true),
317 Field::new("total_amount", DataType::Float64, true),
318 ]);
319
320 let ctx = SessionContext::new();
321 ctx.register_csv(
322 "tripdata",
323 "file:///file.csv",
324 CsvReadOptions::new().schema(&schema),
325 )
326 .await?;
327
328 let dataframe = ctx
329 .sql(
330 "SELECT passenger_count, MIN(fare_amount), MAX(fare_amount) \
331 FROM tripdata GROUP BY passenger_count",
332 )
333 .await?;
334 let optimized_plan = dataframe.into_optimized_plan().unwrap();
335
336 match &optimized_plan {
337 LogicalPlan::Aggregate(Aggregate { input, .. }) => match input.as_ref() {
338 LogicalPlan::TableScan(TableScan {
339 projected_schema, ..
340 }) => {
341 assert_eq!(2, projected_schema.fields().len());
342 assert_eq!(projected_schema.field(0).name(), "passenger_count");
343 assert_eq!(projected_schema.field(1).name(), "fare_amount");
344 }
345 _ => unreachable!(),
346 },
347 _ => unreachable!(),
348 }
349
350 Ok(())
351}

Callers

nothing calls this directly

Calls 6

newFunction · 0.85
sqlMethod · 0.80
into_optimized_planMethod · 0.80
register_csvMethod · 0.45
schemaMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected