2014-01-17 15:19:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-12-30 18:04:53 +00:00
|
|
|
#include <set>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Parsers/IAST.h>
|
2014-12-30 18:04:53 +00:00
|
|
|
|
2014-01-17 15:19:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2014-12-30 18:04:53 +00:00
|
|
|
class Context;
|
2017-05-23 18:01:50 +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
|
|
|
|
2017-05-10 04:00:19 +00:00
|
|
|
/// Calculate the minimum numeric suffix to add to the string so that it is not present in the set
|
2014-02-26 10:59:56 +00:00
|
|
|
String chooseSuffix(const NamesAndTypesList & columns, const String & name);
|
2014-01-17 15:19:20 +00:00
|
|
|
|
2017-05-10 04:00:19 +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.
|
2014-02-26 10:59:56 +00:00
|
|
|
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.
|
2014-02-26 10:59:56 +00:00
|
|
|
void rewriteEntityInAst(ASTPtr ast, const String & column_name, const Field & value);
|
2014-02-08 16:49:45 +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.
|
|
|
|
/// 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>
|
2014-07-29 14:05:15 +00:00
|
|
|
std::multiset<T1> extractSingleValueFromBlock(const Block & block, const String & name)
|
2014-02-08 16:49:45 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
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;
|
2014-02-08 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|