forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypeTime64.cpp
More file actions
76 lines (62 loc) · 2.43 KB
/
DataTypeTime64.cpp
File metadata and controls
76 lines (62 loc) · 2.43 KB
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
#include <DataTypes/DataTypeTime64.h>
#include <DataTypes/Serializations/SerializationTime64.h>
#include <IO/Operators.h>
#include <IO/WriteBufferFromString.h>
#include <string>
namespace DB
{
namespace ErrorCodes
{
extern const int ARGUMENT_OUT_OF_BOUND;
extern const int LOGICAL_ERROR;
}
static constexpr UInt32 max_scale = 9;
DataTypeTime64::DataTypeTime64(UInt32 scale_, const std::string & time_zone_name)
: DataTypeDecimalBase<Time64>(DecimalUtils::max_precision<Time64>, scale_),
TimezoneMixin(time_zone_name)
{
if (scale > max_scale)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Scale {} is too large for Time64. "
"Maximum is up to nanoseconds (9).", std::to_string(scale));
}
DataTypeTime64::DataTypeTime64(UInt32 scale_, const TimezoneMixin & time_zone_info)
: DataTypeDecimalBase<Time64>(DecimalUtils::max_precision<Time64>, scale_),
TimezoneMixin(time_zone_info)
{
if (scale > max_scale)
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND, "Scale {} is too large for Time64. "
"Maximum is up to nanoseconds (9).", std::to_string(scale));
}
void DataTypeTime64::updateHashImpl(SipHash & hash) const
{
hash.update(has_explicit_time_zone);
if (has_explicit_time_zone)
hash.update(time_zone.getTimeZone());
}
std::string DataTypeTime64::doGetName() const
{
if (!has_explicit_time_zone)
return std::string(getFamilyName()) + "(" + std::to_string(this->scale) + ")";
WriteBufferFromOwnString out;
out << "Time64(" << this->scale << ", " << quote << time_zone.getTimeZone() << ")";
return out.str();
}
bool DataTypeTime64::equals(const IDataType & rhs) const
{
if (const auto * ptype = typeid_cast<const DataTypeTime64 *>(&rhs))
return this->scale == ptype->getScale();
return false;
}
SerializationPtr DataTypeTime64::doGetDefaultSerialization() const
{
return std::make_shared<SerializationTime64>(scale, *this);
}
std::string getTimeTimezone(const IDataType & data_type)
{
if (const auto * type = typeid_cast<const DataTypeTime *>(&data_type))
return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string();
if (const auto * type = typeid_cast<const DataTypeTime64 *>(&data_type))
return type->hasExplicitTimeZone() ? type->getTimeZone().getTimeZone() : std::string();
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot get time zone from type {}", data_type.getName());
}
}