andygrove commented on code in PR #329:
URL: https://github.com/apache/datafusion-spark/pull/329#discussion_r4628825912
##########
crates/spark/src/function/datetime/make_date.rs:
##########
@@ -0,0 +1,538 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF)
under one or more contributor license agreements
+
+use std::sync::Arc;
+
+use arrow::array::{Array, Date32Array, Date32Builder, new_empty_array};
+use arrow::datatypes::{DataType, Field, FieldRef};
+use datafusion_common::cast::as_int32_array;
+use datafusion_common::types::{NativeType, logical_int32, logical_string};
+use datafusion_common::utils::take_function_args;
+use datafusion_common::{Result, ScalarValue, exec_err, internal_err};
+use datafusion_expr::{
+ Coercion, ColumnarValue, Documentation, ReturnFieldArgs,
ScalarFunctionArgs,
+ ScalarUDFImpl, Signature, TypeSignatureClass, Volatility,
+};
+use datafusion_macros::user_doc;
+
+const ARITHMETIC_OVERFLOW_ERROR: &str = r#"[ARITHMETIC_OVERFLOW] overflow. If
necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
SQLSTATE: 22003"#;
+
+/// Spark-compatible `make_date` expression.
+///
+/// <https://spark.apache.org/docs/latest/api/sql/index.html#make_date>
+#[user_doc(
+ doc_section(label = "Time and Date Functions"),
+ description = "Creates a date from `year`, `month` and `day` fields.
DataFusion has no built-in \
+ equivalent. Years from -999999999 to 999999999 are accepted (year 0 is
1 BC), as long as \
+ the date fits the DATE range. When the fields do not form a valid date
(for example \
+ month 13 or February 29 in a non-leap year), the function returns
NULL, or raises \
+ DATETIME_FIELD_OUT_OF_BOUNDS when
`datafusion.execution.enable_ansi_mode` is true. A \
+ valid date outside the DATE range (before -5877641-06-23 or after
+5881580-07-11) raises \
+ ARITHMETIC_OVERFLOW in both modes, as in Spark. Other numeric and
string inputs are cast \
+ to INT first, which truncates fractions and raises an error if the
value is out of the \
+ INT range or is not a valid number. These errors match Spark with ANSI
mode enabled. \
+ With ANSI mode disabled, Spark wraps an out-of-range BIGINT and
returns NULL for a \
+ malformed string, while this function still errors (see \
Review Comment:
Thanks, all three are in 04199a2. The `#[user_doc]` sentence now uses your
wording, `make_date.slt` has the `'2024.7'` case, and the `int32_coercion()`
comment now says it errors in cases where Spark with ANSI mode off returns a
value or NULL. I checked the four values you gave on PySpark 4.2.0 in both
modes.
Since #368 landed, I also turned the commented-out records into live ones in
1815b8b. Each asserts DataFusion's current cast error and has a `# xfail
spark:` marker linking #88, so the PySpark runner tracks them and will flag
when they start matching. The NaN record casts the date to STRING, because
PySpark can't convert year 0 to a Python date. After merging `main`, the
`unix_date` record is `skipif evaluate` as in `unix.slt`, until #306 is fixed.
All `datetime/` files pass in both modes, and the runner reports 32 passes and
8 expected failures for `make_date.slt`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]