2011-08-09 19:19:00 +00:00
|
|
|
|
#pragma once
|
2010-05-21 19:53:44 +00:00
|
|
|
|
|
2011-11-06 05:01:42 +00:00
|
|
|
|
#include <DB/Core/Block.h>
|
2010-05-21 19:53:44 +00:00
|
|
|
|
#include <DB/DataStreams/IRowInputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
class ReadBuffer;
|
|
|
|
|
class WriteBuffer;
|
|
|
|
|
|
|
|
|
|
|
2012-11-10 04:43:04 +00:00
|
|
|
|
/** Поток для ввода данных в формате tsv.
|
2010-05-21 19:53:44 +00:00
|
|
|
|
*/
|
|
|
|
|
class TabSeparatedRowInputStream : public IRowInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-11-06 06:22:52 +00:00
|
|
|
|
/** with_names - в первой строке заголовок с именами столбцов
|
|
|
|
|
* with_types - на следующей строке заголовок с именами типов
|
|
|
|
|
*/
|
|
|
|
|
TabSeparatedRowInputStream(ReadBuffer & istr_, const Block & sample_, bool with_names_ = false, bool with_types_ = false);
|
2010-05-21 19:53:44 +00:00
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
bool read(Block & block) override;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
void readPrefix() override;
|
2010-05-21 19:53:44 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2010-06-04 18:25:25 +00:00
|
|
|
|
ReadBuffer & istr;
|
2012-10-10 18:32:45 +00:00
|
|
|
|
const Block sample;
|
2011-11-06 06:22:52 +00:00
|
|
|
|
bool with_names;
|
|
|
|
|
bool with_types;
|
2011-11-06 05:01:42 +00:00
|
|
|
|
DataTypes data_types;
|
2015-03-29 07:13:38 +00:00
|
|
|
|
|
|
|
|
|
/// Для удобной диагностики в случае ошибки.
|
|
|
|
|
|
|
|
|
|
size_t row_num = 0;
|
|
|
|
|
|
|
|
|
|
/// Сколько байт было считано, не считая тех, что ещё в буфере.
|
|
|
|
|
size_t bytes_read_at_start_of_buffer_on_current_row = 0;
|
|
|
|
|
size_t bytes_read_at_start_of_buffer_on_prev_row = 0;
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
char * pos_of_current_row = nullptr;
|
|
|
|
|
char * pos_of_prev_row = nullptr;
|
2015-03-29 07:13:38 +00:00
|
|
|
|
|
2015-03-29 09:02:24 +00:00
|
|
|
|
/** В случае исключения при парсинге, вызывается эта функция.
|
|
|
|
|
* Она выполняет заново парсинг последних двух строк и выводит подробную информацию о том, что происходит.
|
|
|
|
|
*/
|
2016-02-16 16:39:39 +00:00
|
|
|
|
void printDiagnosticInfo(Block & block, WriteBuffer & out);
|
2015-03-29 09:02:24 +00:00
|
|
|
|
|
2015-03-29 07:13:38 +00:00
|
|
|
|
void updateDiagnosticInfo()
|
|
|
|
|
{
|
|
|
|
|
++row_num;
|
|
|
|
|
|
|
|
|
|
bytes_read_at_start_of_buffer_on_prev_row = bytes_read_at_start_of_buffer_on_current_row;
|
|
|
|
|
bytes_read_at_start_of_buffer_on_current_row = istr.count() - istr.offset();
|
|
|
|
|
|
|
|
|
|
pos_of_prev_row = pos_of_current_row;
|
|
|
|
|
pos_of_current_row = istr.position();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
|
bool parseRowAndPrintDiagnosticInfo(Block & block,
|
|
|
|
|
WriteBuffer & out, size_t max_length_of_column_name, size_t max_length_of_data_type_name);
|
2010-05-21 19:53:44 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|