mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
DB: IO: development.
This commit is contained in:
parent
e77285160d
commit
b18bedd18c
@ -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()
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <Yandex/DateLUT.h>
|
||||
|
||||
#include <DB/Core/Types.h>
|
||||
#include <DB/Core/Exception.h>
|
||||
#include <DB/Core/ErrorCodes.h>
|
||||
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <Yandex/DateLUT.h>
|
||||
|
||||
#include <DB/Core/Types.h>
|
||||
#include <DB/Core/Exception.h>
|
||||
#include <DB/Core/ErrorCodes.h>
|
||||
@ -30,8 +32,6 @@ inline void writeChar(char x, WriteBuffer & buf)
|
||||
}
|
||||
|
||||
|
||||
template <typename T> struct IntFormat { static const char * format; };
|
||||
|
||||
template <typename T>
|
||||
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
|
||||
|
@ -3,16 +3,6 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
template <> const char * IntFormat<Int8>::format = "%hhi";
|
||||
template <> const char * IntFormat<Int16>::format = "%hi";
|
||||
template <> const char * IntFormat<Int32>::format = "%li";
|
||||
template <> const char * IntFormat<Int64>::format = "%lli";
|
||||
template <> const char * IntFormat<UInt8>::format = "%hhi";
|
||||
template <> const char * IntFormat<UInt16>::format = "%hi";
|
||||
template <> const char * IntFormat<UInt32>::format = "%li";
|
||||
template <> const char * IntFormat<UInt64>::format = "%lli";
|
||||
|
||||
|
||||
void writeEscapedString(const String & s, WriteBuffer & buf)
|
||||
{
|
||||
for (String::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||
|
Loading…
Reference in New Issue
Block a user