2016-11-15 19:51:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <IO/ConnectionTimeouts.h>
|
2019-09-25 08:08:46 +00:00
|
|
|
#include <IO/ReadWriteBufferFromHTTP.h>
|
2019-09-25 04:33:54 +00:00
|
|
|
#include <Poco/Net/HTTPBasicCredentials.h>
|
2018-05-16 13:22:27 +00:00
|
|
|
#include <Poco/URI.h>
|
2021-12-21 13:41:53 +00:00
|
|
|
#include <Common/LocalDateTime.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "IDictionarySource.h"
|
2021-05-09 11:27:11 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <IO/CompressionMethod.h>
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2016-11-15 19:51:06 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2017-09-05 01:08:26 +00:00
|
|
|
/// Allows loading dictionaries from http[s] source
|
2016-11-15 19:51:06 +00:00
|
|
|
class HTTPDictionarySource final : public IDictionarySource
|
|
|
|
{
|
|
|
|
public:
|
2021-06-10 08:34:57 +00:00
|
|
|
|
|
|
|
struct Configuration
|
|
|
|
{
|
|
|
|
const std::string url;
|
|
|
|
const std::string format;
|
|
|
|
const std::string update_field;
|
|
|
|
const UInt64 update_lag;
|
2022-12-16 22:57:09 +00:00
|
|
|
const HTTPHeaderEntries header_entries;
|
2021-06-10 08:34:57 +00:00
|
|
|
};
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
HTTPDictionarySource(
|
|
|
|
const DictionaryStructure & dict_struct_,
|
2021-06-10 08:34:57 +00:00
|
|
|
const Configuration & configuration,
|
|
|
|
const Poco::Net::HTTPBasicCredentials & credentials_,
|
2019-08-03 11:02:40 +00:00
|
|
|
Block & sample_block_,
|
2022-07-13 15:33:18 +00:00
|
|
|
ContextPtr context_);
|
2016-11-15 19:51:06 +00:00
|
|
|
|
|
|
|
HTTPDictionarySource(const HTTPDictionarySource & other);
|
2019-07-08 00:51:43 +00:00
|
|
|
HTTPDictionarySource & operator=(const HTTPDictionarySource &) = delete;
|
2016-11-15 19:51:06 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
QueryPipeline loadAll() override;
|
2016-11-15 19:51:06 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
QueryPipeline loadUpdatedAll() override;
|
2018-02-15 13:08:23 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
QueryPipeline loadIds(const std::vector<UInt64> & ids) override;
|
2016-11-15 19:51:06 +00:00
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
QueryPipeline loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2016-11-15 19:51:06 +00:00
|
|
|
|
|
|
|
bool isModified() const override;
|
|
|
|
|
|
|
|
bool supportsSelectiveLoad() const override;
|
|
|
|
|
2018-01-15 12:44:39 +00:00
|
|
|
bool hasUpdateField() const override;
|
|
|
|
|
2016-11-15 19:51:06 +00:00
|
|
|
DictionarySourcePtr clone() const override;
|
|
|
|
|
|
|
|
std::string toString() const override;
|
|
|
|
|
|
|
|
private:
|
2018-05-16 13:22:27 +00:00
|
|
|
void getUpdateFieldAndDate(Poco::URI & uri);
|
2018-02-15 13:08:23 +00:00
|
|
|
|
2021-05-07 23:20:30 +00:00
|
|
|
// wrap buffer using encoding from made request
|
2022-05-20 19:49:31 +00:00
|
|
|
QueryPipeline createWrappedBuffer(std::unique_ptr<ReadWriteBufferFromHTTP> http_buffer);
|
2021-05-07 23:20:30 +00:00
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
Poco::Logger * log;
|
2016-11-15 19:51:06 +00:00
|
|
|
|
|
|
|
LocalDateTime getLastModification() const;
|
|
|
|
|
2018-01-15 12:44:39 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> update_time;
|
2016-11-18 01:48:13 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
2021-06-10 08:34:57 +00:00
|
|
|
const Configuration configuration;
|
2019-09-25 04:33:54 +00:00
|
|
|
Poco::Net::HTTPBasicCredentials credentials;
|
2016-11-15 19:51:06 +00:00
|
|
|
Block sample_block;
|
2021-06-01 12:20:52 +00:00
|
|
|
ContextPtr context;
|
2017-12-27 17:58:52 +00:00
|
|
|
ConnectionTimeouts timeouts;
|
2016-11-15 19:51:06 +00:00
|
|
|
};
|
|
|
|
|
2021-08-06 08:41:45 +00:00
|
|
|
}
|