ClickHouse/dbms/src/DataStreams/ValuesRowOutputStream.cpp

55 lines
914 B
C++
Raw Normal View History

2011-10-30 05:19:41 +00:00
#include <DB/DataStreams/ValuesRowOutputStream.h>
#include <DB/IO/WriteHelpers.h>
namespace DB
{
using Poco::SharedPtr;
2011-11-06 05:01:42 +00:00
ValuesRowOutputStream::ValuesRowOutputStream(WriteBuffer & ostr_, const Block & sample_)
: ostr(ostr_), sample(sample_), field_number(0)
2011-10-30 05:19:41 +00:00
{
2011-11-06 05:01:42 +00:00
size_t columns = sample.columns();
data_types.resize(columns);
for (size_t i = 0; i < columns; ++i)
data_types[i] = sample.getByPosition(i).type;
2011-10-30 05:19:41 +00:00
}
void ValuesRowOutputStream::writeField(const Field & field)
{
2011-11-06 05:01:42 +00:00
data_types[field_number]->serializeTextQuoted(field, ostr);
2011-10-30 05:19:41 +00:00
++field_number;
}
void ValuesRowOutputStream::writeFieldDelimiter()
{
writeChar(',', ostr);
}
void ValuesRowOutputStream::writeRowStartDelimiter()
{
writeChar('(', ostr);
}
void ValuesRowOutputStream::writeRowEndDelimiter()
{
2011-10-31 06:37:12 +00:00
writeChar(')', ostr);
2011-10-30 05:19:41 +00:00
}
void ValuesRowOutputStream::writeRowBetweenDelimiter()
{
writeCString(",", ostr);
2011-10-30 05:19:41 +00:00
field_number = 0;
}
}