2014-01-17 15:19:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2019-05-20 12:16:51 +00:00
|
|
|
#include <Parsers/IAST_fwd.h>
|
2021-03-04 05:59:57 +00:00
|
|
|
#include <Storages/SelectQueryInfo.h>
|
2014-12-30 18:04:53 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <unordered_set>
|
|
|
|
|
2014-01-17 15:19:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
class NamesAndTypesList;
|
2014-12-30 18:04:53 +00:00
|
|
|
|
|
|
|
|
2014-01-22 14:24:05 +00:00
|
|
|
namespace VirtualColumnUtils
|
2014-01-17 15:19:20 +00:00
|
|
|
{
|
2014-01-22 14:24:05 +00:00
|
|
|
|
2019-11-06 17:37:30 +00:00
|
|
|
/// Adds to the select query section `WITH value AS column_name`, and uses func
|
|
|
|
/// to wrap the value (if any)
|
|
|
|
///
|
|
|
|
/// For example:
|
|
|
|
/// - `WITH 9000 as _port`.
|
|
|
|
/// - `WITH toUInt16(9000) as _port`.
|
|
|
|
void rewriteEntityInAst(ASTPtr ast, const String & column_name, const Field & value, const String & func = "");
|
2014-02-08 16:49:45 +00:00
|
|
|
|
2021-03-03 08:36:20 +00:00
|
|
|
/// Prepare `expression_ast` to filter block. Returns true if `expression_ast` is not trimmed, that is,
|
2021-03-04 05:59:57 +00:00
|
|
|
/// `block` provides all needed columns for `expression_ast`, else return false.
|
2021-04-10 23:33:54 +00:00
|
|
|
bool prepareFilterBlockWithQuery(const ASTPtr & query, ContextPtr context, Block block, ASTPtr & expression_ast);
|
2021-03-03 08:36:20 +00:00
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/// Leave in the block only the rows that fit under the WHERE clause and the PREWHERE clause of the query.
|
|
|
|
/// Only elements of the outer conjunction are considered, depending only on the columns present in the block.
|
2021-03-03 08:36:20 +00:00
|
|
|
/// If `expression_ast` is passed, use it to filter block.
|
2021-04-10 23:33:54 +00:00
|
|
|
void filterBlockWithQuery(const ASTPtr & query, Block & block, ContextPtr context, ASTPtr expression_ast = {});
|
2014-01-17 15:19:20 +00:00
|
|
|
|
2017-05-07 20:25:26 +00:00
|
|
|
/// Extract from the input stream a set of `name` column values
|
2019-05-20 12:16:51 +00:00
|
|
|
template <typename T>
|
2020-09-25 08:38:09 +00:00
|
|
|
auto extractSingleValueFromBlock(const Block & block, const String & name)
|
2014-02-08 16:49:45 +00:00
|
|
|
{
|
2020-09-25 08:38:09 +00:00
|
|
|
std::unordered_set<T> res;
|
2015-07-17 01:27:35 +00:00
|
|
|
const ColumnWithTypeAndName & data = block.getByName(name);
|
2014-07-29 14:05:15 +00:00
|
|
|
size_t rows = block.rows();
|
|
|
|
for (size_t i = 0; i < rows; ++i)
|
2019-05-20 12:16:51 +00:00
|
|
|
res.insert((*data.column)[i].get<T>());
|
2014-02-08 16:49:45 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|