2010-06-04 18:25:25 +00:00
|
|
|
#include <DB/IO/ReadHelpers.h>
|
|
|
|
|
2010-05-21 19:52:50 +00:00
|
|
|
#include <DB/DataStreams/TabSeparatedRowInputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
TabSeparatedRowInputStream::TabSeparatedRowInputStream(ReadBuffer & istr_, SharedPtr<DataTypes> & data_types_)
|
2010-05-21 19:52:50 +00:00
|
|
|
: istr(istr_), data_types(data_types_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Row TabSeparatedRowInputStream::read()
|
|
|
|
{
|
|
|
|
Row res;
|
|
|
|
size_t size = data_types->size();
|
|
|
|
res.resize(size);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
if (i == 0 && istr.eof())
|
|
|
|
{
|
|
|
|
res.clear();
|
|
|
|
return res;
|
|
|
|
}
|
2010-06-04 18:38:56 +00:00
|
|
|
|
|
|
|
(*data_types)[i]->deserializeTextEscaped(res[i], istr);
|
2010-05-21 19:52:50 +00:00
|
|
|
|
|
|
|
/// пропускаем разделители
|
|
|
|
if (i + 1 == size)
|
|
|
|
{
|
2010-06-04 18:25:25 +00:00
|
|
|
if (!istr.eof())
|
|
|
|
assertString("\n", istr);
|
2010-05-21 19:52:50 +00:00
|
|
|
}
|
|
|
|
else
|
2010-06-04 18:25:25 +00:00
|
|
|
assertString("\t", istr);
|
2010-05-21 19:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|