ClickHouse/dbms/src/Storages/VirtualColumnUtils.h

47 lines
1.2 KiB
C++
Raw Normal View History

2014-01-17 15:19:20 +00:00
#pragma once
#include <set>
#include <Core/Block.h>
2019-05-20 12:16:51 +00:00
#include <Parsers/IAST_fwd.h>
2014-01-17 15:19:20 +00:00
namespace DB
{
class Context;
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 = "");
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.
/// Returns true if at least one row is discarded.
void filterBlockWithQuery(const ASTPtr & query, Block & block, const Context & context);
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>
std::multiset<T> extractSingleValueFromBlock(const Block & block, const String & name)
{
2019-05-20 12:16:51 +00:00
std::multiset<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;
}
}
}