diff options
author | batyrkulov <batyrkulov@yandex-team.ru> | 2022-02-10 16:52:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:52:17 +0300 |
commit | 245cfe27068fced78264d40861fffbb325c48b45 (patch) | |
tree | 4794c271293a98db25f118ad0d1c4536b0265f38 | |
parent | e5a19414806c5ec712d5141bb00d350bcac24801 (diff) | |
download | ydb-245cfe27068fced78264d40861fffbb325c48b45.tar.gz |
Restoring authorship annotation for <batyrkulov@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | ydb/library/yql/core/type_ann/type_ann_list.cpp | 32 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_expr_type_annotation.cpp | 16 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_expr_type_annotation.h | 4 | ||||
-rw-r--r-- | ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp | 140 | ||||
-rw-r--r-- | ydb/library/yql/minikql/comp_nodes/ut/mkql_listfromrange_ut.cpp | 774 | ||||
-rw-r--r-- | ydb/library/yql/minikql/comp_nodes/ut/ya.make | 2 | ||||
-rw-r--r-- | ydb/library/yql/minikql/mkql_node.cpp | 20 | ||||
-rw-r--r-- | ydb/library/yql/minikql/mkql_node.h | 4 | ||||
-rw-r--r-- | ydb/library/yql/minikql/mkql_program_builder.cpp | 16 | ||||
-rw-r--r-- | ydb/library/yql/udfs/common/datetime2/datetime_udf.cpp | 272 |
10 files changed, 640 insertions, 640 deletions
diff --git a/ydb/library/yql/core/type_ann/type_ann_list.cpp b/ydb/library/yql/core/type_ann/type_ann_list.cpp index b145cde3893..6384d3bbfb5 100644 --- a/ydb/library/yql/core/type_ann/type_ann_list.cpp +++ b/ydb/library/yql/core/type_ann/type_ann_list.cpp @@ -1909,7 +1909,7 @@ namespace { const auto stepType = input->ChildrenSize() == 2U ? nullptr : input->Tail().GetTypeAnn(); if (stepType && !EnsureDataType(input->Tail().Pos(), *stepType, ctx.Expr)) { - return IGraphTransformer::TStatus::Error; + return IGraphTransformer::TStatus::Error; } const TTypeAnnotationNode* commonType = nullptr; @@ -1919,7 +1919,7 @@ namespace { if (IGraphTransformer::TStatus::Error == status) { ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Child(0U)->Pos()), TStringBuilder() << "Impossible silent convert bound of type " << *input->Child(0U)->GetTypeAnn() << " into " << *stepType)); - } + } return status; } if (const auto status = TrySilentConvertTo(input->ChildRef(1U), *stepType, ctx.Expr); IGraphTransformer::TStatus::Ok != status) { @@ -1953,25 +1953,25 @@ namespace { } else { TExprNode::TPtr value; switch (slot) { - case EDataSlot::Date: - case EDataSlot::TzDate: + case EDataSlot::Date: + case EDataSlot::TzDate: value = ctx.Expr.NewAtom(input->Pos(), "86400000000", TNodeFlags::Default); - break; - case EDataSlot::Datetime: - case EDataSlot::TzDatetime: + break; + case EDataSlot::Datetime: + case EDataSlot::TzDatetime: value = ctx.Expr.NewAtom(input->Pos(), "1000000", TNodeFlags::Default); - break; - default: + break; + default: value = ctx.Expr.NewAtom(input->Pos(), "1", TNodeFlags::Default); - break; - } - + break; + } + auto newChildren = input->ChildrenList(); newChildren.emplace_back(ctx.Expr.NewCallable(input->Pos(), NKikimr::NUdf::GetDataTypeInfo(stepSlot).Name, {std::move(value)})); - output = ctx.Expr.ChangeChildren(*input, std::move(newChildren)); - return IGraphTransformer::TStatus::Repeat; - } - + output = ctx.Expr.ChangeChildren(*input, std::move(newChildren)); + return IGraphTransformer::TStatus::Repeat; + } + input->SetTypeAnn(ctx.Expr.MakeType<TListExprType>(commonType)); return IGraphTransformer::TStatus::Ok; } diff --git a/ydb/library/yql/core/yql_expr_type_annotation.cpp b/ydb/library/yql/core/yql_expr_type_annotation.cpp index f2b793af8d3..e18f4c15de5 100644 --- a/ydb/library/yql/core/yql_expr_type_annotation.cpp +++ b/ydb/library/yql/core/yql_expr_type_annotation.cpp @@ -3425,14 +3425,14 @@ bool IsDataTypeDateOrTzDateOrInterval(EDataSlot dataSlot) { return NUdf::GetDataTypeInfo(dataSlot).Features & (NUdf::DateType | NUdf::TzDateType | NUdf::TimeIntervalType); } -bool IsDataTypeDateOrTzDate(EDataSlot dataSlot) { - return NUdf::GetDataTypeInfo(dataSlot).Features & (NUdf::DateType | NUdf::TzDateType); -} - -bool IsDataTypeInterval(EDataSlot dataSlot) { - return NUdf::GetDataTypeInfo(dataSlot).Features & NUdf::TimeIntervalType; -} - +bool IsDataTypeDateOrTzDate(EDataSlot dataSlot) { + return NUdf::GetDataTypeInfo(dataSlot).Features & (NUdf::DateType | NUdf::TzDateType); +} + +bool IsDataTypeInterval(EDataSlot dataSlot) { + return NUdf::GetDataTypeInfo(dataSlot).Features & NUdf::TimeIntervalType; +} + bool IsDataTypeDate(EDataSlot dataSlot) { return (NUdf::GetDataTypeInfo(dataSlot).Features & NUdf::DateType); } diff --git a/ydb/library/yql/core/yql_expr_type_annotation.h b/ydb/library/yql/core/yql_expr_type_annotation.h index a865aa27cd9..f9a1f27602c 100644 --- a/ydb/library/yql/core/yql_expr_type_annotation.h +++ b/ydb/library/yql/core/yql_expr_type_annotation.h @@ -235,8 +235,8 @@ EDataSlot MakeSigned(EDataSlot dataSlot); EDataSlot MakeUnsigned(EDataSlot dataSlot); bool IsDataTypeDecimal(EDataSlot dataSlot); bool IsDataTypeDateOrTzDateOrInterval(EDataSlot dataSlot); -bool IsDataTypeDateOrTzDate(EDataSlot dataSlot); -bool IsDataTypeInterval(EDataSlot dataSlot); +bool IsDataTypeDateOrTzDate(EDataSlot dataSlot); +bool IsDataTypeInterval(EDataSlot dataSlot); ui8 GetDecimalWidthOfIntegral(EDataSlot dataSlot); TMaybe<ui32> GetDataFixedSize(const TTypeAnnotationNode* typeAnnotation); bool IsFixedSizeData(const TTypeAnnotationNode* typeAnnotation); diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp index 5eeac1ea865..744d5679bac 100644 --- a/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp +++ b/ydb/library/yql/minikql/comp_nodes/mkql_listfromrange.cpp @@ -32,13 +32,13 @@ ui64 GetElementsCount(ui64 start, ui64 end, ui64 step) { } template<typename T, typename TStep> -ui64 GetElementsCount(T start, T end, TStep step) { +ui64 GetElementsCount(T start, T end, TStep step) { ui64 newStart = ShiftByMaxNegative(start); ui64 newEnd = ShiftByMaxNegative(end); ui64 newStep; if (step < 0) { - newStep = (step == std::numeric_limits<TStep>::min()) ? (ui64(std::numeric_limits<TStep>::max()) + 1ul) : ui64(TStep(0) - step); + newStep = (step == std::numeric_limits<TStep>::min()) ? (ui64(std::numeric_limits<TStep>::max()) + 1ul) : ui64(TStep(0) - step); std::swap(newStart, newEnd); } else { newStep = ui64(step); @@ -48,7 +48,7 @@ ui64 GetElementsCount(T start, T end, TStep step) { } template <typename T, typename TStep = std::make_signed_t<T>, std::conditional_t<std::is_floating_point_v<TStep>, i8, TStep> TConstFactor = 1, ui64 TConstLimit = std::numeric_limits<ui64>::max(), bool TzDate = false> -class TListFromRangeWrapper : public TMutableCodegeneratorNode<TListFromRangeWrapper<T, TStep, TConstFactor, TConstLimit, TzDate>> { +class TListFromRangeWrapper : public TMutableCodegeneratorNode<TListFromRangeWrapper<T, TStep, TConstFactor, TConstLimit, TzDate>> { private: using TBaseComputation = TMutableCodegeneratorNode<TListFromRangeWrapper<T, TStep, TConstFactor, TConstLimit, TzDate>>; @@ -60,14 +60,14 @@ private: template <bool Asc> class TIterator<Asc, false> : public TComputationValue<TIterator<Asc, false>> { public: - TIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step) + TIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step) : TComputationValue<TIterator>(memInfo) , Current(start) , Step(step) - , Count(GetElementsCount<T, TStep>(start, end, step)) + , Count(GetElementsCount<T, TStep>(start, end, step)) {} - protected: + protected: bool Skip() final { if (!Count) { return false; @@ -77,7 +77,7 @@ private: return true; } - bool Next(NUdf::TUnboxedValue& value) override { + bool Next(NUdf::TUnboxedValue& value) override { if (!Count) { return false; } @@ -89,14 +89,14 @@ private: } T Current; - const TStep Step; + const TStep Step; ui64 Count; }; template <bool Asc> class TIterator<Asc, true> : public TComputationValue<TIterator<Asc, true>> { public: - TIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step) + TIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step) : TComputationValue<TIterator>(memInfo) , Start(start) , Index(-T(1)) @@ -127,9 +127,9 @@ private: const T Start; T Index; const T Limit; - const TStep Step; + const TStep Step; }; - TValue(TMemoryUsageInfo* memInfo, TComputationContext& ctx, T start, T end, TStep step) + TValue(TMemoryUsageInfo* memInfo, TComputationContext& ctx, T start, T end, TStep step) : TComputationValue<TValue>(memInfo) , Ctx(ctx) , Start(start) @@ -138,11 +138,11 @@ private: { } - protected: - NUdf::TUnboxedValue GetListIterator() const override { - if (Step > TStep(0)) { + protected: + NUdf::TUnboxedValue GetListIterator() const override { + if (Step > TStep(0)) { return Ctx.HolderFactory.template Create<TIterator<true, std::is_floating_point<T>::value>>(Start, End, Step); - } else if (Step < TStep(0)) { + } else if (Step < TStep(0)) { return Ctx.HolderFactory.template Create<TIterator<false, std::is_floating_point<T>::value>>(Start, End, Step); } else { return Ctx.HolderFactory.GetEmptyContainer(); @@ -151,7 +151,7 @@ private: ui64 GetListLength() const final { if (std::is_integral<T>()) { - return GetElementsCount<T, TStep>(Start, End, Step); + return GetElementsCount<T, TStep>(Start, End, Step); } if (Step > T(0) && Start < End) { @@ -172,9 +172,9 @@ private: } bool HasListItems() const final { - if (Step > TStep(0)) { + if (Step > TStep(0)) { return Start < End; - } else if (Step < TStep(0)) { + } else if (Step < TStep(0)) { return Start > End; } else { return false; @@ -188,46 +188,46 @@ private: TComputationContext& Ctx; const T Start; const T End; - const TStep Step; + const TStep Step; }; - class TTzValue : public TValue { - public: - template <bool Asc> - class TTzIterator : public TValue::template TIterator<Asc, false> { - public: - using TBase = typename TValue::template TIterator<Asc, false>; - TTzIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step, ui16 Tz) - : TBase(memInfo, start, end, step) - , TimezoneId(Tz) - {} - bool Next(NUdf::TUnboxedValue& value) final { - if (TBase::Next(value)) { - value.SetTimezoneId(TimezoneId); - return true; - } - return false; - } - private: + class TTzValue : public TValue { + public: + template <bool Asc> + class TTzIterator : public TValue::template TIterator<Asc, false> { + public: + using TBase = typename TValue::template TIterator<Asc, false>; + TTzIterator(TMemoryUsageInfo* memInfo, T start, T end, TStep step, ui16 Tz) + : TBase(memInfo, start, end, step) + , TimezoneId(Tz) + {} + bool Next(NUdf::TUnboxedValue& value) final { + if (TBase::Next(value)) { + value.SetTimezoneId(TimezoneId); + return true; + } + return false; + } + private: const ui16 TimezoneId; - }; - NUdf::TUnboxedValue GetListIterator() const final { - if (TValue::Step > TStep(0)) { - return TValue::Ctx.HolderFactory.template Create<TTzIterator<true>>(TValue::Start, TValue::End, TValue::Step, TimezoneId); - } else if (TValue::Step < TStep(0)) { - return TValue::Ctx.HolderFactory.template Create<TTzIterator<false>>(TValue::Start, TValue::End, TValue::Step, TimezoneId); - } else { - return TValue::Ctx.HolderFactory.GetEmptyContainer(); - } - } - TTzValue(TMemoryUsageInfo* memInfo, TComputationContext& ctx, T start, T end, TStep step, ui16 TimezoneId) - : TimezoneId(TimezoneId) - , TValue(memInfo, ctx, start, end, step) - { - } - private: + }; + NUdf::TUnboxedValue GetListIterator() const final { + if (TValue::Step > TStep(0)) { + return TValue::Ctx.HolderFactory.template Create<TTzIterator<true>>(TValue::Start, TValue::End, TValue::Step, TimezoneId); + } else if (TValue::Step < TStep(0)) { + return TValue::Ctx.HolderFactory.template Create<TTzIterator<false>>(TValue::Start, TValue::End, TValue::Step, TimezoneId); + } else { + return TValue::Ctx.HolderFactory.GetEmptyContainer(); + } + } + TTzValue(TMemoryUsageInfo* memInfo, TComputationContext& ctx, T start, T end, TStep step, ui16 TimezoneId) + : TimezoneId(TimezoneId) + , TValue(memInfo, ctx, start, end, step) + { + } + private: const ui16 TimezoneId; - }; + }; public: TListFromRangeWrapper(TComputationMutables& mutables, IComputationNode* start, IComputationNode* end, IComputationNode* step) : TBaseComputation(mutables, EValueRepresentation::Boxed) @@ -246,13 +246,13 @@ public: else step /= TConstFactor; } - + if constexpr (TzDate) { return MakeList(ctx, start.Get<T>(), end.Get<T>(), step, start.GetTimezoneId()); - } else { + } else { return MakeList(ctx, start.Get<T>(), end.Get<T>(), step, 0U); - } - } + } + } #ifndef MKQL_DISABLE_CODEGEN Value* DoGenerateGetValue(const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen->GetContext(); @@ -340,18 +340,18 @@ IComputationNode* WrapListFromRange(TCallable& callable, const TComputationNodeF return new TListFromRangeWrapper<float, float>(ctx.Mutables, start, end, step); case NUdf::EDataSlot::Double: return new TListFromRangeWrapper<double, double>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::Date: - return new TListFromRangeWrapper<ui16, i64, 86400000000ll, NYql::NUdf::MAX_DATE>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::TzDate: - return new TListFromRangeWrapper<ui16, i64, 86400000000ll, NYql::NUdf::MAX_DATE, true>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::Datetime: - return new TListFromRangeWrapper<ui32, i64, 1000000, NYql::NUdf::MAX_DATETIME>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::TzDatetime: - return new TListFromRangeWrapper<ui32, i64, 1000000, NYql::NUdf::MAX_DATETIME, true>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::Timestamp: - return new TListFromRangeWrapper<ui64, i64, 1, NYql::NUdf::MAX_TIMESTAMP>(ctx.Mutables, start, end, step); - case NUdf::EDataSlot::TzTimestamp: - return new TListFromRangeWrapper<ui64, i64, 1, NYql::NUdf::MAX_TIMESTAMP, true>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::Date: + return new TListFromRangeWrapper<ui16, i64, 86400000000ll, NYql::NUdf::MAX_DATE>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::TzDate: + return new TListFromRangeWrapper<ui16, i64, 86400000000ll, NYql::NUdf::MAX_DATE, true>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::Datetime: + return new TListFromRangeWrapper<ui32, i64, 1000000, NYql::NUdf::MAX_DATETIME>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::TzDatetime: + return new TListFromRangeWrapper<ui32, i64, 1000000, NYql::NUdf::MAX_DATETIME, true>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::Timestamp: + return new TListFromRangeWrapper<ui64, i64, 1, NYql::NUdf::MAX_TIMESTAMP>(ctx.Mutables, start, end, step); + case NUdf::EDataSlot::TzTimestamp: + return new TListFromRangeWrapper<ui64, i64, 1, NYql::NUdf::MAX_TIMESTAMP, true>(ctx.Mutables, start, end, step); case NUdf::EDataSlot::Interval: return new TListFromRangeWrapper<i64, i64, 1, NYql::NUdf::MAX_TIMESTAMP>(ctx.Mutables, start, end, step); default: diff --git a/ydb/library/yql/minikql/comp_nodes/ut/mkql_listfromrange_ut.cpp b/ydb/library/yql/minikql/comp_nodes/ut/mkql_listfromrange_ut.cpp index 1ba1c92bdb0..add9ddc6fbc 100644 --- a/ydb/library/yql/minikql/comp_nodes/ut/mkql_listfromrange_ut.cpp +++ b/ydb/library/yql/minikql/comp_nodes/ut/mkql_listfromrange_ut.cpp @@ -1,449 +1,449 @@ -#include "mkql_computation_node_ut.h" - +#include "mkql_computation_node_ut.h" + #include <ydb/library/yql/minikql/mkql_node_cast.h> #include <ydb/library/yql/minikql/mkql_string_util.h> - - -namespace NKikimr { -namespace NMiniKQL { - -namespace { -template<bool UseLLVM, typename T> -TRuntimeNode MakeList(TSetup<UseLLVM>& setup, T Start, T End, i64 Step, const auto dateType) { - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto start = pb.Unwrap(pb.ToIntegral(pb.NewDataLiteral<T>(Start), dateType), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - - const auto end = pb.Unwrap(pb.ToIntegral(pb.NewDataLiteral<T>(End), dateType), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&Step, sizeof(Step))); + + +namespace NKikimr { +namespace NMiniKQL { + +namespace { +template<bool UseLLVM, typename T> +TRuntimeNode MakeList(TSetup<UseLLVM>& setup, T Start, T End, i64 Step, const auto dateType) { + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto start = pb.Unwrap(pb.ToIntegral(pb.NewDataLiteral<T>(Start), dateType), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + + const auto end = pb.Unwrap(pb.ToIntegral(pb.NewDataLiteral<T>(End), dateType), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&Step, sizeof(Step))); return pb.Collect(pb.ToFlow(pb.ListFromRange(start, end, step))); -} -} - - -Y_UNIT_TEST_SUITE(TMiniKQLListFromRangeTest) { - Y_UNIT_TEST_LLVM(TestCorrectDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 140; - ui16 end = 150; - i64 step = 86400000000LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); +} +} + + +Y_UNIT_TEST_SUITE(TMiniKQLListFromRangeTest) { + Y_UNIT_TEST_LLVM(TestCorrectDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 140; + ui16 end = 150; + i64 step = 86400000000LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), end - start); - NUdf::TUnboxedValue item; - for (size_t i = 0; i < end - start; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start + i); - } - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestCorrectDateReverse) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 150; - ui16 end = 140; - i64 step = -86400000000LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + NUdf::TUnboxedValue item; + for (size_t i = 0; i < end - start; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start + i); + } + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestCorrectDateReverse) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 150; + ui16 end = 140; + i64 step = -86400000000LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), start - end); - NUdf::TUnboxedValue item; - for (int i = 0; i < start - end; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start - i); - } - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestCorrectDatetime) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui32 start = 140; - ui32 end = 150; - i64 step = 1000000LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); - + NUdf::TUnboxedValue item; + for (int i = 0; i < start - end; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start - i); + } + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestCorrectDatetime) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui32 start = 140; + ui32 end = 150; + i64 step = 1000000LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); + const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), end - start); - NUdf::TUnboxedValue item; - for (size_t i = 0; i < end - start; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start + i); - } - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestCorrectTimestamp) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui64 start = 140; - ui64 end = 150; - i64 step = 1LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); - + NUdf::TUnboxedValue item; + for (size_t i = 0; i < end - start; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start + i); + } + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestCorrectTimestamp) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui64 start = 140; + ui64 end = 150; + i64 step = 1LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); + const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), end - start); - NUdf::TUnboxedValue item; - for (size_t i = 0; i < end - start; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start + i); - } - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestWrongIntervalForDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 140; - ui16 end = 150; - i64 step = 86400000001LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + NUdf::TUnboxedValue item; + for (size_t i = 0; i < end - start; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start + i); + } + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestWrongIntervalForDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 140; + ui16 end = 150; + i64 step = 86400000001LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 0); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestWrongIntervalForDatetime) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui32 start = 140; - ui32 end = 150; - i64 step = 1000003LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestWrongIntervalForDatetime) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui32 start = 140; + ui32 end = 150; + i64 step = 1000003LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 0); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestWrongStartType) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto value0 = ui32(1000000); - const auto start = pb.NewDataLiteral<ui32>(value0); - - const auto value1 = ui32(1000005); - const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( - NUdf::TStringRef((const char*)&value1, sizeof(value1))); - - const auto value2 = i64(1000001LL); - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); - } - Y_UNIT_TEST_LLVM(TestWrongEndType) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto value0 = ui32(1000000); - const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( - NUdf::TStringRef((const char*)&value0, sizeof(value0))); - - const auto value1 = ui32(1000005); - const auto end = pb.NewDataLiteral<ui32>(value1); - - const auto value2 = i64(1000001LL); - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); - } - Y_UNIT_TEST_LLVM(TestWrongStepType) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto value0 = ui32(1000000); - const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( - NUdf::TStringRef((const char*)&value0, sizeof(value0))); - - const auto value1 = ui32(1000005); - const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( - NUdf::TStringRef((const char*)&value1, sizeof(value1))); - - const auto value2 = i64(1000001LL); - const auto step = pb.NewDataLiteral<ui32>(value2); - - UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); - } - Y_UNIT_TEST_LLVM(TestEmptyListDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 150; - ui16 end = 144; - i64 step = 86400000000LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestWrongStartType) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto value0 = ui32(1000000); + const auto start = pb.NewDataLiteral<ui32>(value0); + + const auto value1 = ui32(1000005); + const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( + NUdf::TStringRef((const char*)&value1, sizeof(value1))); + + const auto value2 = i64(1000001LL); + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); + } + Y_UNIT_TEST_LLVM(TestWrongEndType) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto value0 = ui32(1000000); + const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( + NUdf::TStringRef((const char*)&value0, sizeof(value0))); + + const auto value1 = ui32(1000005); + const auto end = pb.NewDataLiteral<ui32>(value1); + + const auto value2 = i64(1000001LL); + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); + } + Y_UNIT_TEST_LLVM(TestWrongStepType) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto value0 = ui32(1000000); + const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( + NUdf::TStringRef((const char*)&value0, sizeof(value0))); + + const auto value1 = ui32(1000005); + const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( + NUdf::TStringRef((const char*)&value1, sizeof(value1))); + + const auto value2 = i64(1000001LL); + const auto step = pb.NewDataLiteral<ui32>(value2); + + UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); + } + Y_UNIT_TEST_LLVM(TestEmptyListDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 150; + ui16 end = 144; + i64 step = 86400000000LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 0); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestWrongStartEndTypes) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto value0 = ui16(140); - const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Date>( - NUdf::TStringRef((const char*)&value0, sizeof(value0))); - - const auto value1 = ui32(140 * 60 * 60 * 24 + 5); - const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( - NUdf::TStringRef((const char*)&value1, sizeof(value1))); - - const auto value2 = i64(2000000LL); // 2 Seconds - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); - } - Y_UNIT_TEST_LLVM(TestMinOverflowForDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 4; - ui16 end = 0; - i64 step = -518400000000LL; // -6 days - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestWrongStartEndTypes) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto value0 = ui16(140); + const auto start = pb.NewDataLiteral<NUdf::EDataSlot::Date>( + NUdf::TStringRef((const char*)&value0, sizeof(value0))); + + const auto value1 = ui32(140 * 60 * 60 * 24 + 5); + const auto end = pb.NewDataLiteral<NUdf::EDataSlot::Datetime>( + NUdf::TStringRef((const char*)&value1, sizeof(value1))); + + const auto value2 = i64(2000000LL); // 2 Seconds + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + UNIT_ASSERT_EXCEPTION(pb.ListFromRange(start, end, step), yexception); + } + Y_UNIT_TEST_LLVM(TestMinOverflowForDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 4; + ui16 end = 0; + i64 step = -518400000000LL; // -6 days + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestMinOverflowForDatetime) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui32 start = 9; - ui32 end = 0; - i64 step = -10000000LL; // -10 seconds - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestMinOverflowForDatetime) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui32 start = 9; + ui32 end = 0; + i64 step = -10000000LL; // -10 seconds + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestMinOverflowForTimestamp) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui64 start = 100; - ui64 end = 10; - i64 step = -110LL; // -110 microseconds - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestMinOverflowForTimestamp) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui64 start = 100; + ui64 end = 10; + i64 step = -110LL; // -110 microseconds + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - - Y_UNIT_TEST_LLVM(TestMaxOverflowForDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - ui16 start = 100; - ui16 end = NYql::NUdf::MAX_DATE - 1; - i64 step = (NYql::NUdf::MAX_DATE - 1) * 24LL * 60 * 60 * 1000000; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + + Y_UNIT_TEST_LLVM(TestMaxOverflowForDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + ui16 start = 100; + ui16 end = NYql::NUdf::MAX_DATE - 1; + i64 step = (NYql::NUdf::MAX_DATE - 1) * 24LL * 60 * 60 * 1000000; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestMaxOverflowForDatetime) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - ui32 start = NYql::NUdf::MAX_DATETIME - 123; - ui32 end = NYql::NUdf::MAX_DATETIME - 1; - i64 step = (NYql::NUdf::MAX_DATETIME - 1) * 1000000LL; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestMaxOverflowForDatetime) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + ui32 start = NYql::NUdf::MAX_DATETIME - 123; + ui32 end = NYql::NUdf::MAX_DATETIME - 1; + i64 step = (NYql::NUdf::MAX_DATETIME - 1) * 1000000LL; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestMaxOverflowForTimestamp) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - ui64 start = NYql::NUdf::MAX_TIMESTAMP - 123; - ui64 end = NYql::NUdf::MAX_TIMESTAMP - 1; - i64 step = NYql::NUdf::MAX_TIMESTAMP - 1; - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); - - const auto dates = MakeList(setup, start, end, step, dateType); - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestMaxOverflowForTimestamp) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + ui64 start = NYql::NUdf::MAX_TIMESTAMP - 123; + ui64 end = NYql::NUdf::MAX_TIMESTAMP - 1; + i64 step = NYql::NUdf::MAX_TIMESTAMP - 1; + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); + + const auto dates = MakeList(setup, start, end, step, dateType); + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); - NUdf::TUnboxedValue item; + NUdf::TUnboxedValue item; UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 1); - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start); - UNIT_ASSERT(!iterator.Next(item)); - } - Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - const auto canada = pb.NewDataLiteral<ui16>(375U); - const auto europe = pb.NewDataLiteral<ui16>(459U); - const auto value2 = i64(24LL * 60 * 60 * 1000000); // 1 Day - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123), dateType); - const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123 + 5), dateType); - const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto date2 = pb.Unwrap(pb.AddTimezone(day2, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto dates = pb.ListFromRange(date1, date2, step); - - const auto graph = setup.BuildGraph(dates); + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), start); + UNIT_ASSERT(!iterator.Next(item)); + } + Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + const auto canada = pb.NewDataLiteral<ui16>(375U); + const auto europe = pb.NewDataLiteral<ui16>(459U); + const auto value2 = i64(24LL * 60 * 60 * 1000000); // 1 Day + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123), dateType); + const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123 + 5), dateType); + const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto date2 = pb.Unwrap(pb.AddTimezone(day2, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto dates = pb.ListFromRange(date1, date2, step); + + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 5); - NUdf::TUnboxedValue item; - for (size_t i = 123; i < 123 + 5; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), i); - UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); - } - } - Y_UNIT_TEST_LLVM(TestSameTimezonesForTzDate) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); - const auto canada = pb.NewDataLiteral<ui16>(375U); - const auto value2 = i64(24LL * 60 * 60 * 1000000); // 1 Day - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123), dateType); - const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123 + 5), dateType); - const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto date2 = pb.Unwrap(pb.AddTimezone(day2, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto dates = pb.ListFromRange(date1, date2, step); - - const auto graph = setup.BuildGraph(dates); + NUdf::TUnboxedValue item; + for (size_t i = 123; i < 123 + 5; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), i); + UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); + } + } + Y_UNIT_TEST_LLVM(TestSameTimezonesForTzDate) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Date, true); + const auto canada = pb.NewDataLiteral<ui16>(375U); + const auto value2 = i64(24LL * 60 * 60 * 1000000); // 1 Day + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123), dateType); + const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui16>(123 + 5), dateType); + const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto date2 = pb.Unwrap(pb.AddTimezone(day2, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto dates = pb.ListFromRange(date1, date2, step); + + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 5); - NUdf::TUnboxedValue item; - for (size_t i = 123; i < 123 + 5; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), i); - UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); - } - } - Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzDatetime) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); - const auto canada = pb.NewDataLiteral<ui16>(375U); - const auto europe = pb.NewDataLiteral<ui16>(459U); - const auto value2 = i64(1000000LL); // 1 Second - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui32>(123), dateType); - const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui32>(123 + 5), dateType); - const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto date2 = pb.Unwrap(pb.AddTimezone(day2, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto dates = pb.ListFromRange(date1, date2, step); - - const auto graph = setup.BuildGraph(dates); + NUdf::TUnboxedValue item; + for (size_t i = 123; i < 123 + 5; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui16>(), i); + UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); + } + } + Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzDatetime) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Datetime, true); + const auto canada = pb.NewDataLiteral<ui16>(375U); + const auto europe = pb.NewDataLiteral<ui16>(459U); + const auto value2 = i64(1000000LL); // 1 Second + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui32>(123), dateType); + const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui32>(123 + 5), dateType); + const auto date1 = pb.Unwrap(pb.AddTimezone(day1, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto date2 = pb.Unwrap(pb.AddTimezone(day2, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto dates = pb.ListFromRange(date1, date2, step); + + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 5); - NUdf::TUnboxedValue item; - for (size_t i = 123; i < 123 + 5; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), i); - UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); - } - } - Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzTimestamp) { - TSetup<LLVM> setup; - TProgramBuilder& pb = *setup.PgmBuilder; - - const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); - const auto europe = pb.NewDataLiteral<ui16>(459U); - const auto canada = pb.NewDataLiteral<ui16>(375U); - const auto value2 = i64(1LL); // 1 Microsecond - const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( - NUdf::TStringRef((const char*)&value2, sizeof(value2))); - - const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui64>(123), dateType); - const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui64>(123 + 5), dateType); - const auto date1 = pb.Unwrap(pb.AddTimezone(day1, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto date2 = pb.Unwrap(pb.AddTimezone(day2, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); - const auto dates = pb.ListFromRange(date1, date2, step); - - const auto graph = setup.BuildGraph(dates); + NUdf::TUnboxedValue item; + for (size_t i = 123; i < 123 + 5; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui32>(), i); + UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 375U); + } + } + Y_UNIT_TEST_LLVM(TestDifferentTimezonesForTzTimestamp) { + TSetup<LLVM> setup; + TProgramBuilder& pb = *setup.PgmBuilder; + + const auto dateType = pb.NewDataType(NUdf::EDataSlot::Timestamp, true); + const auto europe = pb.NewDataLiteral<ui16>(459U); + const auto canada = pb.NewDataLiteral<ui16>(375U); + const auto value2 = i64(1LL); // 1 Microsecond + const auto step = pb.NewDataLiteral<NUdf::EDataSlot::Interval>( + NUdf::TStringRef((const char*)&value2, sizeof(value2))); + + const auto day1 = pb.ToIntegral(pb.NewDataLiteral<ui64>(123), dateType); + const auto day2 = pb.ToIntegral(pb.NewDataLiteral<ui64>(123 + 5), dateType); + const auto date1 = pb.Unwrap(pb.AddTimezone(day1, europe), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto date2 = pb.Unwrap(pb.AddTimezone(day2, canada), pb.NewDataLiteral<NUdf::EDataSlot::String>(""), "", 0, 0); + const auto dates = pb.ListFromRange(date1, date2, step); + + const auto graph = setup.BuildGraph(dates); const auto list = graph->GetValue(); const auto iterator = list.GetListIterator(); UNIT_ASSERT_VALUES_EQUAL(list.GetListLength(), 5); - NUdf::TUnboxedValue item; - for (size_t i = 123; i < 123 + 5; i++) { - UNIT_ASSERT(iterator.Next(item)); - UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), i); - UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 459U); - } - } + NUdf::TUnboxedValue item; + for (size_t i = 123; i < 123 + 5; i++) { + UNIT_ASSERT(iterator.Next(item)); + UNIT_ASSERT_VALUES_EQUAL(item.template Get<ui64>(), i); + UNIT_ASSERT_VALUES_EQUAL(item.GetTimezoneId(), 459U); + } + } Y_UNIT_TEST_LLVM(TestResverseUnsignedShorts) { TSetup<LLVM> setup; @@ -464,6 +464,6 @@ Y_UNIT_TEST_SUITE(TMiniKQLListFromRangeTest) { UNIT_ASSERT_VALUES_EQUAL(list.GetElement(3U).template Get<ui16>(), 59994U); UNIT_ASSERT_VALUES_EQUAL(list.GetElement(4U).template Get<ui16>(), 59992U); } -} -} +} +} } diff --git a/ydb/library/yql/minikql/comp_nodes/ut/ya.make b/ydb/library/yql/minikql/comp_nodes/ut/ya.make index dffda1318f3..571facba377 100644 --- a/ydb/library/yql/minikql/comp_nodes/ut/ya.make +++ b/ydb/library/yql/minikql/comp_nodes/ut/ya.make @@ -51,7 +51,7 @@ SRCS( mkql_wide_filter_ut.cpp mkql_wide_map_ut.cpp mkql_wide_nodes_ut.cpp - mkql_listfromrange_ut.cpp + mkql_listfromrange_ut.cpp ) PEERDIR( diff --git a/ydb/library/yql/minikql/mkql_node.cpp b/ydb/library/yql/minikql/mkql_node.cpp index 4c6f3e45ad4..66470c6a88a 100644 --- a/ydb/library/yql/minikql/mkql_node.cpp +++ b/ydb/library/yql/minikql/mkql_node.cpp @@ -2195,16 +2195,16 @@ bool IsDateType(NUdf::TDataTypeId typeId) { return slot && NUdf::GetDataTypeInfo(*slot).Features & NUdf::DateType && *slot != NUdf::EDataSlot::Interval; } -bool IsTzDateType(NUdf::TDataTypeId typeId) { - auto slot = NUdf::FindDataSlot(typeId); - return slot && NUdf::GetDataTypeInfo(*slot).Features & NUdf::TzDateType && *slot != NUdf::EDataSlot::Interval; -} - -bool IsIntervalType(NUdf::TDataTypeId typeId) { - auto slot = NUdf::FindDataSlot(typeId); - return slot && NUdf::GetDataTypeInfo(*slot).Features & NUdf::TimeIntervalType; -} - +bool IsTzDateType(NUdf::TDataTypeId typeId) { + auto slot = NUdf::FindDataSlot(typeId); + return slot && NUdf::GetDataTypeInfo(*slot).Features & NUdf::TzDateType && *slot != NUdf::EDataSlot::Interval; +} + +bool IsIntervalType(NUdf::TDataTypeId typeId) { + auto slot = NUdf::FindDataSlot(typeId); + return slot && NUdf::GetDataTypeInfo(*slot).Features & NUdf::TimeIntervalType; +} + EValueRepresentation GetValueRepresentation(NUdf::TDataTypeId type) { switch (type) { #define CASE_FOR(type, layout) \ diff --git a/ydb/library/yql/minikql/mkql_node.h b/ydb/library/yql/minikql/mkql_node.h index ee74455ea69..5d38797b8b2 100644 --- a/ydb/library/yql/minikql/mkql_node.h +++ b/ydb/library/yql/minikql/mkql_node.h @@ -1370,8 +1370,8 @@ inline TType* TRuntimeNode::GetRuntimeType() const { bool IsNumericType(NUdf::TDataTypeId typeId); bool IsCommonStringType(NUdf::TDataTypeId typeId); bool IsDateType(NUdf::TDataTypeId typeId); -bool IsTzDateType(NUdf::TDataTypeId typeId); -bool IsIntervalType(NUdf::TDataTypeId typeId); +bool IsTzDateType(NUdf::TDataTypeId typeId); +bool IsIntervalType(NUdf::TDataTypeId typeId); enum class EValueRepresentation { Embedded = 0, diff --git a/ydb/library/yql/minikql/mkql_program_builder.cpp b/ydb/library/yql/minikql/mkql_program_builder.cpp index 47ae6e4c8fc..887db594404 100644 --- a/ydb/library/yql/minikql/mkql_program_builder.cpp +++ b/ydb/library/yql/minikql/mkql_program_builder.cpp @@ -1433,22 +1433,22 @@ TRuntimeNode TProgramBuilder::BlockAdd(TRuntimeNode arg1, TRuntimeNode arg2) { TRuntimeNode TProgramBuilder::ListFromRange(TRuntimeNode start, TRuntimeNode end, TRuntimeNode step) { MKQL_ENSURE(start.GetStaticType()->IsData(), "Expected data"); MKQL_ENSURE(end.GetStaticType()->IsSameType(*start.GetStaticType()), "Mismatch type"); - - if constexpr (RuntimeVersion < 24U) { - MKQL_ENSURE(IsNumericType(AS_TYPE(TDataType, start)->GetSchemeType()), "Expected numeric"); - } else { + + if constexpr (RuntimeVersion < 24U) { + MKQL_ENSURE(IsNumericType(AS_TYPE(TDataType, start)->GetSchemeType()), "Expected numeric"); + } else { MKQL_ENSURE(IsNumericType(AS_TYPE(TDataType, start)->GetSchemeType()) || IsDateType(AS_TYPE(TDataType, start)->GetSchemeType()) || IsTzDateType(AS_TYPE(TDataType, start)->GetSchemeType()) || IsIntervalType(AS_TYPE(TDataType, start)->GetSchemeType()), - "Expected numeric, date or tzdate"); + "Expected numeric, date or tzdate"); if (IsNumericType(AS_TYPE(TDataType, start)->GetSchemeType())) { MKQL_ENSURE(IsNumericType(AS_TYPE(TDataType, step)->GetSchemeType()), "Expected numeric"); } else { - MKQL_ENSURE(IsIntervalType(AS_TYPE(TDataType, step)->GetSchemeType()), "Expected interval"); - } - } + MKQL_ENSURE(IsIntervalType(AS_TYPE(TDataType, step)->GetSchemeType()), "Expected interval"); + } + } TCallableBuilder callableBuilder(Env, __func__, TListType::Create(start.GetStaticType(), Env)); callableBuilder.Add(start); diff --git a/ydb/library/yql/udfs/common/datetime2/datetime_udf.cpp b/ydb/library/yql/udfs/common/datetime2/datetime_udf.cpp index 763fea8024f..eedc50cd183 100644 --- a/ydb/library/yql/udfs/common/datetime2/datetime_udf.cpp +++ b/ydb/library/yql/udfs/common/datetime2/datetime_udf.cpp @@ -220,64 +220,64 @@ namespace { return timezoneId < zones.size() && !zones[timezoneId].empty(); } - inline bool ValidateMonthShortName(const std::string_view& monthName, ui8& month) { + inline bool ValidateMonthShortName(const std::string_view& monthName, ui8& month) { static constexpr auto cmp = [](const std::string_view& a, const std::string_view& b) { - int cmp = strnicmp(a.data(), b.data(), std::min(a.size(), b.size())); - if (cmp == 0) - return a.size() < b.size(); - return cmp < 0; - }; - static const std::map<std::string_view, ui8, decltype(cmp)> mp = { - {"jan", 1}, - {"feb", 2}, - {"mar", 3}, - {"apr", 4}, - {"may", 5}, - {"jun", 6}, - {"jul", 7}, - {"aug", 8}, - {"sep", 9}, - {"oct", 10}, - {"nov", 11}, - {"dec", 12} - }; - const auto& it = mp.find(monthName); - if (it != mp.end()) { - month = it -> second; - return true; - } - return false; - } - - inline bool ValidateMonthFullName(const std::string_view& monthName, ui8& month) { + int cmp = strnicmp(a.data(), b.data(), std::min(a.size(), b.size())); + if (cmp == 0) + return a.size() < b.size(); + return cmp < 0; + }; + static const std::map<std::string_view, ui8, decltype(cmp)> mp = { + {"jan", 1}, + {"feb", 2}, + {"mar", 3}, + {"apr", 4}, + {"may", 5}, + {"jun", 6}, + {"jul", 7}, + {"aug", 8}, + {"sep", 9}, + {"oct", 10}, + {"nov", 11}, + {"dec", 12} + }; + const auto& it = mp.find(monthName); + if (it != mp.end()) { + month = it -> second; + return true; + } + return false; + } + + inline bool ValidateMonthFullName(const std::string_view& monthName, ui8& month) { static constexpr auto cmp = [](const std::string_view& a, const std::string_view& b) { - int cmp = strnicmp(a.data(), b.data(), std::min(a.size(), b.size())); - if (cmp == 0) - return a.size() < b.size(); - return cmp < 0; - }; - static const std::map<std::string_view, ui8, decltype(cmp)> mp = { - {"january", 1}, - {"february", 2}, - {"march", 3}, - {"april", 4}, - {"may", 5}, - {"june", 6}, - {"july", 7}, - {"august", 8}, - {"september", 9}, - {"october", 10}, - {"november", 11}, - {"december", 12} - }; - const auto& it = mp.find(monthName); - if (it != mp.end()) { - month = it -> second; - return true; - } - return false; - } - + int cmp = strnicmp(a.data(), b.data(), std::min(a.size(), b.size())); + if (cmp == 0) + return a.size() < b.size(); + return cmp < 0; + }; + static const std::map<std::string_view, ui8, decltype(cmp)> mp = { + {"january", 1}, + {"february", 2}, + {"march", 3}, + {"april", 4}, + {"may", 5}, + {"june", 6}, + {"july", 7}, + {"august", 8}, + {"september", 9}, + {"october", 10}, + {"november", 11}, + {"december", 12} + }; + const auto& it = mp.find(monthName); + if (it != mp.end()) { + month = it -> second; + return true; + } + return false; + } + inline bool ValidateDatetime(ui32 datetime) { return datetime < MAX_DATETIME; } @@ -1233,56 +1233,56 @@ namespace { }); ReservedSize_ += MAX_TIMEZONE_NAME_LEN; break; - case 'b': { - static constexpr size_t size = 3; - Printers_.emplace_back([](char* out, const TUnboxedValuePod& value, const IDateBuilder&) { - static constexpr std::string_view mp[] { - "Jan", - "Feb", + case 'b': { + static constexpr size_t size = 3; + Printers_.emplace_back([](char* out, const TUnboxedValuePod& value, const IDateBuilder&) { + static constexpr std::string_view mp[] { + "Jan", + "Feb", "Mar", "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec" - }; + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" + }; auto month = GetMonth(value); Y_ENSURE(month > 0 && month <= sizeof(mp) / sizeof(mp[0]), "Invalid month value"); std::memcpy(out, mp[month - 1].data(), size); - return size; - }); - ReservedSize_ += size; - break; - } - case 'B': { - Printers_.emplace_back([](char* out, const TUnboxedValuePod& value, const IDateBuilder&) { - static constexpr std::string_view mp[] { - "January", - "February", + return size; + }); + ReservedSize_ += size; + break; + } + case 'B': { + Printers_.emplace_back([](char* out, const TUnboxedValuePod& value, const IDateBuilder&) { + static constexpr std::string_view mp[] { + "January", + "February", "March", "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December" - }; + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + }; auto month = GetMonth(value); Y_ENSURE(month > 0 && month <= sizeof(mp) / sizeof(mp[0]), "Invalid month value"); const std::string_view monthFullName = mp[month - 1]; - std::memcpy(out, monthFullName.data(), monthFullName.size()); - return monthFullName.size(); - }); - ReservedSize_ += 9U; // MAX_MONTH_FULL_NAME_LEN - break; - } + std::memcpy(out, monthFullName.data(), monthFullName.size()); + return monthFullName.size(); + }); + ReservedSize_ += 9U; // MAX_MONTH_FULL_NAME_LEN + break; + } default: ythrow yexception() << "invalid format character: " << *ptr; } @@ -1567,46 +1567,46 @@ namespace { return true; }); break; - case 'b': { - static constexpr size_t size = 3; - Scanners_.emplace_back([](std::string_view::const_iterator& it, size_t limit, TUnboxedValuePod& result, const IDateBuilder&) { - const auto start = it; - size_t cnt = 0U; - while (limit > 0 && cnt < size && std::isalpha(*it)) { - ++it; - ++cnt; - --limit; - } - const std::string_view monthName{start, cnt}; - ui8 month = 0U; - if (cnt < size || !ValidateMonthShortName(monthName, month)) { - return false; - } - SetMonth(result, month); - return true; - }); - break; - } - case 'B': { - Scanners_.emplace_back([](std::string_view::const_iterator& it, size_t limit, TUnboxedValuePod& result, const IDateBuilder&) { - const auto start = it; - size_t cnt = 0U; - while (limit > 0 && std::isalpha(*it)) { - ++it; - ++cnt; - --limit; - } - - const std::string_view monthName{start, cnt}; - ui8 month = 0U; - if (cnt < 4 || !ValidateMonthFullName(monthName, month)) { - return false; - } - SetMonth(result, month); - return true; - }); - break; - } + case 'b': { + static constexpr size_t size = 3; + Scanners_.emplace_back([](std::string_view::const_iterator& it, size_t limit, TUnboxedValuePod& result, const IDateBuilder&) { + const auto start = it; + size_t cnt = 0U; + while (limit > 0 && cnt < size && std::isalpha(*it)) { + ++it; + ++cnt; + --limit; + } + const std::string_view monthName{start, cnt}; + ui8 month = 0U; + if (cnt < size || !ValidateMonthShortName(monthName, month)) { + return false; + } + SetMonth(result, month); + return true; + }); + break; + } + case 'B': { + Scanners_.emplace_back([](std::string_view::const_iterator& it, size_t limit, TUnboxedValuePod& result, const IDateBuilder&) { + const auto start = it; + size_t cnt = 0U; + while (limit > 0 && std::isalpha(*it)) { + ++it; + ++cnt; + --limit; + } + + const std::string_view monthName{start, cnt}; + ui8 month = 0U; + if (cnt < 4 || !ValidateMonthFullName(monthName, month)) { + return false; + } + SetMonth(result, month); + return true; + }); + break; + } default: ythrow yexception() << "invalid format character: " << *ptr; } |