dbms: development.

This commit is contained in:
Alexey Milovidov 2011-08-07 03:42:36 +00:00
parent e1dca98ecb
commit b3bca9c160
4 changed files with 39 additions and 35 deletions

View File

@ -27,7 +27,7 @@ public:
{
time_t x;
readDateTimeText(x, istr);
field = x;
field = NearestFieldType<UInt32>::Type(x);
}
void serializeTextEscaped(const Field & field, WriteBuffer & ostr) const

View File

@ -108,20 +108,24 @@ void writeDoubleQuotedString(const String & s, WriteBuffer & buf);
/// в формате YYYY-MM-DD
inline void writeDateText(Yandex::DayNum_t date, WriteBuffer & buf)
{
char s[10];
char s[10] = {'0', '0', '0', '0', '-', '0', '0', '-', '0', '0'};
if (unlikely(date > DATE_LUT_MAX_DAY_NUM || date == 0))
{
buf.write(s, 10);
return;
}
const Yandex::DateLUT::Values & values = Yandex::DateLUTSingleton::instance().getValues(date);
s[0] = '0' + values.year / 1000;
s[1] = '0' + (values.year / 100) % 10;
s[2] = '0' + (values.year / 10) % 10;
s[3] = '0' + values.year % 10;
s[4] = '-';
s[5] = '0' + values.month / 10;
s[6] = '0' + values.month % 10;
s[7] = '-';
s[8] = '0' + values.day_of_month / 10;
s[9] = '0' + values.day_of_month % 10;
s[0] += values.year / 1000;
s[1] += (values.year / 100) % 10;
s[2] += (values.year / 10) % 10;
s[3] += values.year % 10;
s[5] += values.month / 10;
s[6] += values.month % 10;
s[8] += values.day_of_month / 10;
s[9] += values.day_of_month % 10;
buf.write(s, 10);
}
@ -130,35 +134,36 @@ inline void writeDateText(Yandex::DayNum_t date, WriteBuffer & buf)
/// в формате YYYY-MM-DD HH:MM:SS, согласно текущему часовому поясу
inline void writeDateTimeText(time_t datetime, WriteBuffer & buf)
{
char s[19];
char s[19] = {'0', '0', '0', '0', '-', '0', '0', '-', '0', '0', ' ', '0', '0', ':', '0', '0', ':', '0', '0'};
if (unlikely(datetime > DATE_LUT_MAX || datetime == 0))
{
buf.write(s, 19);
return;
}
Yandex::DateLUTSingleton & date_lut = Yandex::DateLUTSingleton::instance();
const Yandex::DateLUT::Values & values = date_lut.getValues(datetime);
s[0] = '0' + values.year / 1000;
s[1] = '0' + (values.year / 100) % 10;
s[2] = '0' + (values.year / 10) % 10;
s[3] = '0' + values.year % 10;
s[4] = '-';
s[5] = '0' + values.month / 10;
s[6] = '0' + values.month % 10;
s[7] = '-';
s[8] = '0' + values.day_of_month / 10;
s[9] = '0' + values.day_of_month % 10;
s[0] += values.year / 1000;
s[1] += (values.year / 100) % 10;
s[2] += (values.year / 10) % 10;
s[3] += values.year % 10;
s[5] += values.month / 10;
s[6] += values.month % 10;
s[8] += values.day_of_month / 10;
s[9] += values.day_of_month % 10;
UInt8 hour = date_lut.toHourInaccurate(datetime);
UInt8 minute = date_lut.toMinute(datetime);
UInt8 second = date_lut.toSecond(datetime);
s[10] = ' ';
s[11] = '0' + hour / 10;
s[12] = '0' + hour % 10;
s[13] = ':';
s[14] = '0' + minute / 10;
s[15] = '0' + minute % 10;
s[16] = ':';
s[17] = '0' + second / 10;
s[18] = '0' + second % 10;
s[11] += hour / 10;
s[12] += hour % 10;
s[14] += minute / 10;
s[15] += minute % 10;
s[17] += second / 10;
s[18] += second % 10;
buf.write(s, 19);
}

View File

@ -3,7 +3,6 @@
#include <DB/DataStreams/BlockInputStreamFromRowInputStream.h>
#include <iostream>
namespace DB
{

View File

@ -35,10 +35,10 @@ namespace Yandex
/// Заполняем lookup таблицу для годов
memset(years_lut, 0, DATE_LUT_YEARS * sizeof(years_lut[0]));
for (size_t day = 0; day < lut.size() && lut[day].year < DATE_LUT_YEARS + 1900; ++day)
for (size_t day = 0; day < lut.size() && lut[day].year <= DATE_LUT_MAX_YEAR; ++day)
{
if (lut[day].month == 1 && lut[day].day_of_month == 1)
years_lut[lut[day].year - 1900] = day;
years_lut[lut[day].year - DATE_LUT_MIN_YEAR] = day;
}
}
}