andygrove commented on code in PR #329:
URL: https://github.com/apache/datafusion-spark/pull/329#discussion_r4607469895
##########
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 for the correction. In 98e1f48 the doc sentence now uses your
wording. The slt file has the DECIMAL wrapping case you gave, a 1e10 DOUBLE
case, and comments on saturation and wrapping. The int32_coercion comment now
says "returns NULL, wraps, or saturates". I checked each value on PySpark 4.2.0
with ANSI off.
--
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]