diff --git a/cpp/src/gandiva/function_registry_datetime.cc b/cpp/src/gandiva/function_registry_datetime.cc index e7172e84170c6..4849c731b86f9 100644 --- a/cpp/src/gandiva/function_registry_datetime.cc +++ b/cpp/src/gandiva/function_registry_datetime.cc @@ -69,6 +69,10 @@ std::vector GetDateTimeFunctionRegistry() { kResultNullIfNull, "castTIMESTAMP_utf8", NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors), + NativeFunction("castTIMESTAMP_with_validation_check", {}, DataTypeVector{utf8()}, timestamp(), + kResultNullInternal, "castTIMESTAMP_with_validation_check_utf8", + NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors), + NativeFunction("castTIMESTAMP_withCarrying", {}, DataTypeVector{utf8()}, timestamp(), kResultNullInternal, "castTIMESTAMP_withCarrying_utf8", NativeFunction::kNeedsContext | NativeFunction::kCanReturnErrors), diff --git a/cpp/src/gandiva/precompiled/time.cc b/cpp/src/gandiva/precompiled/time.cc index 42bf535937b7f..b9def96162991 100644 --- a/cpp/src/gandiva/precompiled/time.cc +++ b/cpp/src/gandiva/precompiled/time.cc @@ -871,6 +871,23 @@ gdv_timestamp castTIMESTAMP_utf8(int64_t context, const char* input, gdv_int32 l return std::chrono::time_point_cast(date_time).time_since_epoch().count(); } +gdv_timestamp castTIMESTAMP_with_validation_check_utf8(int64_t context, const char* input, + gdv_int32 length, bool in_valid, + bool* out_valid) { + if (!in_valid) { + *out_valid = false; + return 0; + } + // Suppose the input is yyyy-MM-dd. + // TODO: check validaition during/after parsing. + if (length > 10) { + *out_valid = false; + return 0; + } + return castTIMESTAMP_withCarrying_utf8(context, input, length, in_valid, out_valid); +} + + /* * Input consists of mandatory and optional fields. * Mandatory fields are year, month and day. diff --git a/cpp/src/gandiva/precompiled/types.h b/cpp/src/gandiva/precompiled/types.h index b16351b7ace51..64051b20a3725 100644 --- a/cpp/src/gandiva/precompiled/types.h +++ b/cpp/src/gandiva/precompiled/types.h @@ -425,6 +425,9 @@ gdv_timestamp castTIMESTAMP_utf8(int64_t execution_context, const char* input, gdv_timestamp castTIMESTAMP_withCarrying_utf8(int64_t context, const char* input, gdv_int32 length, bool in_valid, bool* out_valid); +gdv_timestamp castTIMESTAMP_with_validation_check_utf8(int64_t context, const char* input, + gdv_int32 length, bool in_valid, + bool* out_valid); gdv_timestamp castTIMESTAMP_date64(gdv_date64); gdv_timestamp castTIMESTAMP_int64(gdv_int64); gdv_date64 castDATE_timestamp(gdv_timestamp);