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
63 lines (49 loc) · 1.6 KB
/
Copy pathDataTypeTime64.cpp
File metadata and controls
63 lines (49 loc) · 1.6 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
#include <string>
#include <DataTypes/DataTypeTime64.h>
#include <DataTypes/Serializations/SerializationTime64.h>
#include <IO/Operators.h>
#include <IO/WriteBufferFromString.h>
#include <Common/Exception.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int BAD_ARGUMENTS;
}
static constexpr UInt32 TIME64_MAX_SCALE = 9;
DataTypeTime64::DataTypeTime64(UInt32 scale_)
: DataTypeDecimalBase<Time64>(DecimalUtils::max_precision<Time64>, scale_)
{
if (scale_ > TIME64_MAX_SCALE)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "DataTypeTime64 scale {} is too large, maximum is {}", scale_, TIME64_MAX_SCALE);
}
std::string DataTypeTime64::doGetName() const
{
return std::string(getFamilyName()) + "(" + std::to_string(this->scale) + ")";
}
void DataTypeTime64::updateHashImpl(SipHash & hash) const
{
hash.update(this->scale);
}
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::doGetSerialization(const SerializationInfoSettings &) const
{
return SerializationTime64::create(scale, *this);
}
const DateLUTImpl & DataTypeTime64::getTimeZone() const
{
return DateLUT::instance();
}
std::string getTimeTimezone(const IDataType & data_type)
{
if (typeid_cast<const DataTypeTime *>(&data_type) || typeid_cast<const DataTypeTime64 *>(&data_type))
return std::string();
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot get time zone from type {}", data_type.getName());
}
}