ClickHouse/dbms/src/Storages/VirtualColumnUtils.h

50 lines
1.5 KiB
C++
Raw Normal View History

2014-01-17 15:19:20 +00:00
#pragma once
#include <set>
#include <Core/Block.h>
#include <Parsers/IAST.h>
2014-01-17 15:19:20 +00:00
namespace DB
{
class Context;
2017-05-23 18:01:50 +00:00
class NamesAndTypesList;
namespace VirtualColumnUtils
2014-01-17 15:19:20 +00:00
{
/// Calculate the minimum numeric suffix to add to the string so that it is not present in the set
String chooseSuffix(const NamesAndTypesList & columns, const String & name);
2014-01-17 15:19:20 +00:00
/// Calculate the minimum total numeric suffix to add to each string,
2017-05-07 20:25:26 +00:00
/// so that none is present in the set.
String chooseSuffixForSet(const NamesAndTypesList & columns, const std::vector<String> & names);
2014-01-17 15:19:20 +00:00
2017-05-07 20:25:26 +00:00
/// Adds to the select query section `select column_name as value`
/// For example select _port as 9000.
void rewriteEntityInAst(ASTPtr ast, const String & column_name, const Field & value);
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.
2017-05-23 18:01:50 +00:00
bool 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
2017-05-23 18:01:50 +00:00
template <typename T1>
std::multiset<T1> extractSingleValueFromBlock(const Block & block, const String & name)
{
std::multiset<T1> res;
const ColumnWithTypeAndName & data = block.getByName(name);
size_t rows = block.rows();
for (size_t i = 0; i < rows; ++i)
res.insert((*data.column)[i].get<T1>());
return res;
}
}
}