diff --git a/dbms/include/DB/IO/CompressedWriteBuffer.h b/dbms/include/DB/IO/CompressedWriteBuffer.h index 70cc1ef0551..5d9ed09ac49 100644 --- a/dbms/include/DB/IO/CompressedWriteBuffer.h +++ b/dbms/include/DB/IO/CompressedWriteBuffer.h @@ -18,8 +18,10 @@ private: char compressed_buffer[DBMS_COMPRESSING_STREAM_BUFFER_SIZE + QUICKLZ_ADDITIONAL_SPACE]; char scratch[QLZ_SCRATCH_COMPRESS]; + size_t compressed_bytes; + public: - CompressedWriteBuffer(WriteBuffer & out_) : out(out_) {} + CompressedWriteBuffer(WriteBuffer & out_) : out(out_), compressed_bytes(0) {} void next() { @@ -31,6 +33,19 @@ public: out.write(compressed_buffer, compressed_size); pos = internal_buffer; + compressed_bytes += compressed_size; + } + + size_t getCompressedBytes() + { + nextIfAtEnd(); + return compressed_bytes; + } + + size_t getUncompressedBytes() + { + nextIfAtEnd(); + return pos - internal_buffer; } ~CompressedWriteBuffer() diff --git a/dbms/include/DB/IO/ReadHelpers.h b/dbms/include/DB/IO/ReadHelpers.h index da7c9891597..33fed4a46fc 100644 --- a/dbms/include/DB/IO/ReadHelpers.h +++ b/dbms/include/DB/IO/ReadHelpers.h @@ -5,6 +5,8 @@ #include #include +#include + #include #include #include @@ -216,6 +218,19 @@ void readEscapedString(String & s, ReadBuffer & buf); void readQuotedString(String & s, ReadBuffer & buf); +/// в формате YYYY-MM-DD +inline void readDateText(Yandex::DayNum_t & date, ReadBuffer & buf) +{ + char s[10]; + buf.read(s, 10); + + UInt16 year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0'); + UInt8 month = (s[5] - '0') * 10 + (s[6] - '0'); + UInt8 day = (s[8] - '0') * 10 + (s[9] - '0'); + + date = Yandex::DateLUTSingleton::instance().makeDayNum(year, month, day); +} + } #endif diff --git a/dbms/include/DB/IO/WriteBuffer.h b/dbms/include/DB/IO/WriteBuffer.h index 5383ad19db5..f259431275d 100644 --- a/dbms/include/DB/IO/WriteBuffer.h +++ b/dbms/include/DB/IO/WriteBuffer.h @@ -33,7 +33,7 @@ public: Position end_pos; /// на 1 байт после конца буфера }; - WriteBuffer() : working_buffer(internal_buffer, internal_buffer + DEFAULT_WRITE_BUFFER_SIZE), pos(internal_buffer) {} + WriteBuffer() : working_buffer(internal_buffer, internal_buffer + DEFAULT_WRITE_BUFFER_SIZE), pos(internal_buffer), bytes_written(0) {} /// получить часть буфера, в который можно писать данные inline Buffer & buffer() { return working_buffer; } @@ -71,12 +71,22 @@ public: pos += bytes_to_copy; bytes_copied += bytes_to_copy; } + + bytes_written += n; + } + + size_t count() + { + return bytes_written; } protected: char internal_buffer[DEFAULT_WRITE_BUFFER_SIZE]; Buffer working_buffer; Position pos; + +private: + size_t bytes_written; }; diff --git a/dbms/include/DB/IO/WriteHelpers.h b/dbms/include/DB/IO/WriteHelpers.h index c3e56cb797e..0732361ba71 100644 --- a/dbms/include/DB/IO/WriteHelpers.h +++ b/dbms/include/DB/IO/WriteHelpers.h @@ -6,6 +6,8 @@ #include #include +#include + #include #include #include @@ -30,8 +32,6 @@ inline void writeChar(char x, WriteBuffer & buf) } -template struct IntFormat { static const char * format; }; - template void writeIntText(T x, WriteBuffer & buf) { @@ -94,6 +94,28 @@ inline void writeQuotedString(const String & s, WriteBuffer & buf) } +/// в формате YYYY-MM-DD +inline void writeDateText(Yandex::DayNum_t date, WriteBuffer & buf) +{ + char s[10]; + + 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; + + buf.write(s, 10); +} + + } #endif diff --git a/dbms/src/IO/WriteHelpers.cpp b/dbms/src/IO/WriteHelpers.cpp index 5c61408bf67..e1642d7a477 100644 --- a/dbms/src/IO/WriteHelpers.cpp +++ b/dbms/src/IO/WriteHelpers.cpp @@ -3,16 +3,6 @@ namespace DB { -template <> const char * IntFormat::format = "%hhi"; -template <> const char * IntFormat::format = "%hi"; -template <> const char * IntFormat::format = "%li"; -template <> const char * IntFormat::format = "%lli"; -template <> const char * IntFormat::format = "%hhi"; -template <> const char * IntFormat::format = "%hi"; -template <> const char * IntFormat::format = "%li"; -template <> const char * IntFormat::format = "%lli"; - - void writeEscapedString(const String & s, WriteBuffer & buf) { for (String::const_iterator it = s.begin(); it != s.end(); ++it)