dbms: development [#CONV-2944].

This commit is contained in:
Alexey Milovidov 2011-08-15 00:55:43 +00:00
parent 47453e759f
commit dbe5dda339
6 changed files with 116 additions and 27 deletions

View File

@ -57,6 +57,7 @@ namespace ErrorCodes
UNKNOWN_IDENTIFIER,
NOT_IMPLEMENTED,
LOGICAL_ERROR,
UNKNOWN_TYPE,
};
}

View File

@ -20,14 +20,14 @@ public:
void serializeText(const Field & field, WriteBuffer & ostr) const
{
writeDateText(boost::get<UInt64>(field), ostr);
writeDateText(Yandex::DayNum_t(boost::get<UInt64>(field)), ostr);
}
void deserializeText(Field & field, ReadBuffer & istr) const
{
Yandex::DayNum_t x;
readDateText(x, istr);
field = x;
field = static_cast<UInt64>(x);
}
void serializeTextEscaped(const Field & field, WriteBuffer & ostr) const

View File

@ -0,0 +1,33 @@
#pragma once
#include <Poco/RegularExpression.h>
#include <DB/DataTypes/DataTypesNumberFixed.h>
#include <DB/DataTypes/DataTypesNumberVariable.h>
#include <DB/DataTypes/DataTypeDate.h>
#include <DB/DataTypes/DataTypeDateTime.h>
#include <DB/DataTypes/DataTypeString.h>
#include <DB/DataTypes/DataTypeFixedString.h>
namespace DB
{
/** Позволяет создать тип данных по его имени.
*/
class DataTypeFactory
{
public:
DataTypeFactory();
DataTypePtr get(const String & name);
private:
typedef std::map<String, DataTypePtr> NonParametricDataTypes;
NonParametricDataTypes non_parametric_data_types;
Poco::RegularExpression fixed_string_regexp;
};
}

View File

