diff options
author | imunkin <imunkin@yandex-team.com> | 2025-02-28 15:10:21 +0300 |
---|---|---|
committer | imunkin <imunkin@yandex-team.com> | 2025-02-28 16:34:40 +0300 |
commit | 2c78e37f663e4321fb887df5aa0977eab5be1c2c (patch) | |
tree | b18633f76725c5090e9e0a6b50810e407231f413 | |
parent | 680ad352dc598780b4945d5420f8168c1665dad2 (diff) | |
download | ydb-2c78e37f663e4321fb887df5aa0977eab5be1c2c.tar.gz |
YQL-18303: Introduce To* overloads
commit_hash:99b69544bd45b52e2e6bfcd8cd51e34827a0f08d
7 files changed, 1260 insertions, 120 deletions
diff --git a/yql/essentials/udfs/common/datetime2/datetime_udf.cpp b/yql/essentials/udfs/common/datetime2/datetime_udf.cpp index c0157f2365..c56b22a7fa 100644 --- a/yql/essentials/udfs/common/datetime2/datetime_udf.cpp +++ b/yql/essentials/udfs/common/datetime2/datetime_udf.cpp @@ -13,6 +13,9 @@ using namespace NUdf; using namespace NYql::DateTime; extern const char SplitUDF[] = "Split"; +extern const char ToDaysUDF[] = "ToDays"; +extern const char ToHoursUDF[] = "ToHours"; +extern const char ToMinutesUDF[] = "ToMinutes"; extern const char ToSecondsUDF[] = "ToSeconds"; extern const char ToMillisecondsUDF[] = "ToMilliseconds"; extern const char ToMicrosecondsUDF[] = "ToMicroseconds"; @@ -59,7 +62,7 @@ const auto UsecondsInMinute = 60000000ll; const auto UsecondsInSecond = 1000000ll; const auto UsecondsInMilliseconds = 1000ll; -template <const char* TFuncName, typename TResult, ui32 ScaleAfterSeconds> +template <const char* TFuncName, typename TResult, typename TWResult, ui32 ScaleAfterSeconds> class TToUnits { public: typedef bool TTypeAwareMarker; @@ -69,6 +72,10 @@ public: return value * ui32(86400) * TResult(ScaleAfterSeconds); } + static TWResult Date32Core(i32 value) { + return value * i64(86400) * TWResult(ScaleAfterSeconds); + } + template<typename TTzDate> static TResult TzBlockCore(TBlockItem tzDate); @@ -91,14 +98,26 @@ public: return value * TResult(ScaleAfterSeconds); } + static TWResult Datetime64Core(i64 value) { + return value * TWResult(ScaleAfterSeconds); + } + static TResult TimestampCore(ui64 value) { return TResult(value / (1000000u / ScaleAfterSeconds)); } + static TWResult Timestamp64Core(i64 value) { + return TWResult(value / (1000000u / ScaleAfterSeconds)); + } + static TSignedResult IntervalCore(i64 value) { return TSignedResult(value / (1000000u / ScaleAfterSeconds)); } + static TWResult Interval64Core(i64 value) { + return TWResult(value / (1000000u / ScaleAfterSeconds)); + } + static const TStringRef& Name() { static auto name = TStringRef(TFuncName, std::strlen(TFuncName)); return name; @@ -120,125 +139,166 @@ public: return false; } - try { - auto typeInfoHelper = builder.TypeInfoHelper(); - TTupleTypeInspector tuple(*typeInfoHelper, userType); - Y_ENSURE(tuple); - Y_ENSURE(tuple.GetElementsCount() > 0); - TTupleTypeInspector argsTuple(*typeInfoHelper, tuple.GetElementType(0)); - Y_ENSURE(argsTuple); - if (argsTuple.GetElementsCount() != 1) { - builder.SetError("Expected one argument"); - return true; - } + if (!userType) { + builder.SetError("User type is missing"); + return true; + } + builder.UserType(userType); - auto argType = argsTuple.GetElementType(0); - TVector<const TType*> argBlockTypes; - argBlockTypes.push_back(argType); + const auto typeInfoHelper = builder.TypeInfoHelper(); + TTupleTypeInspector tuple(*typeInfoHelper, userType); + Y_ENSURE(tuple, "Tuple with args and options tuples expected"); + Y_ENSURE(tuple.GetElementsCount() > 0, + "Tuple has to contain positional arguments"); - TBlockTypeInspector block(*typeInfoHelper, argType); - if (block) { - Y_ENSURE(!block.IsScalar()); - argType = block.GetItemType(); - } + TTupleTypeInspector argsTuple(*typeInfoHelper, tuple.GetElementType(0)); + Y_ENSURE(argsTuple, "Tuple with args expected"); + if (argsTuple.GetElementsCount() != 1) { + builder.SetError("Single argument expected"); + return true; + } - bool isOptional = false; - if (auto opt = TOptionalTypeInspector(*typeInfoHelper, argType)) { - argType = opt.GetItemType(); - isOptional = true; - } + auto argType = argsTuple.GetElementType(0); + TVector<const TType*> argBlockTypes; + argBlockTypes.push_back(argType); - TDataTypeInspector data(*typeInfoHelper, argType); - if (!data) { - builder.SetError("Expected data type"); - return true; - } + TBlockTypeInspector block(*typeInfoHelper, argType); + if (block) { + Y_ENSURE(!block.IsScalar()); + argType = block.GetItemType(); + } - auto typeId = data.GetTypeId(); - if (!(typeId == TDataType<TDate>::Id || typeId == TDataType<TTzDate>::Id || - typeId == TDataType<TDatetime>::Id || typeId == TDataType<TTzDatetime>::Id || - typeId == TDataType<TTimestamp>::Id || typeId == TDataType<TTzTimestamp>::Id || - typeId == TDataType<TInterval>::Id)) { - builder.SetError(TStringBuilder() << "Type " << GetDataTypeInfo(GetDataSlot(typeId)).Name << " is not supported"); - } + bool isOptional = false; + if (auto opt = TOptionalTypeInspector(*typeInfoHelper, argType)) { + argType = opt.GetItemType(); + isOptional = true; + } - builder.Args()->Add(argsTuple.GetElementType(0)).Done(); - const TType* retType; - if (typeId != TDataType<TInterval>::Id) { - retType = builder.SimpleType<TResult>(); - } else { - retType = builder.SimpleType<TSignedResult>(); - } - if (isOptional) { - retType = builder.Optional()->Item(retType).Build(); - } + TDataTypeInspector data(*typeInfoHelper, argType); + if (!data) { + builder.SetError("Data type expected"); + return true; + } - auto outputType = retType; - if (block) { - retType = builder.Block(block.IsScalar())->Item(retType).Build(); - } + const auto typeId = data.GetTypeId(); + const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(typeId)).Features; + + if (!(features & (NUdf::DateType | NUdf::TzDateType | NUdf::TimeIntervalType))) { + builder.SetError(TStringBuilder() + << "Type " + << GetDataTypeInfo(GetDataSlot(typeId)).Name + << " is not supported"); + return true; + } + + builder.Args()->Add(argsTuple.GetElementType(0)); + const TType* retType; + if (features & NUdf::BigDateType) { + retType = builder.SimpleType<TWResult>(); + } else if (features & NUdf::TimeIntervalType) { + retType = builder.SimpleType<TSignedResult>(); + } else { + retType = builder.SimpleType<TResult>(); + } + + if (isOptional) { + retType = builder.Optional()->Item(retType).Build(); + } - builder.Returns(retType); + auto outputType = retType; + if (block) { + retType = builder.Block(block.IsScalar())->Item(retType).Build(); + } + + builder.Returns(retType); + if (!(features & NUdf::BigDateType)) { + // FIXME: Only non-wide overloads support block rewrite now. builder.SupportsBlocks(); - builder.IsStrict(); + } + builder.IsStrict(); - builder.UserType(userType); - if (!typesOnly) { - if (typeId == TDataType<TDate>::Id || typeId == TDataType<TTzDate>::Id) { - if (block) { - const auto exec = (typeId == TDataType<TTzDate>::Id) - ? MakeTzBlockExec<TTzDate, TResult>() - : UnaryPreallocatedExecImpl<ui16, TResult, DateCore>; - - builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), - exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); - } else { - builder.Implementation(new TUnaryOverOptionalImpl<ui16, TResult, DateCore>()); - } + if (!typesOnly) { + if (typeId == TDataType<TDate>::Id || typeId == TDataType<TTzDate>::Id) { + if (block) { + const auto exec = (typeId == TDataType<TTzDate>::Id) + ? MakeTzBlockExec<TTzDate, TResult>() + : UnaryPreallocatedExecImpl<ui16, TResult, DateCore>; + + builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), + exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); + } else { + builder.Implementation(new TUnaryOverOptionalImpl<ui16, TResult, DateCore>()); } + return true; + } - if (typeId == TDataType<TDatetime>::Id || typeId == TDataType<TTzDatetime>::Id) { - if (block) { - const auto exec = (typeId == TDataType<TTzDatetime>::Id) - ? MakeTzBlockExec<TTzDatetime, TResult>() - : UnaryPreallocatedExecImpl<ui32, TResult, DatetimeCore>; + if (typeId == TDataType<TDatetime>::Id || typeId == TDataType<TTzDatetime>::Id) { + if (block) { + const auto exec = (typeId == TDataType<TTzDatetime>::Id) + ? MakeTzBlockExec<TTzDatetime, TResult>() + : UnaryPreallocatedExecImpl<ui32, TResult, DatetimeCore>; - builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), - exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); - } else { - builder.Implementation(new TUnaryOverOptionalImpl<ui32, TResult, DatetimeCore>()); - } + builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), + exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); + } else { + builder.Implementation(new TUnaryOverOptionalImpl<ui32, TResult, DatetimeCore>()); } + return true; + } - if (typeId == TDataType<TTimestamp>::Id || typeId == TDataType<TTzTimestamp>::Id) { - if (block) { - const auto exec = (typeId == TDataType<TTzTimestamp>::Id) - ? MakeTzBlockExec<TTzTimestamp, TResult>() - : UnaryPreallocatedExecImpl<ui64, TResult, TimestampCore>; + if (typeId == TDataType<TTimestamp>::Id || typeId == TDataType<TTzTimestamp>::Id) { + if (block) { + const auto exec = (typeId == TDataType<TTzTimestamp>::Id) + ? MakeTzBlockExec<TTzTimestamp, TResult>() + : UnaryPreallocatedExecImpl<ui64, TResult, TimestampCore>; - builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), - exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); - } else { - builder.Implementation(new TUnaryOverOptionalImpl<ui64, TResult, TimestampCore>()); - } + builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), + exec, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); + } else { + builder.Implementation(new TUnaryOverOptionalImpl<ui64, TResult, TimestampCore>()); } + return true; + } - if (typeId == TDataType<TInterval>::Id) { - if (block) { - builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), - UnaryPreallocatedExecImpl<i64, TSignedResult, IntervalCore>, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); - } else { - builder.Implementation(new TUnaryOverOptionalImpl<i64, TSignedResult, IntervalCore>()); - } + if (typeId == TDataType<TInterval>::Id) { + if (block) { + builder.Implementation(new TSimpleArrowUdfImpl(argBlockTypes, outputType, block.IsScalar(), + UnaryPreallocatedExecImpl<i64, TSignedResult, IntervalCore>, builder, TString(name), arrow::compute::NullHandling::INTERSECTION)); + } else { + builder.Implementation(new TUnaryOverOptionalImpl<i64, TSignedResult, IntervalCore>()); } + return true; } - } catch (const std::exception& e) { - builder.SetError(TStringBuf(e.what())); - } + if (typeId == TDataType<TDate32>::Id || typeId == TDataType<TTzDate32>::Id) { + Y_ABORT_IF(block, "Block overload is not supported"); + builder.Implementation(new TUnaryOverOptionalImpl<i32, TWResult, Date32Core>()); + return true; + } + + if (typeId == TDataType<TDatetime64>::Id || typeId == TDataType<TTzDatetime64>::Id) { + Y_ABORT_IF(block, "Block overload is not supported"); + builder.Implementation(new TUnaryOverOptionalImpl<i64, TWResult, Datetime64Core>()); + return true; + } + + if (typeId == TDataType<TTimestamp64>::Id || typeId == TDataType<TTzTimestamp64>::Id) { + Y_ABORT_IF(block, "Block overload is not supported"); + builder.Implementation(new TUnaryOverOptionalImpl<i64, TWResult, Timestamp64Core>()); + return true; + } + + if (typeId == TDataType<TInterval64>::Id) { + Y_ABORT_IF(block, "Block overload is not supported"); + builder.Implementation(new TUnaryOverOptionalImpl<i64, TWResult, Interval64Core>()); + return true; + } + + Y_UNREACHABLE(); + } return true; } }; @@ -1770,29 +1830,106 @@ TUnboxedValue GetTimezoneName(const IValueBuilder* valueBuilder, const TUnboxedV // To* - BEGIN_SIMPLE_STRICT_ARROW_UDF(TToDays, i32(TAutoMap<TInterval>)) { - Y_UNUSED(valueBuilder); - return TUnboxedValuePod(i32(args[0].Get<i64>() / UsecondsInDay)); +template<const char* TUdfName, typename TResult, typename TWResult, i64 ScaleSeconds> +class TToConverter : public TBoxedValue { +public: + typedef bool TTypeAwareMarker; + static const ::NYql::NUdf::TStringRef& Name() { + static auto name = TStringRef(TUdfName, std::strlen(TUdfName)); + return name; } - END_SIMPLE_ARROW_UDF_WITH_NULL_HANDLING(TToDays, - (UnaryPreallocatedExecImpl<i64, i32, [] (i64 arg) { return i32(arg / UsecondsInDay); }>), - arrow::compute::NullHandling::INTERSECTION); - BEGIN_SIMPLE_STRICT_ARROW_UDF(TToHours, i32(TAutoMap<TInterval>)) { - Y_UNUSED(valueBuilder); - return TUnboxedValuePod(i32(args[0].Get<i64>() / UsecondsInHour)); + static bool DeclareSignature( + const TStringRef& name, + TType* userType, + IFunctionTypeInfoBuilder& builder, + bool typesOnly) + { + if (Name() != name) { + return false; + } + + if (!userType) { + builder.SetError("User type is missing"); + return true; + } + + builder.UserType(userType); + + const auto typeInfoHelper = builder.TypeInfoHelper(); + TTupleTypeInspector tuple(*typeInfoHelper, userType); + Y_ENSURE(tuple, "Tuple with args and options tuples expected"); + Y_ENSURE(tuple.GetElementsCount() > 0, + "Tuple has to contain positional arguments"); + + TTupleTypeInspector argsTuple(*typeInfoHelper, tuple.GetElementType(0)); + Y_ENSURE(argsTuple, "Tuple with args expected"); + if (argsTuple.GetElementsCount() != 1) { + builder.SetError("Single argument expected"); + return true; + } + + auto argType = argsTuple.GetElementType(0); + + if (const auto optType = TOptionalTypeInspector(*typeInfoHelper, argType)) { + argType = optType.GetItemType(); + } + + TDataTypeInspector data(*typeInfoHelper, argType); + if (!data) { + SetInvalidTypeError(builder, typeInfoHelper, argType); + return true; + } + + const auto features = NUdf::GetDataTypeInfo(NUdf::GetDataSlot(data.GetTypeId())).Features; + if (features & NUdf::TimeIntervalType) { + if (features & NUdf::BigDateType) { + BuildSignature<TInterval64, TWResult>(builder, typesOnly); + } else { + BuildSignature<TInterval, TResult>(builder, typesOnly); + } + return true; + } + SetInvalidTypeError(builder, typeInfoHelper, argType); + return true; + } +private: + class TImpl : public TBoxedValue { + public: + TUnboxedValue Run(const IValueBuilder* valueBuilder, const TUnboxedValuePod* args) const final { + try { + Y_UNUSED(valueBuilder); + return TUnboxedValuePod(i64(args[0].Get<i64>() / ScaleSeconds)); + } catch (const std::exception& e) { + TStringBuilder sb; + sb << CurrentExceptionMessage(); + sb << Endl << "[" << TStringBuf(Name()) << "]" ; + UdfTerminate(sb.c_str()); + } + } + + }; + + static void SetInvalidTypeError(NUdf::IFunctionTypeInfoBuilder& builder, + ITypeInfoHelper::TPtr typeInfoHelper, const TType* argType) + { + ::TStringBuilder sb; + sb << "Invalid argument type: got "; + TTypePrinter(*typeInfoHelper, argType).Out(sb.Out); + sb << ", but Interval or Interval64 expected"; + builder.SetError(sb); } - END_SIMPLE_ARROW_UDF_WITH_NULL_HANDLING(TToHours, - (UnaryPreallocatedExecImpl<i64, i32, [] (i64 arg) { return i32(arg / UsecondsInHour); }>), - arrow::compute::NullHandling::INTERSECTION); - BEGIN_SIMPLE_STRICT_ARROW_UDF(TToMinutes, i32(TAutoMap<TInterval>)) { - Y_UNUSED(valueBuilder); - return TUnboxedValuePod(i32(args[0].Get<i64>() / UsecondsInMinute)); + template<typename TInput, typename TOutput> + static void BuildSignature(NUdf::IFunctionTypeInfoBuilder& builder, bool typesOnly) { + builder.Returns<TOutput>(); + builder.Args()->Add<TAutoMap<TInput>>(); + builder.IsStrict(); + if (!typesOnly) { + builder.Implementation(new TImpl()); + } } - END_SIMPLE_ARROW_UDF_WITH_NULL_HANDLING(TToMinutes, - (UnaryPreallocatedExecImpl<i64, i32, [] (i64 arg) { return i32(arg / UsecondsInMinute); }>), - arrow::compute::NullHandling::INTERSECTION); +}; // StartOf* @@ -3298,9 +3435,9 @@ private: TInterval64FromMilliseconds, TInterval64FromMicroseconds, - TToDays, - TToHours, - TToMinutes, + TToConverter<ToDaysUDF, i32, i32, UsecondsInDay>, + TToConverter<ToHoursUDF, i32, i64, UsecondsInHour>, + TToConverter<ToMinutesUDF, i32, i64, UsecondsInMinute>, TBoundaryOf<StartOfYearUDF, SimpleDatetimeToDatetimeUdf<TMResourceName, StartOfYear<TTMStorage>>, SimpleDatetimeToDatetimeUdf<TM64ResourceName, StartOfYear<TTM64Storage>>>, @@ -3333,9 +3470,9 @@ private: TBoundaryOfInterval<EndOfUDF, SimpleDatetimeToIntervalUdf<TMResourceName, EndOf<TTMStorage>>, SimpleDatetimeToIntervalUdf<TM64ResourceName, EndOf<TTM64Storage>>>, - TToUnits<ToSecondsUDF, ui32, 1>, - TToUnits<ToMillisecondsUDF, ui64, 1000>, - TToUnits<ToMicrosecondsUDF, ui64, 1000000>, + TToUnits<ToSecondsUDF, ui32, i64, 1>, + TToUnits<ToMillisecondsUDF, ui64, i64, 1000>, + TToUnits<ToMicrosecondsUDF, ui64, i64, 1000000>, TFormat, TParse<ParseUDF, TMResourceName>, diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/result.json b/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/result.json index 79e742fc9f..c88d3bdf2a 100644 --- a/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/result.json +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/result.json @@ -44,6 +44,11 @@ "uri": "file://test.test_StartOf_/results.txt" } ], + "test.test[To]": [ + { + "uri": "file://test.test_To_/results.txt" + } + ], "test.test[UpdateTz]": [ { "uri": "file://test.test_UpdateTz_/results.txt" diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/test.test_To_/results.txt b/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/test.test_To_/results.txt new file mode 100644 index 0000000000..2c6a80c75a --- /dev/null +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/canondata/test.test_To_/results.txt @@ -0,0 +1,826 @@ +[ + { + "Write" = [ + { + "Type" = [ + "ListType"; + [ + "StructType"; + [ + [ + "interval64_to_days"; + [ + "OptionalType"; + [ + "DataType"; + "Int32" + ] + ] + ]; + [ + "interval64_to_hours"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "interval64_to_minutes"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "interval64_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "interval64_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "interval64_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "date32_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "datetime64_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "timestamp64_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdate32_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdatetime64_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tztimestamp64_to_seconds"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "date32_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "datetime64_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "timestamp64_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdate32_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdatetime64_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tztimestamp64_to_msec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "date32_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "datetime64_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "timestamp64_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdate32_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tzdatetime64_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ]; + [ + "tztimestamp64_to_usec"; + [ + "OptionalType"; + [ + "DataType"; + "Int64" + ] + ] + ] + ] + ] + ]; + "Data" = [ + [ + [ + "-106751616" + ]; + [ + "-2562038807" + ]; + [ + "-153722328479" + ]; + [ + "-9223339708799" + ]; + [ + "-9223339708799000" + ]; + [ + "-9223339708799000000" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-4611669897600000000" + ] + ]; + [ + [ + "-53375809" + ]; + [ + "-1281019416" + ]; + [ + "-76861164960" + ]; + [ + "-4611669897600" + ]; + [ + "-4611669897600000" + ]; + [ + "-4611669897600000000" + ]; + [ + "-62167219200" + ]; + [ + "-62167132801" + ]; + [ + "-62167132800" + ]; + [ + "-62167305600" + ]; + [ + "-62167141818" + ]; + [ + "-62167141817" + ]; + [ + "-62167219200000" + ]; + [ + "-62167132801000" + ]; + [ + "-62167132800000" + ]; + [ + "-62167305600000" + ]; + [ + "-62167141818000" + ]; + [ + "-62167141817000" + ]; + [ + "-62167219200000000" + ]; + [ + "-62167132801000000" + ]; + [ + "-62167132800000001" + ]; + [ + "-62167305600000000" + ]; + [ + "-62167141818000000" + ]; + [ + "-62167141817000001" + ] + ]; + [ + [ + "-1" + ]; + [ + "-24" + ]; + [ + "-1440" + ]; + [ + "-86400" + ]; + [ + "-86400000" + ]; + [ + "-86400000000" + ]; + [ + "-62135596800" + ]; + [ + "-62135596800" + ]; + [ + "-62135596800" + ]; + [ + "-62135683200" + ]; + [ + "-62135605817" + ]; + [ + "-62135605817" + ]; + [ + "-62135596800000" + ]; + [ + "-62135596800000" + ]; + [ + "-62135596800000" + ]; + [ + "-62135683200000" + ]; + [ + "-62135605817000" + ]; + [ + "-62135605817000" + ]; + [ + "-62135596800000000" + ]; + [ + "-62135596800000000" + ]; + [ + "-62135596800000000" + ]; + [ + "-62135683200000000" + ]; + [ + "-62135605817000000" + ]; + [ + "-62135605817000000" + ] + ]; + [ + #; + #; + #; + #; + #; + #; + [ + "-86400" + ]; + [ + "-1" + ]; + [ + "0" + ]; + [ + "-172800" + ]; + [ + "-10801" + ]; + [ + "-10800" + ]; + [ + "-86400000" + ]; + [ + "-1000" + ]; + [ + "0" + ]; + [ + "-172800000" + ]; + [ + "-10801000" + ]; + [ + "-10800000" + ]; + [ + "-86400000000" + ]; + [ + "-1000000" + ]; + [ + "-1" + ]; + [ + "-172800000000" + ]; + [ + "-10801000000" + ]; + [ + "-10800000001" + ] + ]; + [ + [ + "1" + ]; + [ + "24" + ]; + [ + "1440" + ]; + [ + "86400" + ]; + [ + "86400000" + ]; + [ + "86400000000" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "-86400" + ]; + [ + "-10800" + ]; + [ + "-10800" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "-86400000" + ]; + [ + "-10800000" + ]; + [ + "-10800000" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "0" + ]; + [ + "-86400000000" + ]; + [ + "-10800000000" + ]; + [ + "-10800000000" + ] + ]; + [ + #; + #; + #; + #; + #; + #; + [ + "1735689600" + ]; + [ + "1735693323" + ]; + [ + "1735693323" + ]; + [ + "1735603200" + ]; + [ + "1735693323" + ]; + [ + "1735693323" + ]; + [ + "1735689600000" + ]; + [ + "1735693323000" + ]; + [ + "1735693323456" + ]; + [ + "1735603200000" + ]; + [ + "1735693323000" + ]; + [ + "1735693323456" + ]; + [ + "1735689600000000" + ]; + [ + "1735693323000000" + ]; + [ + "1735693323456789" + ]; + [ + "1735603200000000" + ]; + [ + "1735693323000000" + ]; + [ + "1735693323456789" + ] + ]; + [ + [ + "53375807" + ]; + [ + "1281019391" + ]; + [ + "76861163519" + ]; + [ + "4611669811199" + ]; + [ + "4611669811199000" + ]; + [ + "4611669811199000000" + ]; + [ + "4291747200" + ]; + [ + "4291747200" + ]; + [ + "4291747200" + ]; + [ + "4291660800" + ]; + [ + "4291747200" + ]; + [ + "4291747200" + ]; + [ + "4291747200000" + ]; + [ + "4291747200000" + ]; + [ + "4291747200000" + ]; + [ + "4291660800000" + ]; + [ + "4291747200000" + ]; + [ + "4291747200000" + ]; + [ + "4291747200000000" + ]; + [ + "4291747200000000" + ]; + [ + "4291747200000000" + ]; + [ + "4291660800000000" + ]; + [ + "4291747200000000" + ]; + [ + "4291747200000000" + ] + ]; + [ + [ + "106751616" + ]; + [ + "2562038807" + ]; + [ + "153722328479" + ]; + [ + "9223339708799" + ]; + [ + "9223339708799000" + ]; + [ + "9223339708799000000" + ]; + [ + "4611669724800" + ]; + [ + "4611669811199" + ]; + [ + "4611669811199" + ]; + [ + "4611669638400" + ]; + [ + "4611669811199" + ]; + [ + "4611669811199" + ]; + [ + "4611669724800000" + ]; + [ + "4611669811199000" + ]; + [ + "4611669811199999" + ]; + [ + "4611669638400000" + ]; + [ + "4611669811199000" + ]; + [ + "4611669811199999" + ]; + [ + "4611669724800000000" + ]; + [ + "4611669811199000000" + ]; + [ + "4611669811199999999" + ]; + [ + "4611669638400000000" + ]; + [ + "4611669811199000000" + ]; + [ + "4611669811199999999" + ] + ] + ] + } + ] + } +]
\ No newline at end of file diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.cfg b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.cfg new file mode 100644 index 0000000000..31260d619b --- /dev/null +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.cfg @@ -0,0 +1 @@ +in plato.Input To.in diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in new file mode 100644 index 0000000000..1097a51534 --- /dev/null +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in @@ -0,0 +1,72 @@ +{ + "fdate32"="-144169-01-01"; + "fdatetime64"="-144169-01-01T00:00:00Z"; + "ftimestamp64"="-144169-01-01T00:00:00.000000Z"; + "ftzdate32"="-144169-01-02,Europe/Moscow"; + "ftzdatetime64"="-144169-01-01T02:30:17,Europe/Moscow"; + "ftztimestamp64"="-144169-01-01T02:30:17.000000,Europe/Moscow"; + "finterval64"="-PT9223339708799S"; +}; +{ + "fdate32"="-1-01-01"; + "fdatetime64"="-1-01-01T23:59:59Z"; + "ftimestamp64"="-1-01-01T23:59:59.999999Z"; + "ftzdate32"="-1-01-01,Europe/Moscow"; + "ftzdatetime64"="-1-01-01T23:59:59,Europe/Moscow"; + "ftztimestamp64"="-1-01-01T23:59:59.999999,Europe/Moscow"; + "finterval64"="-PT4611669897600S"; +}; +{ + "fdate32"="1-01-01"; + "fdatetime64"="1-01-01T00:00:00Z"; + "ftimestamp64"="1-01-01T00:00:00.000000Z"; + "ftzdate32"="1-01-01,Europe/Moscow"; + "ftzdatetime64"="1-01-01T00:00:00,Europe/Moscow"; + "ftztimestamp64"="1-01-01T00:00:00.000000,Europe/Moscow"; + "finterval64"="-P1D"; +}; +{ + "fdate32"="1969-12-31"; + "fdatetime64"="1969-12-31T23:59:59Z"; + "ftimestamp64"="1969-12-31T23:59:59.999999Z"; + "ftzdate32"="1969-12-31,Europe/Moscow"; + "ftzdatetime64"="1969-12-31T23:59:59,Europe/Moscow"; + "ftztimestamp64"="1969-12-31T23:59:59.999999,Europe/Moscow"; + "finterval64"="P1W1DT1H1M1.000001S"; +}; +{ + "fdate32"="1970-01-01"; + "fdatetime64"="1970-01-01T00:00:00Z"; + "ftimestamp64"="1970-01-01T00:00:00.000000Z"; + "ftzdate32"="1970-01-01,Europe/Moscow"; + "ftzdatetime64"="1970-01-01T00:00:00,Europe/Moscow"; + "ftztimestamp64"="1970-01-01T00:00:00.000000,Europe/Moscow"; + "finterval64"="P1D"; +}; +{ + "fdate32"="2025-01-01"; + "fdatetime64"="2025-01-01T01:02:03Z"; + "ftimestamp64"="2025-01-01T01:02:03.456789Z"; + "ftzdate32"="2025-01-01,Europe/Moscow"; + "ftzdatetime64"="2025-01-01T04:02:03,Europe/Moscow"; + "ftztimestamp64"="2025-01-01T04:02:03.456789,Europe/Moscow"; + "finterval64"="P1W2DT3H4M5.678912S"; +}; +{ + "fdate32"="2106-01-01"; + "fdatetime64"="2106-01-01T00:00:00Z"; + "ftimestamp64"="2106-01-01T00:00:00.000000Z"; + "ftzdate32"="2106-01-01,Europe/Moscow"; + "ftzdatetime64"="2106-01-01T03:00:00,Europe/Moscow"; + "ftztimestamp64"="2106-01-01T03:00:00.000000,Europe/Moscow"; + "finterval64"="PT4611669811199S"; +}; +{ + "fdate32"="148107-12-31"; + "fdatetime64"="148107-12-31T23:59:59Z"; + "ftimestamp64"="148107-12-31T23:59:59.999999Z"; + "ftzdate32"="148107-12-31,Europe/Moscow"; + "ftzdatetime64"="148108-01-01T02:59:59,Europe/Moscow"; + "ftztimestamp64"="148108-01-01T02:59:59.999999,Europe/Moscow"; + "finterval64"="PT9223339708799S"; +}; diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in.attr b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in.attr new file mode 100644 index 0000000000..53b63c62f6 --- /dev/null +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.in.attr @@ -0,0 +1,59 @@ +{ + "_yql_row_spec" = { + "Type" = [ + "StructType"; + [ + [ + "fdate32"; + [ + "DataType"; + "String" + ] + ]; + [ + "fdatetime64"; + [ + "DataType"; + "String" + ] + ]; + [ + "ftimestamp64"; + [ + "DataType"; + "String" + ] + ]; + [ + "ftzdate32"; + [ + "DataType"; + "String" + ] + ]; + [ + "ftzdatetime64"; + [ + "DataType"; + "String" + ] + ]; + [ + "ftztimestamp64"; + [ + "DataType"; + "String" + ] + ]; + [ + "finterval64"; + [ + "DataType"; + "String" + ] + ]; + ] + ] + } +} + diff --git a/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.sql b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.sql new file mode 100644 index 0000000000..07c15913d3 --- /dev/null +++ b/yql/essentials/udfs/common/datetime2/test_bigdates/cases/To.sql @@ -0,0 +1,40 @@ +/* syntax version 1 */ +SELECT + DateTime::ToDays(finterval64) as interval64_to_days, + DateTime::ToHours(finterval64) as interval64_to_hours, + DateTime::ToMinutes(finterval64) as interval64_to_minutes, + DateTime::ToSeconds(finterval64) as interval64_to_seconds, + DateTime::ToMilliseconds(finterval64) as interval64_to_msec, + DateTime::ToMicroseconds(finterval64) as interval64_to_usec, + + DateTime::ToSeconds(fdate32) as date32_to_seconds, + DateTime::ToSeconds(fdatetime64) as datetime64_to_seconds, + DateTime::ToSeconds(ftimestamp64) as timestamp64_to_seconds, + DateTime::ToSeconds(ftzdate32) as tzdate32_to_seconds, + DateTime::ToSeconds(ftzdatetime64) as tzdatetime64_to_seconds, + DateTime::ToSeconds(ftztimestamp64) as tztimestamp64_to_seconds, + + DateTime::ToMilliseconds(fdate32) as date32_to_msec, + DateTime::ToMilliseconds(fdatetime64) as datetime64_to_msec, + DateTime::ToMilliseconds(ftimestamp64) as timestamp64_to_msec, + DateTime::ToMilliseconds(ftzdate32) as tzdate32_to_msec, + DateTime::ToMilliseconds(ftzdatetime64) as tzdatetime64_to_msec, + DateTime::ToMilliseconds(ftztimestamp64) as tztimestamp64_to_msec, + + DateTime::ToMicroseconds(fdate32) as date32_to_usec, + DateTime::ToMicroseconds(fdatetime64) as datetime64_to_usec, + DateTime::ToMicroseconds(ftimestamp64) as timestamp64_to_usec, + DateTime::ToMicroseconds(ftzdate32) as tzdate32_to_usec, + DateTime::ToMicroseconds(ftzdatetime64) as tzdatetime64_to_usec, + DateTime::ToMicroseconds(ftztimestamp64) as tztimestamp64_to_usec, +FROM ( + SELECT + CAST(fdate32 as Date32) as fdate32, + CAST(fdatetime64 as Datetime64) as fdatetime64, + CAST(ftimestamp64 as Timestamp64) as ftimestamp64, + CAST(finterval64 as Interval64) as finterval64, + CAST(ftzdate32 as TzDate32) as ftzdate32, + CAST(ftzdatetime64 as TzDatetime64) as ftzdatetime64, + CAST(ftztimestamp64 as TzTimestamp64) as ftztimestamp64, + from Input +); |