Skip to content

Commit 9e39afd

Browse files
Omega359alamb
andauthored
Move the to_timestamp* functions to datafusion-functions (#9388)
* WIP * WIP * cargo fmt updates. * Migrate to_timestamp* functions to new functions crate. * update to allow wasm run to complete. * Fix expr_api example * cargo fmt. * Update datafusion/core/tests/simplification.rs Co-authored-by: Andrew Lamb <[email protected]> * Revert changes to sql in tests to restore to_timestamp(..) calls. * Rust fmt apparently can't make up it's mind. * Updates for merge and moving some expression simplifier tests from optimizer to core/tests. * Revert test changes * Update datafusion/core/tests/simplification.rs * Move cast_column to `ColumnarValue::cast_to` * Remove datafusion-physical-expr dependency * Move dependencies to dev * Fix merge conflict by migrating to_date to new functions module alongside to_timestamp. * Cargo lock update from merge. * Add missing licenses. --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent b2ff249 commit 9e39afd

File tree

33 files changed

+2035
-1807
lines changed

33 files changed

+2035
-1807
lines changed

.github/workflows/rust.yml

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
- name: Check function packages (array_expressions)
8989
run: cargo check --no-default-features --features=array_expressions -p datafusion
9090

91+
- name: Check function packages (datetime_expressions)
92+
run: cargo check --no-default-features --features=datetime_expressions -p datafusion
93+
9194
- name: Check Cargo.lock for datafusion-cli
9295
run: |
9396
# If this test fails, try running `cargo update` in the `datafusion-cli` directory

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Default features:
7878
- `array_expressions`: functions for working with arrays such as `array_to_string`
7979
- `compression`: reading files compressed with `xz2`, `bzip2`, `flate2`, and `zstd`
8080
- `crypto_expressions`: cryptographic functions such as `md5` and `sha256`
81+
- `datetime_expressions`: date and time functions such as `to_timestamp`
8182
- `encoding_expressions`: `encode` and `decode` functions
8283
- `parquet`: support for reading the [Apache Parquet] format
8384
- `regex_expressions`: regular expression functions, such as `regexp_match`

datafusion-cli/Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion-cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ clap = { version = "3", features = ["derive", "cargo"] }
3838
datafusion = { path = "../datafusion/core", version = "36.0.0", features = [
3939
"avro",
4040
"crypto_expressions",
41+
"datetime_expressions",
4142
"encoding_expressions",
4243
"parquet",
4344
"regex_expressions",

datafusion-examples/examples/expr_api.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use std::collections::HashMap;
19+
use std::sync::Arc;
20+
1821
use arrow::array::{BooleanArray, Int32Array};
1922
use arrow::record_batch::RecordBatch;
23+
2024
use datafusion::arrow::datatypes::{DataType, Field, Schema, TimeUnit};
2125
use datafusion::common::{DFField, DFSchema};
2226
use datafusion::error::Result;
@@ -30,8 +34,6 @@ use datafusion_common::{ScalarValue, ToDFSchema};
3034
use datafusion_expr::expr::BinaryExpr;
3135
use datafusion_expr::interval_arithmetic::Interval;
3236
use datafusion_expr::{ColumnarValue, ExprSchemable, Operator};
33-
use std::collections::HashMap;
34-
use std::sync::Arc;
3537

3638
/// This example demonstrates the DataFusion [`Expr`] API.
3739
///
@@ -113,10 +115,7 @@ fn evaluate_demo() -> Result<()> {
113115
fn simplify_demo() -> Result<()> {
114116
// For example, lets say you have has created an expression such
115117
// ts = to_timestamp("2020-09-08T12:00:00+00:00")
116-
let expr = col("ts").eq(call_fn(
117-
"to_timestamp",
118-
vec![lit("2020-09-08T12:00:00+00:00")],
119-
)?);
118+
let expr = col("ts").eq(to_timestamp(vec![lit("2020-09-08T12:00:00+00:00")]));
120119

121120
// Naively evaluating such an expression against a large number of
122121
// rows would involve re-converting "2020-09-08T12:00:00+00:00" to a

datafusion/common/src/format.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use arrow::compute::CastOptions;
1819
use arrow::util::display::{DurationFormat, FormatOptions};
1920

2021
/// The default [`FormatOptions`] to use within DataFusion
2122
pub const DEFAULT_FORMAT_OPTIONS: FormatOptions<'static> =
2223
FormatOptions::new().with_duration_format(DurationFormat::Pretty);
24+
25+
/// The default [`CastOptions`] to use within DataFusion
26+
pub const DEFAULT_CAST_OPTIONS: CastOptions<'static> = CastOptions {
27+
safe: false,
28+
format_options: DEFAULT_FORMAT_OPTIONS,
29+
};

datafusion/core/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ avro = ["apache-avro", "num-traits", "datafusion-common/avro"]
4343
backtrace = ["datafusion-common/backtrace"]
4444
compression = ["xz2", "bzip2", "flate2", "zstd", "async-compression", "tokio-util"]
4545
crypto_expressions = ["datafusion-physical-expr/crypto_expressions", "datafusion-optimizer/crypto_expressions"]
46+
datetime_expressions = ["datafusion-functions/datetime_expressions"]
4647
default = [
4748
"array_expressions",
4849
"crypto_expressions",
50+
"datetime_expressions",
4951
"encoding_expressions",
5052
"regex_expressions",
5153
"unicode_expressions",

0 commit comments

Comments
 (0)