2018-02-22 23:02:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2018-02-22 23:02:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Convert one block structure to another:
|
|
|
|
*
|
|
|
|
* Leaves only necessary columns;
|
|
|
|
*
|
|
|
|
* Columns are searched in source first by name;
|
|
|
|
* and if there is no column with same name, then by position.
|
|
|
|
*
|
|
|
|
* Converting types of matching columns (with CAST function).
|
|
|
|
*
|
|
|
|
* Materializing columns which are const in source and non-const in result,
|
|
|
|
* throw if they are const in result and non const in source,
|
|
|
|
* or if they are const and have different values.
|
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class ConvertingBlockInputStream : public IBlockInputStream
|
2018-02-22 23:02:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-23 01:00:47 +00:00
|
|
|
enum class MatchColumnsMode
|
|
|
|
{
|
|
|
|
/// Require same number of columns in source and result. Match columns by corresponding positions, regardless to names.
|
|
|
|
Position,
|
|
|
|
/// Find columns in source by their names. Allow excessive columns in source.
|
2020-01-23 15:53:58 +00:00
|
|
|
Name
|
2018-02-23 01:00:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ConvertingBlockInputStream(
|
|
|
|
const Context & context,
|
|
|
|
const BlockInputStreamPtr & input,
|
|
|
|
const Block & result_header,
|
2020-01-23 15:53:58 +00:00
|
|
|
MatchColumnsMode mode);
|
2018-02-22 23:02:35 +00:00
|
|
|
|
|
|
|
String getName() const override { return "Converting"; }
|
|
|
|
Block getHeader() const override { return header; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Block readImpl() override;
|
|
|
|
|
|
|
|
const Context & context;
|
|
|
|
Block header;
|
|
|
|
|
|
|
|
/// How to construct result block. Position in source block, where to get each column.
|
|
|
|
using Conversion = std::vector<size_t>;
|
|
|
|
Conversion conversion;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|