2016-02-07 08:42:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
2018-06-10 19:22:49 +00:00
|
|
|
#include <Formats/IRowInputStream.h>
|
|
|
|
#include <Formats/FormatSettings.h>
|
2016-02-07 08:42:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-02-16 16:39:39 +00:00
|
|
|
class ReadBuffer;
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** A stream for inputting data in csv format.
|
|
|
|
* Does not conform with https://tools.ietf.org/html/rfc4180 because it skips spaces and tabs between values.
|
2016-02-07 08:42:21 +00:00
|
|
|
*/
|
|
|
|
class CSVRowInputStream : public IRowInputStream
|
|
|
|
{
|
|
|
|
public:
|
2017-05-13 22:19:04 +00:00
|
|
|
/** with_names - in the first line the header with column names
|
|
|
|
* with_types - on the next line header with type names
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2018-06-08 01:51:55 +00:00
|
|
|
CSVRowInputStream(ReadBuffer & istr_, const Block & header_, bool with_names_, const FormatSettings & format_settings);
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2017-12-14 20:58:18 +00:00
|
|
|
bool read(MutableColumns & columns) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
void readPrefix() override;
|
2018-06-03 16:51:31 +00:00
|
|
|
bool allowSyncAfterError() const override { return true; }
|
2017-04-01 07:20:54 +00:00
|
|
|
void syncAfterError() override;
|
2017-01-27 04:29:47 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getDiagnosticInfo() override;
|
2016-02-07 08:42:21 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBuffer & istr;
|
2017-12-18 02:43:40 +00:00
|
|
|
Block header;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool with_names;
|
|
|
|
DataTypes data_types;
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2018-06-08 01:51:55 +00:00
|
|
|
const FormatSettings format_settings;
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// For convenient diagnostics in case of an error.
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t row_num = 0;
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// How many bytes were read, not counting those that are still in the buffer.
|
2017-04-01 07:20:54 +00:00
|
|
|
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-07 08:42:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
char * pos_of_current_row = nullptr;
|
|
|
|
char * pos_of_prev_row = nullptr;
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void updateDiagnosticInfo();
|
2016-02-07 08:42:21 +00:00
|
|
|
|
2017-12-14 20:58:18 +00:00
|
|
|
bool parseRowAndPrintDiagnosticInfo(MutableColumns & columns,
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBuffer & out, size_t max_length_of_column_name, size_t max_length_of_data_type_name);
|
2016-02-07 08:42:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|