mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-11 17:02:25 +00:00
dbms: development.
This commit is contained in:
parent
777299ae48
commit
f71d00d6f5
@ -511,6 +511,39 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/** IP адрес. Отличается от UInt32 текстовой сериализацией. */
|
||||
class ColumnTypeIPAddress : public ColumnTypeUInt32
|
||||
{
|
||||
public:
|
||||
std::string getName() const { return "IPAddress"; }
|
||||
|
||||
void serializeText(const DB::Field & field, std::ostream & ostr) const
|
||||
{
|
||||
UInt x = boost::get<UInt>(field);
|
||||
ostr << static_cast<Poco::UInt8>((x >> 24) & 0xFF)
|
||||
<< "." << static_cast<Poco::UInt8>((x >> 16) & 0xFF)
|
||||
<< "." << static_cast<Poco::UInt8>((x >> 8) & 0xFF)
|
||||
<< "." << static_cast<Poco::UInt8>(x & 0xFF);
|
||||
}
|
||||
|
||||
void deserializeText(DB::Field & field, std::istream & istr) const
|
||||
{
|
||||
Poco::UInt32 n1, n2, n3, n4;
|
||||
istr >> n1;
|
||||
istr.ignore();
|
||||
istr >> n2;
|
||||
istr.ignore();
|
||||
istr >> n3;
|
||||
istr.ignore();
|
||||
istr >> n4;
|
||||
istr.ignore();
|
||||
if (n1 > 255 || n2 > 255 || n3 > 255 || n4 > 255)
|
||||
throw Exception("Invalid IP address", ErrorCodes::INVALID_IP_ADDRESS);
|
||||
boost::get<UInt>(field) = (n1 << 24) | (n2 << 16) | (n3 << 8) | n4;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ColumnTypeFactory
|
||||
{
|
||||
public:
|
||||
@ -530,6 +563,8 @@ public:
|
||||
return new ColumnTypeUInt64;
|
||||
if (name == "Text")
|
||||
return new ColumnTypeText;
|
||||
if (name == "IPAddress")
|
||||
return new ColumnTypeIPAddress;
|
||||
|
||||
/// параметризованные типы
|
||||
static Poco::RegularExpression one_parameter_regexp("^([^\\(]+)\\((.+)\\)$");
|
||||
@ -537,7 +572,7 @@ public:
|
||||
|
||||
Poco::RegularExpression::MatchVec matches;
|
||||
|
||||
if (two_parameters_regexp.match(name, 0, matches))
|
||||
if (two_parameters_regexp.match(name, 0, matches) && matches.size() == 3)
|
||||
{
|
||||
/// FixedArray(T, N), где T - любой тип, а N - размер
|
||||
if (name.substr(matches[0].offset, matches[0].length) == "FixedArray")
|
||||
@ -554,7 +589,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (one_parameter_regexp.match(name, 0, matches))
|
||||
if (one_parameter_regexp.match(name, 0, matches) && matches.size() == 2)
|
||||
{
|
||||
/// FixedText(N), где N - размер
|
||||
if (name.substr(matches[0].offset, matches[0].length) == "FixedText")
|
||||
|
@ -18,7 +18,8 @@ namespace ErrorCodes
|
||||
TOO_FEW_COLUMNS_FOR_KEY,
|
||||
STORAGE_WAS_NOT_ATTACHED,
|
||||
CANT_READ_DATA_FILE,
|
||||
TOO_MANY_COLUMNS_FOR_KEY
|
||||
TOO_MANY_COLUMNS_FOR_KEY,
|
||||
INVALID_IP_ADDRESS,
|
||||
};
|
||||
}
|
||||
|
||||
|
24
dbms/src/tests/istream_test.cpp
Normal file
24
dbms/src/tests/istream_test.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <Poco/Types.h>
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "192.168.1.1fls";
|
||||
|
||||
unsigned x;
|
||||
s >> x;
|
||||
s.get();
|
||||
std::cout << x << std::endl;
|
||||
s >> x;
|
||||
s.get();
|
||||
std::cout << x << std::endl;
|
||||
s >> x;
|
||||
s.get();
|
||||
std::cout << x << std::endl;
|
||||
s >> x;
|
||||
std::cout << x << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user