ClickHouse/dbms/src/DataStreams/ValuesRowInputStream.cpp

57 lines
974 B
C++
Raw Normal View History

2011-10-30 05:19:41 +00:00
#include <DB/IO/ReadHelpers.h>
#include <DB/DataStreams/ValuesRowInputStream.h>
namespace DB
{
using Poco::SharedPtr;
2011-11-06 05:01:42 +00:00
ValuesRowInputStream::ValuesRowInputStream(ReadBuffer & istr_, const Block & sample_)
: istr(istr_), sample(sample_)
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
}
Row ValuesRowInputStream::read()
{
Row res;
2011-11-06 05:01:42 +00:00
size_t size = data_types.size();
2011-10-30 05:19:41 +00:00
res.resize(size);
skipWhitespaceIfAny(istr);
2012-05-21 06:49:05 +00:00
if (istr.eof() || *istr.position() == ';')
2011-10-30 05:19:41 +00:00
{
res.clear();
return res;
}
2012-05-21 06:49:05 +00:00
2011-10-30 05:19:41 +00:00
assertString("(", istr);
for (size_t i = 0; i < size; ++i)
{
if (i != 0)
assertString(",", istr);
skipWhitespaceIfAny(istr);
2011-11-06 05:01:42 +00:00
data_types[i]->deserializeTextQuoted(res[i], istr);
2011-10-30 05:19:41 +00:00
skipWhitespaceIfAny(istr);
}
assertString(")", istr);
skipWhitespaceIfAny(istr);
if (!istr.eof() && *istr.position() == ',')
++istr.position();
return res;
}
}