aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/mkql_type_ops.h
blob: 68efcb229e1b9b57f8404a5226b9235aa99a2270 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "defs.h"
#include <yql/essentials/public/udf/udf_types.h>
#include <yql/essentials/public/udf/udf_value.h>
#include <yql/essentials/public/udf/udf_type_ops.h>
#include <yql/essentials/public/udf/udf_type_builder.h>

#include <util/stream/output.h>

namespace NKikimr {
namespace NMiniKQL {

//TODO remove
TStringBuf AdaptLegacyYqlType(const TStringBuf& type);

bool IsValidValue(NUdf::EDataSlot type, const NUdf::TUnboxedValuePod& value);

bool IsLeapYear(i32 year);

ui32 GetMonthLength(ui32 month, bool isLeap);

bool IsValidStringValue(NUdf::EDataSlot type, NUdf::TStringRef buf);

NUdf::TUnboxedValuePod ValueFromString(NUdf::EDataSlot type, NUdf::TStringRef buf);
NUdf::TUnboxedValuePod SimpleValueFromYson(NUdf::EDataSlot type, NUdf::TStringRef buf);

NUdf::TUnboxedValuePod ValueToString(NUdf::EDataSlot type, NUdf::TUnboxedValuePod value);

NUdf::TUnboxedValuePod ParseUuid(NUdf::TStringRef buf, bool shortForm=false);
bool ParseUuid(NUdf::TStringRef buf, void* output, bool shortForm=false);

bool IsValidDecimal(NUdf::TStringRef buf);

bool MakeDate(ui32 year, ui32 month, ui32 day, ui16& value);
bool MakeDate32(i32 year, ui32 month, ui32 day, i32& value);
bool MakeTime(ui32 hour, ui32 minute, ui32 second, ui32& value);
bool SplitDate(ui16 value, ui32& year, ui32& month, ui32& day);
bool SplitDate32(i32 value, i32& year, ui32& month, ui32& day);
bool SplitDatetime(ui32 value, ui32& year, ui32& month, ui32& day, ui32& hour, ui32& min, ui32& sec);
bool SplitTimestamp(ui64 value, ui32& year, ui32& month, ui32& day, ui32& hour, ui32& min, ui32& sec, ui32& usec);
bool SplitInterval(i64 value, bool& sign, ui32& day, ui32& hour, ui32& min, ui32& sec, ui32& usec);

bool SplitDate32(i32 date, i32& year, ui32& month, ui32& day,
        ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek);
bool SplitTzDate32(i32 date, i32& year, ui32& month, ui32& day,
        ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek, ui16 tzId);
bool SplitTzDatetime64(i64 value, i32& year, ui32& month, ui32& day, ui32& hour, ui32& min, ui32& sec,
        ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek, ui16 tzId);

bool MakeTzDate32(i32 year, ui32 month, ui32 day, i32& value, ui16 tzId);
bool MakeDatetime64(i32 year, ui32 month, ui32 day, ui32 hour, ui32 min, ui32 sec, i64& value);
bool MakeTzDatetime64(i32 year, ui32 month, ui32 day, ui32 hour, ui32 min, ui32 sec, i64& value, ui16 tzId);

bool SplitTzDate(ui16 value, ui32& year, ui32& month, ui32& day, ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek, ui16 tzId);
bool SplitTzDatetime(ui32 value, ui32& year, ui32& month, ui32& day, ui32& hour, ui32& min, ui32& sec, ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek, ui16 tzId);

bool MakeTzDate(ui32 year, ui32 month, ui32 day, ui16& value, ui16 tzId);
bool MakeTzDatetime(ui32 year, ui32 month, ui32 day, ui32 hour, ui32 min, ui32 sec, ui32& value, ui16 tzId);
bool SplitTzDatetime(ui32 value, ui32& year, ui32& month, ui32& day, ui32& hour, ui32& min, ui32& sec, ui16 tzId);
bool EnrichDate(ui16 date, ui32& dayOfYear, ui32& weekOfYear, ui32& weekOfYearIso8601, ui32& dayOfWeek);
bool GetTimezoneShift(ui32 year, ui32 month, ui32 day, ui32 hour, ui32 min, ui32 sec, ui16 tzId, i32& value);

ui16 InitTimezones();
bool IsValidTimezoneId(ui16 id);
TMaybe<ui16> FindTimezoneId(TStringBuf ianaName);
ui16 GetTimezoneId(TStringBuf ianaName);
TMaybe<TStringBuf> FindTimezoneIANAName(ui16 id);
TStringBuf GetTimezoneIANAName(ui16 id);
std::vector<ui16> GetTzBlackList();

void SerializeTzDate(ui16 date, ui16 tzId, IOutputStream& out);
void SerializeTzDatetime(ui32 datetime, ui16 tzId, IOutputStream& out);
void SerializeTzTimestamp(ui64 timestamp, ui16 tzId, IOutputStream& out);
bool DeserializeTzDate(TStringBuf buf, ui16& date, ui16& tzId);
bool DeserializeTzDatetime(TStringBuf buf, ui32& datetime, ui16& tzId);
bool DeserializeTzTimestamp(TStringBuf buf, ui64& timestamp, ui16& tzId);

void SerializeTzDate32(i32 date, ui16 tzId, IOutputStream& out);
void SerializeTzDatetime64(i64 datetime, ui16 tzId, IOutputStream& out);
void SerializeTzTimestamp64(i64 timestamp, ui16 tzId, IOutputStream& out);
bool DeserializeTzDate32(TStringBuf buf, i32& date, ui16& tzId);
bool DeserializeTzDatetime64(TStringBuf buf, i64& datetime, ui16& tzId);
bool DeserializeTzTimestamp64(TStringBuf buf, i64& timestamp, ui16& tzId);
} // namespace NMiniKQL
} // namespace NKikimr