ClickHouse/programs/odbc-bridge/ODBCBlockInputStream.h

45 lines
1.3 KiB
C++
Raw Normal View History

#pragma once
#include <string>
#include <Core/Block.h>
#include <DataStreams/IBlockInputStream.h>
2019-02-15 11:46:07 +00:00
#include <Core/ExternalResultDescription.h>
2021-05-07 10:37:11 +00:00
#include "ODBCConnectionFactory.h"
namespace DB
{
/// Allows processing results of a query to ODBC source as a sequence of Blocks, simplifies chaining
class ODBCBlockInputStream final : public IBlockInputStream
{
public:
2021-05-07 11:18:49 +00:00
ODBCBlockInputStream(nanodbc::ConnectionHolderPtr connection, const std::string & query_str, const Block & sample_block, const UInt64 max_block_size_);
String getName() const override { return "ODBC"; }
Block getHeader() const override { return description.sample_block.cloneEmpty(); }
private:
2021-03-22 11:40:29 +00:00
using QueryResult = std::shared_ptr<nanodbc::result>;
using ValueType = ExternalResultDescription::ValueType;
Block readImpl() override;
static void insertValue(IColumn & column, const DataTypePtr data_type, const ValueType type, nanodbc::result & row, size_t idx);
2021-03-22 11:40:29 +00:00
static void insertDefaultValue(IColumn & column, const IColumn & sample_column)
{
column.insertFrom(sample_column, 0);
}
2021-03-22 11:40:29 +00:00
Poco::Logger * log;
2019-02-10 16:55:12 +00:00
const UInt64 max_block_size;
ExternalResultDescription description;
2021-03-22 11:40:29 +00:00
nanodbc::result result;
String query;
bool finished = false;
};
}