2019-09-18 12:46:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-07-10 18:10:06 +00:00
|
|
|
#include <Core/Block.h>
|
2019-09-18 12:46:57 +00:00
|
|
|
#include <Interpreters/IJoin.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ColumnWithTypeAndName;
|
2020-07-10 18:10:06 +00:00
|
|
|
class TableJoin;
|
2019-09-18 12:46:57 +00:00
|
|
|
class IColumn;
|
|
|
|
using ColumnRawPtrs = std::vector<const IColumn *>;
|
|
|
|
|
|
|
|
namespace JoinCommon
|
|
|
|
{
|
|
|
|
|
2020-06-04 10:07:22 +00:00
|
|
|
void convertColumnToNullable(ColumnWithTypeAndName & column, bool low_card_nullability = false);
|
2019-09-18 12:46:57 +00:00
|
|
|
void convertColumnsToNullable(Block & block, size_t starting_pos = 0);
|
2019-10-29 19:39:42 +00:00
|
|
|
void removeColumnNullability(ColumnWithTypeAndName & column);
|
2020-07-10 18:10:06 +00:00
|
|
|
void changeColumnRepresentation(const ColumnPtr & src_column, ColumnPtr & dst_column);
|
|
|
|
ColumnPtr emptyNotNullableClone(const ColumnPtr & column);
|
2019-12-17 15:02:42 +00:00
|
|
|
Columns materializeColumns(const Block & block, const Names & names);
|
|
|
|
ColumnRawPtrs materializeColumnsInplace(Block & block, const Names & names);
|
|
|
|
ColumnRawPtrs getRawPointers(const Columns & columns);
|
2019-09-18 12:46:57 +00:00
|
|
|
void removeLowCardinalityInplace(Block & block);
|
2020-09-22 10:16:22 +00:00
|
|
|
void removeLowCardinalityInplace(Block & block, const Names & names, bool change_type = true);
|
|
|
|
void restoreLowCardinalityInplace(Block & block);
|
2019-09-18 12:46:57 +00:00
|
|
|
|
2020-03-13 08:15:43 +00:00
|
|
|
ColumnRawPtrs extractKeysForJoin(const Block & block_keys, const Names & key_names_right);
|
2019-09-18 12:46:57 +00:00
|
|
|
|
|
|
|
/// Throw an exception if blocks have different types of key columns. Compare up to Nullability.
|
|
|
|
void checkTypesOfKeys(const Block & block_left, const Names & key_names_left, const Block & block_right, const Names & key_names_right);
|
|
|
|
|
|
|
|
void createMissedColumns(Block & block);
|
2019-09-19 14:53:03 +00:00
|
|
|
void joinTotals(const Block & totals, const Block & columns_to_add, const Names & key_names_right, Block & block);
|
2019-09-18 12:46:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-10 18:10:06 +00:00
|
|
|
/// Creates result from right table data in RIGHT and FULL JOIN when keys are not present in left table.
|
|
|
|
class NotJoined
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NotJoined(const TableJoin & table_join, const Block & saved_block_sample_, const Block & right_sample_block,
|
|
|
|
const Block & result_sample_block_);
|
|
|
|
|
|
|
|
void correctLowcardAndNullability(MutableColumns & columns_right);
|
|
|
|
void addLeftColumns(Block & block, size_t rows_added) const;
|
|
|
|
void addRightColumns(Block & block, MutableColumns & columns_right) const;
|
|
|
|
void copySameKeys(Block & block) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Block saved_block_sample;
|
|
|
|
Block result_sample_block;
|
|
|
|
|
|
|
|
~NotJoined() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Indices of columns in result_sample_block that should be generated
|
|
|
|
std::vector<size_t> column_indices_left;
|
|
|
|
/// Indices of columns that come from the right-side table: right_pos -> result_pos
|
|
|
|
std::unordered_map<size_t, size_t> column_indices_right;
|
|
|
|
///
|
|
|
|
std::unordered_map<size_t, size_t> same_result_keys;
|
|
|
|
/// Which right columns (saved in parent) need nullability change before placing them in result block
|
|
|
|
std::vector<size_t> right_nullability_adds;
|
|
|
|
std::vector<size_t> right_nullability_removes;
|
|
|
|
/// Which right columns (saved in parent) need LowCardinality change before placing them in result block
|
|
|
|
std::vector<std::pair<size_t, ColumnPtr>> right_lowcard_changes;
|
|
|
|
|
|
|
|
void setRightIndex(size_t right_pos, size_t result_position);
|
|
|
|
void extractColumnChanges(size_t right_pos, size_t result_pos);
|
|
|
|
};
|
|
|
|
|
2019-09-18 12:46:57 +00:00
|
|
|
}
|