@ -14,10 +14,12 @@ namespace DB
/** Реализует часть интерфейса IDataType, общую для всяких чисел
* - ввод и вывод в текстовом виде.
*/
template <typename FieldType>
template <typename FType>
class IDataTypeNumber : public IDataType
{
public:
typedef FType FieldType;
void serializeText(const Field & field, WriteBuffer & ostr) const
{
writeText(boost::get<typename NearestFieldType<FieldType>::Type>(field), ostr);

View File

@ -3,6 +3,7 @@
#include <Poco/NumberFormatter.h>
#include <DB/DataTypes/DataTypesNumberFixed.h>
#include <DB/DataTypes/DataTypesNumberVariable.h>
#include <DB/Functions/IFunction.h>
#include <DB/Functions/NumberTraits.h>
@ -12,7 +13,7 @@ namespace DB
/** Арифметические функции: +, -, *, /, %,
* div (целочисленное деление),
* TODO: <<, >>, <<<, >>>, &, |, ^, &&, ||, ^^, !
* TODO: <<, >>, <<<, >>>, &, |, ^, ~
*/
template<typename A, typename B>
@ -215,9 +216,10 @@ private:
template <typename T0, typename T1>
bool checkRightType(const DataTypes & arguments, DataTypes & types_res) const
{
if (dynamic_cast<const typename DataTypeFromFieldType<T1>::Type *>(&*arguments[1]))
if (dynamic_cast<const T1 *>(&*arguments[1]))
{
types_res.push_back(new typename DataTypeFromFieldType<typename Impl<T0, T1>::ResultType>::Type);
types_res.push_back(new typename DataTypeFromFieldType<
typename Impl<typename T0::FieldType, typename T1::FieldType>::ResultType>::Type);
return true;
}
return false;
@ -226,18 +228,20 @@ private:
template <typename T0>
bool checkLeftType(const DataTypes & arguments, DataTypes & types_res) const
{
if (dynamic_cast<const typename DataTypeFromFieldType<T0>::Type *>(&*arguments[0]))
if (dynamic_cast<const T0 *>(&*arguments[0]))
{
if ( checkRightType<T0, UInt8>(arguments, types_res)
|| checkRightType<T0, UInt16>(arguments, types_res)
|| checkRightType<T0, UInt32>(arguments, types_res)
|| checkRightType<T0, UInt64>(arguments, types_res)
|| checkRightType<T0, Int8>(arguments, types_res)
|| checkRightType<T0, Int16>(arguments, types_res)
|| checkRightType<T0, Int32>(arguments, types_res)
|| checkRightType<T0, Int64>(arguments, types_res)
|| checkRightType<T0, Float32>(arguments, types_res)
|| checkRightType<T0, Float64>(arguments, types_res))
if ( checkRightType<T0, DataTypeUInt8>(arguments, types_res)
|| checkRightType<T0, DataTypeUInt16>(arguments, types_res)
|| checkRightType<T0, DataTypeUInt32>(arguments, types_res)
|| checkRightType<T0, DataTypeUInt64>(arguments, types_res)
|| checkRightType<T0, DataTypeInt8>(arguments, types_res)
|| checkRightType<T0, DataTypeInt16>(arguments, types_res)
|| checkRightType<T0, DataTypeInt32>(arguments, types_res)
|| checkRightType<T0, DataTypeInt64>(arguments, types_res)
|| checkRightType<T0, DataTypeFloat32>(arguments, types_res)
|| checkRightType<T0, DataTypeFloat64>(arguments, types_res)
|| checkRightType<T0, DataTypeVarUInt>(arguments, types_res)
|| checkRightType<T0, DataTypeVarInt>(arguments, types_res))
return true;
else
throw Exception("Illegal type " + arguments[1]->getName() + " of second argument of function " + getName(),
@ -370,16 +374,18 @@ public:
DataTypes types_res;
if (!( checkLeftType<UInt8>(arguments, types_res)
|| checkLeftType<UInt16>(arguments, types_res)
|| checkLeftType<UInt32>(arguments, types_res)
|| checkLeftType<UInt64>(arguments, types_res)
|| checkLeftType<Int8>(arguments, types_res)
|| checkLeftType<Int16>(arguments, types_res)
|| checkLeftType<Int32>(arguments, types_res)
|| checkLeftType<Int64>(arguments, types_res)
|| checkLeftType<Float32>(arguments, types_res)
|| checkLeftType<Float64>(arguments, types_res)))
if (!( checkLeftType<DataTypeUInt8>(arguments, types_res)
|| checkLeftType<DataTypeUInt16>(arguments, types_res)
|| checkLeftType<DataTypeUInt32>(arguments, types_res)
|| checkLeftType<DataTypeUInt64>(arguments, types_res)
|| checkLeftType<DataTypeInt8>(arguments, types_res)
|| checkLeftType<DataTypeInt16>(arguments, types_res)
|| checkLeftType<DataTypeInt32>(arguments, types_res)
|| checkLeftType<DataTypeInt64>(arguments, types_res)
|| checkLeftType<DataTypeFloat32>(arguments, types_res)
|| checkLeftType<DataTypeFloat64>(arguments, types_res)
|| checkLeftType<DataTypeVarUInt>(arguments, types_res)
|| checkLeftType<DataTypeVarInt>(arguments, types_res)))
throw Exception("Illegal type " + arguments[0]->getName() + " of first argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

View File

@ -0,0 +1,47 @@
#include <boost/assign/list_inserter.hpp>
#include <mysqlxx/String.h>
#include <DB/DataTypes/DataTypeFactory.h>
namespace DB
{
DataTypeFactory::DataTypeFactory()
: fixed_string_regexp("^FixedString\\s*\\(\\s*(\\d+)\\s*\\)$")
{
boost::assign::insert(non_parametric_data_types)
("UInt8", new DataTypeUInt8)
("UInt16", new DataTypeUInt16)
("UInt32", new DataTypeUInt32)
("UInt64", new DataTypeUInt64)
("Int8", new DataTypeInt8)
("Int16", new DataTypeInt16)
("Int32", new DataTypeInt32)
("Int64", new DataTypeInt64)
("Float32", new DataTypeFloat32)
("Float64", new DataTypeFloat64)
("VarUInt", new DataTypeVarUInt)
("VarInt", new DataTypeVarInt)
("String", new DataTypeString)
;
}
DataTypePtr DataTypeFactory::get(const String & name)
{
NonParametricDataTypes::iterator it = non_parametric_data_types.find(name);
if (it != non_parametric_data_types.end())
return it->second;
Poco::RegularExpression::MatchVec matches;
if (fixed_string_regexp.match(name, 0, matches) && matches.size() == 2)
return new DataTypeFixedString(mysqlxx::String(name.data() + matches[0].offset, matches[0].length, NULL).getUInt());
throw Exception("Unknown type " + name, ErrorCodes::UNKNOWN_TYPE);
}
}