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>
|
2019-05-20 12:16:51 +00:00
|
|
|
#include <Parsers/IAST_fwd.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-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
|
|
|
|
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.
|
2018-02-21 19:42:42 +00:00
|
|
|
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)
|
2014-02-08 16:49:45 +00:00
|
|
|
{
|
2019-05-20 12:16:51 +00:00
|
|
|
std::multiset<T> res;
|
2017-04-01 07:20:54 +00:00
|
|
|
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>());
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2014-02-08 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|