2018-05-24 01:02:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <Columns/IColumn.h>
|
|
|
|
#include <Processors/Formats/IInputFormat.h>
|
2021-10-15 20:18:20 +00:00
|
|
|
#include <QueryPipeline/SizeLimits.h>
|
2019-08-01 14:25:41 +00:00
|
|
|
#include <Poco/Timespan.h>
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2021-08-11 14:19:45 +00:00
|
|
|
class Stopwatch;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-02-19 18:41:18 +00:00
|
|
|
/// Contains extra information about read data.
|
|
|
|
struct RowReadExtension
|
|
|
|
{
|
2021-04-13 20:04:13 +00:00
|
|
|
/// IRowInputFormat::read output. It contains non zero for columns that actually read from the source and zero otherwise.
|
2019-02-19 18:41:18 +00:00
|
|
|
/// It's used to attach defaults for partially filled rows.
|
|
|
|
std::vector<UInt8> read_columns;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Common parameters for generating blocks.
|
|
|
|
struct RowInputFormatParams
|
|
|
|
{
|
2021-05-08 15:35:09 +00:00
|
|
|
size_t max_block_size = 0;
|
2019-02-19 18:41:18 +00:00
|
|
|
|
2021-05-08 15:35:09 +00:00
|
|
|
UInt64 allow_errors_num = 0;
|
|
|
|
Float64 allow_errors_ratio = 0;
|
2019-07-24 18:00:09 +00:00
|
|
|
|
2019-08-01 14:25:41 +00:00
|
|
|
Poco::Timespan max_execution_time = 0;
|
|
|
|
OverflowMode timeout_overflow_mode = OverflowMode::THROW;
|
2019-02-19 18:41:18 +00:00
|
|
|
};
|
|
|
|
|
2019-09-02 12:57:22 +00:00
|
|
|
bool isParseError(int code);
|
2019-09-02 16:26:22 +00:00
|
|
|
bool checkTimeLimit(const RowInputFormatParams & params, const Stopwatch & stopwatch);
|
2019-09-02 12:57:22 +00:00
|
|
|
|
2020-11-03 20:32:18 +00:00
|
|
|
/// Row oriented input format: reads data row by row.
|
2018-05-24 01:02:16 +00:00
|
|
|
class IRowInputFormat : public IInputFormat
|
|
|
|
{
|
|
|
|
public:
|
2019-02-19 18:41:18 +00:00
|
|
|
using Params = RowInputFormatParams;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
IRowInputFormat(Block header, ReadBuffer & in_, Params params_);
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2019-02-18 16:36:07 +00:00
|
|
|
Chunk generate() override;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2019-11-26 23:46:19 +00:00
|
|
|
void resetParser() override;
|
|
|
|
|
2018-05-24 01:02:16 +00:00
|
|
|
protected:
|
|
|
|
/** Read next row and append it to the columns.
|
|
|
|
* If no more rows - return false.
|
|
|
|
*/
|
2019-02-19 18:41:18 +00:00
|
|
|
virtual bool readRow(MutableColumns & columns, RowReadExtension & extra) = 0;
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2023-08-23 10:15:47 +00:00
|
|
|
/// Count some rows. Called in a loop until it returns 0, and the return values are added up.
|
|
|
|
/// `max_block_size` is the recommended number of rows after which to stop, if the implementation
|
|
|
|
/// involves scanning the data. If the implementation just takes the count from metadata,
|
|
|
|
/// `max_block_size` can be ignored.
|
2023-08-21 12:30:52 +00:00
|
|
|
virtual size_t countRows(size_t max_block_size);
|
|
|
|
virtual bool supportsCountRows() const { return false; }
|
|
|
|
|
2019-04-05 11:39:07 +00:00
|
|
|
virtual void readPrefix() {} /// delimiter before begin of result
|
|
|
|
virtual void readSuffix() {} /// delimiter after end of result
|
2018-05-24 01:02:16 +00:00
|
|
|
|
|
|
|
/// Skip data until next row.
|
|
|
|
/// This is intended for text streams, that allow skipping of errors.
|
|
|
|
/// By default - throws not implemented exception.
|
|
|
|
virtual bool allowSyncAfterError() const { return false; }
|
|
|
|
virtual void syncAfterError();
|
|
|
|
|
|
|
|
/// In case of parse error, try to roll back and parse last one or two rows very carefully
|
|
|
|
/// and collect as much as possible diagnostic information about error.
|
|
|
|
/// If not implemented, returns empty string.
|
2019-04-05 11:39:07 +00:00
|
|
|
virtual std::string getDiagnosticInfo() { return {}; }
|
2022-08-23 04:17:36 +00:00
|
|
|
/// Get diagnostic info and raw data for a row
|
2022-09-08 16:37:18 +00:00
|
|
|
virtual std::pair<std::string, std::string> getDiagnosticAndRawData() { return std::make_pair("", ""); }
|
|
|
|
|
|
|
|
void logError();
|
2018-05-24 01:02:16 +00:00
|
|
|
|
2019-07-30 18:48:40 +00:00
|
|
|
const BlockMissingValues & getMissingValues() const override { return block_missing_values; }
|
|
|
|
|
2020-02-07 09:58:29 +00:00
|
|
|
size_t getTotalRows() const { return total_rows; }
|
|
|
|
|
2023-06-16 15:51:18 +00:00
|
|
|
size_t getApproxBytesReadForChunk() const override { return approx_bytes_read_for_chunk; }
|
|
|
|
|
2021-03-09 14:46:52 +00:00
|
|
|
Serializations serializations;
|
|
|
|
|
2018-05-24 01:02:16 +00:00
|
|
|
private:
|
|
|
|
Params params;
|
|
|
|
|
|
|
|
size_t total_rows = 0;
|
|
|
|
size_t num_errors = 0;
|
2019-07-30 18:48:40 +00:00
|
|
|
|
|
|
|
BlockMissingValues block_missing_values;
|
2023-07-06 13:48:57 +00:00
|
|
|
size_t approx_bytes_read_for_chunk = 0;
|
2018-05-24 01:02:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|