2019-01-21 14:02:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
#include <Processors/Sources/SourceWithProgress.h>
|
2019-01-30 17:41:06 +00:00
|
|
|
|
|
|
|
#include <Storages/Kafka/StorageKafka.h>
|
2019-08-28 13:21:19 +00:00
|
|
|
#include <Storages/Kafka/ReadBufferFromKafkaConsumer.h>
|
|
|
|
|
2019-01-21 14:02:03 +00:00
|
|
|
|
2020-06-11 00:51:27 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
2019-01-21 14:02:03 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
class KafkaSource : public SourceWithProgress
|
2019-01-21 14:02:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-10-07 08:26:08 +00:00
|
|
|
KafkaSource(
|
2020-06-16 12:48:10 +00:00
|
|
|
StorageKafka & storage_,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot_,
|
2021-04-20 12:57:23 +00:00
|
|
|
const ContextPtr & context_,
|
2020-06-16 12:48:10 +00:00
|
|
|
const Names & columns,
|
2020-06-22 09:03:53 +00:00
|
|
|
Poco::Logger * log_,
|
2020-06-16 12:48:10 +00:00
|
|
|
size_t max_block_size_,
|
2021-11-03 12:43:23 +00:00
|
|
|
bool commit_in_suffix = false);
|
2021-10-07 08:26:08 +00:00
|
|
|
~KafkaSource() override;
|
2019-01-21 14:02:03 +00:00
|
|
|
|
2019-01-30 17:41:06 +00:00
|
|
|
String getName() const override { return storage.getName(); }
|
|
|
|
|
2021-10-07 08:26:08 +00:00
|
|
|
Chunk generate() override;
|
2019-01-21 14:02:03 +00:00
|
|
|
|
2019-10-02 21:17:19 +00:00
|
|
|
void commit();
|
2020-07-22 08:28:07 +00:00
|
|
|
bool isStalled() const { return !buffer || buffer->isStalled(); }
|
2019-10-02 21:17:19 +00:00
|
|
|
|
2019-01-21 14:02:03 +00:00
|
|
|
private:
|
|
|
|
StorageKafka & storage;
|
2021-07-09 03:15:41 +00:00
|
|
|
StorageSnapshotPtr storage_snapshot;
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context;
|
2019-05-22 19:38:43 +00:00
|
|
|
Names column_names;
|
2020-06-11 00:51:27 +00:00
|
|
|
Poco::Logger * log;
|
2019-02-11 11:54:30 +00:00
|
|
|
UInt64 max_block_size;
|
2019-01-25 12:48:59 +00:00
|
|
|
|
2019-08-20 11:17:57 +00:00
|
|
|
ConsumerBufferPtr buffer;
|
2020-05-03 13:04:04 +00:00
|
|
|
bool broken = true;
|
2021-10-07 08:26:08 +00:00
|
|
|
bool is_finished = false;
|
2020-05-03 13:04:04 +00:00
|
|
|
bool commit_in_suffix;
|
2020-01-28 13:24:37 +00:00
|
|
|
|
2020-05-03 13:04:04 +00:00
|
|
|
const Block non_virtual_header;
|
|
|
|
const Block virtual_header;
|
2021-03-18 05:26:32 +00:00
|
|
|
const HandleKafkaErrorMode handle_error_mode;
|
2021-10-07 08:26:08 +00:00
|
|
|
|
|
|
|
Chunk generateImpl();
|
2019-01-21 14:02:03 +00:00
|
|
|
};
|
|
|
|
|
2019-06-13 10:37:13 +00:00
|
|
|
}
|