2020-02-05 10:12:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Names.h>
|
|
|
|
#include <Core/Block.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2020-02-05 10:12:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class IFunctionOverloadResolver;
|
|
|
|
using FunctionOverloadResolverPtr = std::shared_ptr<IFunctionOverloadResolver>;
|
|
|
|
|
2022-11-15 01:42:46 +00:00
|
|
|
class DataTypeArray;
|
|
|
|
class ColumnArray;
|
2022-12-14 13:02:03 +00:00
|
|
|
std::shared_ptr<const DataTypeArray> getArrayJoinDataType(DataTypePtr type);
|
|
|
|
const ColumnArray * getArrayJoinColumnRawPtr(const ColumnPtr & column);
|
2022-11-15 01:42:46 +00:00
|
|
|
|
2022-11-21 10:03:46 +00:00
|
|
|
/// If input array join column has map type, convert it to array type.
|
|
|
|
/// Otherwise do nothing.
|
|
|
|
ColumnWithTypeAndName convertArrayJoinColumn(const ColumnWithTypeAndName & src_col);
|
2022-11-15 01:42:46 +00:00
|
|
|
|
2023-09-15 08:33:48 +00:00
|
|
|
|
|
|
|
class ArrayJoinResultIterator;
|
|
|
|
using ArrayJoinResultIteratorPtr = std::unique_ptr<ArrayJoinResultIterator>;
|
2020-08-11 12:03:18 +00:00
|
|
|
class ArrayJoinAction
|
2020-02-05 10:12:19 +00:00
|
|
|
{
|
2020-08-11 12:03:18 +00:00
|
|
|
public:
|
2020-02-05 10:12:19 +00:00
|
|
|
NameSet columns;
|
|
|
|
bool is_left = false;
|
|
|
|
bool is_unaligned = false;
|
2023-09-15 08:33:48 +00:00
|
|
|
size_t max_block_size = DEFAULT_BLOCK_SIZE;
|
2020-02-05 10:12:19 +00:00
|
|
|
|
|
|
|
/// For unaligned [LEFT] ARRAY JOIN
|
|
|
|
FunctionOverloadResolverPtr function_length;
|
|
|
|
FunctionOverloadResolverPtr function_greatest;
|
2022-11-15 01:42:46 +00:00
|
|
|
FunctionOverloadResolverPtr function_array_resize;
|
2020-02-05 10:12:19 +00:00
|
|
|
|
|
|
|
/// For LEFT ARRAY JOIN.
|
|
|
|
FunctionOverloadResolverPtr function_builder;
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
ArrayJoinAction(const NameSet & array_joined_columns_, bool array_join_is_left, ContextPtr context);
|
2020-09-10 18:36:51 +00:00
|
|
|
void prepare(ColumnsWithTypeAndName & sample) const;
|
2023-09-15 08:33:48 +00:00
|
|
|
|
|
|
|
ArrayJoinResultIteratorPtr execute(Block block);
|
2020-02-05 10:12:19 +00:00
|
|
|
};
|
|
|
|
|
2020-08-11 12:03:18 +00:00
|
|
|
using ArrayJoinActionPtr = std::shared_ptr<ArrayJoinAction>;
|
|
|
|
|
2023-09-15 08:33:48 +00:00
|
|
|
class ArrayJoinResultIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ArrayJoinResultIterator(const ArrayJoinAction * array_join_, Block block_);
|
|
|
|
~ArrayJoinResultIterator() = default;
|
|
|
|
|
|
|
|
Block next();
|
|
|
|
bool hasNext() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ArrayJoinAction * array_join;
|
|
|
|
Block block;
|
|
|
|
|
|
|
|
ColumnPtr any_array_map_ptr;
|
|
|
|
const ColumnArray * any_array;
|
|
|
|
/// If LEFT ARRAY JOIN, then we create columns in which empty arrays are replaced by arrays with one element - the default value.
|
|
|
|
std::map<String, ColumnPtr> non_empty_array_columns;
|
|
|
|
|
|
|
|
size_t total_rows;
|
|
|
|
size_t current_row;
|
|
|
|
};
|
2020-02-05 10:12:19 +00:00
|
|
|
}
|