ClickHouse/src/Storages/VirtualColumnUtils.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.6 KiB
C++
Raw Normal View History

2014-01-17 15:19:20 +00:00
#pragma once
#include <Core/Block.h>
#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>
#include <unordered_set>
2014-01-17 15:19:20 +00:00
namespace DB
{
class NamesAndTypesList;
namespace VirtualColumnUtils
2014-01-17 15:19:20 +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 = "");
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.
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.
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>
auto extractSingleValueFromBlock(const Block & block, const String & name)
{
std::unordered_set<T> res;
const ColumnWithTypeAndName & data = block.getByName(name);
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>());
return res;
}
}
}