Skip to content

Commit 44cf77f

Browse files
authored
consolidation of examples: date_time_functions (apache#14240)
* consolidation: date_time_functions * Documentation
1 parent 5592834 commit 44cf77f

File tree

6 files changed

+628
-515
lines changed

6 files changed

+628
-515
lines changed

datafusion-examples/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ cargo run --example dataframe
6464
- [`file_stream_provider.rs`](examples/file_stream_provider.rs): Run a query on `FileStreamProvider` which implements `StreamProvider` for reading and writing to arbitrary stream sources / sinks.
6565
- [`flight_sql_server.rs`](examples/flight/flight_sql_server.rs): Run DataFusion as a standalone process and execute SQL queries from JDBC clients
6666
- [`function_factory.rs`](examples/function_factory.rs): Register `CREATE FUNCTION` handler to implement SQL macros
67-
- [`make_date.rs`](examples/make_date.rs): Examples of using the make_date function
6867
- [`optimizer_rule.rs`](examples/optimizer_rule.rs): Use a custom OptimizerRule to replace certain predicates
6968
- [`parquet_index.rs`](examples/parquet_index.rs): Create an secondary index over several parquet files and use it to speed up queries
7069
- [`parquet_exec_visitor.rs`](examples/parquet_exec_visitor.rs): Extract statistics by visiting an ExecutionPlan after execution
7170
- [`parse_sql_expr.rs`](examples/parse_sql_expr.rs): Parse SQL text into DataFusion `Expr`.
7271
- [`plan_to_sql.rs`](examples/plan_to_sql.rs): Generate SQL from DataFusion `Expr` and `LogicalPlan`
73-
- [`planner_api.rs](examples/planner_api.rs): APIs to manipulate logical and physical plans
72+
- [`planner_api.rs`](examples/planner_api.rs) APIs to manipulate logical and physical plans
7473
- [`pruning.rs`](examples/pruning.rs): Use pruning to rule out files based on statistics
7574
- [`query-aws-s3.rs`](examples/external_dependency/query-aws-s3.rs): Configure `object_store` and run a query against files stored in AWS S3
7675
- [`query-http-csv.rs`](examples/query-http-csv.rs): Configure `object_store` and run a query against files vi HTTP
@@ -82,9 +81,8 @@ cargo run --example dataframe
8281
- [`sql_analysis.rs`](examples/sql_analysis.rs): Analyse SQL queries with DataFusion structures
8382
- [`sql_frontend.rs`](examples/sql_frontend.rs): Create LogicalPlans (only) from sql strings
8483
- [`sql_dialect.rs`](examples/sql_dialect.rs): Example of implementing a custom SQL dialect on top of `DFParser`
85-
- [`sql_query.rs`](examples/memtable.rs): Query data using SQL (in memory `RecordBatch`es, local Parquet files)q
86-
- [`to_char.rs`](examples/to_char.rs): Examples of using the to_char function
87-
- [`to_timestamp.rs`](examples/to_timestamp.rs): Examples of using to_timestamp functions
84+
- [`sql_query.rs`](examples/memtable.rs): Query data using SQL (in memory `RecordBatches`, local Parquet files)
85+
- [`date_time_function.rs`](examples/date_time_function.rs): Examples of date-time related functions and queries.
8886

8987
## Distributed
9088

datafusion-examples/examples/dataframe.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ async fn main() -> Result<()> {
6464
read_csv(&ctx).await?;
6565
read_memory(&ctx).await?;
6666
write_out(&ctx).await?;
67-
query_to_date().await?;
6867
register_aggregate_test_data("t1", &ctx).await?;
6968
register_aggregate_test_data("t2", &ctx).await?;
7069
where_scalar_subquery(&ctx).await?;
@@ -231,41 +230,6 @@ async fn write_out(ctx: &SessionContext) -> std::result::Result<(), DataFusionEr
231230
Ok(())
232231
}
233232

234-
/// This example demonstrates how to use the to_date series
235-
/// of functions in the DataFrame API as well as via sql.
236-
async fn query_to_date() -> Result<()> {
237-
// define a schema.
238-
let schema = Arc::new(Schema::new(vec![Field::new("a", DataType::Utf8, false)]));
239-
240-
// define data.
241-
let batch = RecordBatch::try_new(
242-
schema,
243-
vec![Arc::new(StringArray::from(vec![
244-
"2020-09-08T13:42:29Z",
245-
"2020-09-08T13:42:29.190855-05:00",
246-
"2020-08-09 12:13:29",
247-
"2020-01-02",
248-
]))],
249-
)?;
250-
251-
// declare a new context. In spark API, this corresponds to a new spark SQLsession
252-
let ctx = SessionContext::new();
253-
254-
// declare a table in memory. In spark API, this corresponds to createDataFrame(...).
255-
ctx.register_batch("t", batch)?;
256-
let df = ctx.table("t").await?;
257-
258-
// use to_date function to convert col 'a' to timestamp type using the default parsing
259-
let df = df.with_column("a", to_date(vec![col("a")]))?;
260-
261-
let df = df.select_columns(&["a"])?;
262-
263-
// print the results
264-
df.show().await?;
265-
266-
Ok(())
267-
}
268-
269233
/// Use the DataFrame API to execute the following subquery:
270234
/// select c1,c2 from t1 where (select avg(t2.c2) from t2 where t1.c1 = t2.c1)>0 limit 3;
271235
async fn where_scalar_subquery(ctx: &SessionContext) -> Result<()> {

0 commit comments

Comments
 (0)