OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DateTruncate.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef QUERYENGINE_DATETRUNCATE_H
18 #define QUERYENGINE_DATETRUNCATE_H
19 
20 #include <array>
21 #include <cstdint>
22 
23 #include "../Shared/funcannotations.h"
24 #include "ExtractFromTime.h"
25 
26 // DatetruncField must be synced with datetrunc_fname
28  dtYEAR = 0,
46 };
47 
48 constexpr std::array<char const*, dtINVALID> datetrunc_fname_lookup{
49  {"datetrunc_year",
50  "datetrunc_quarter",
51  "datetrunc_month",
52  "datetrunc_day",
53  "datetrunc_hour",
54  "datetrunc_minute",
55  "datetrunc_second", // not used
56  "datetrunc_millisecond", // not used
57  "datetrunc_microsecond", // not used
58  "datetrunc_nanosecond", // not used
59  "datetrunc_millennium",
60  "datetrunc_century",
61  "datetrunc_decade",
62  "datetrunc_week_monday",
63  "datetrunc_week_sunday",
64  "datetrunc_week_saturday",
65  "datetrunc_quarterday"}};
66 
67 // Arithmetic which relies on these enums being consecutive is used elsewhere.
68 static_assert(dtSECOND + 1 == dtMILLISECOND, "Please keep these consecutive.");
69 static_assert(dtMILLISECOND + 1 == dtMICROSECOND, "Please keep these consecutive.");
70 static_assert(dtMICROSECOND + 1 == dtNANOSECOND, "Please keep these consecutive.");
71 
72 DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval);
73 
74 extern "C" RUNTIME_EXPORT DEVICE int64_t
75 DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale);
76 
77 #endif // QUERYENGINE_DATETRUNCATE_H
DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
#define DEVICE
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
DatetruncField
Definition: DateTruncate.h:27
#define RUNTIME_EXPORT
constexpr std::array< char const *, dtINVALID > datetrunc_fname_lookup
Definition: DateTruncate.h:49
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)