ClickHouse/dbms/src/DataStreams/ValuesRowInputStream.cpp

56 lines
977 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
}
bool ValuesRowInputStream::read(Row & row)
2011-10-30 05:19:41 +00:00
{
2011-11-06 05:01:42 +00:00
size_t size = data_types.size();
row.resize(size);
2011-10-30 05:19:41 +00:00
skipWhitespaceIfAny(istr);
2012-05-21 06:49:05 +00:00
if (istr.eof() || *istr.position() == ';')
2011-10-30 05:19:41 +00:00
{
row.clear();
return false;
2011-10-30 05:19:41 +00:00
}
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);
data_types[i]->deserializeTextQuoted(row[i], istr);
2011-10-30 05:19:41 +00:00
skipWhitespaceIfAny(istr);
}
assertString(")", istr);
skipWhitespaceIfAny(istr);
if (!istr.eof() && *istr.position() == ',')
++istr.position();
return true;
2011-10-30 05:19:41 +00:00
}
}