ClickHouse/dbms/src/Core/toField.h

38 lines
655 B
C++
Raw Normal View History

#pragma once
2017-04-16 05:40:17 +00:00
#include <common/MetrikaTypes.h>
#include <common/LocalDate.h>
#include <common/LocalDateTime.h>
#include <Core/Field.h>
2017-04-16 05:40:17 +00:00
/// This is for Yandex.Metrica code.
namespace DB
{
2017-04-30 13:50:16 +00:00
/// Transform anything to Field.
template <typename T>
inline Field toField(const T & x)
{
return Field(typename NearestFieldType<T>::Type(x));
}
inline Field toField(const LocalDate & x)
{
return toField(static_cast<UInt16>(x.getDayNum()));
}
inline Field toField(const LocalDateTime & x)
{
return toField(static_cast<UInt32>(static_cast<time_t>(x)));
}
inline Field toField(const VisitID_t & x)
{
return toField(static_cast<UInt64>(x));
}
}