| 1 | #pragma once |
| 2 | |
| 3 | #include <set> |
| 4 | |
| 5 | #include <Core/Block.h> |
| 6 | #include <Parsers/IAST_fwd.h> |
| 7 | |
| 8 | |
| 9 | namespace DB |
| 10 | { |
| 11 | |
| 12 | class Context; |
| 13 | class NamesAndTypesList; |
| 14 | |
| 15 | |
| 16 | namespace VirtualColumnUtils |
| 17 | { |
| 18 | |
| 19 | /// Adds to the select query section `WITH value AS column_name`, and uses func |
| 20 | /// to wrap the value (if any) |
| 21 | /// |
| 22 | /// For example: |
| 23 | /// - `WITH 9000 as _port`. |
| 24 | /// - `WITH toUInt16(9000) as _port`. |
| 25 | void rewriteEntityInAst(ASTPtr ast, const String & column_name, const Field & value, const String & func = "" ); |
| 26 | |
| 27 | /// Leave in the block only the rows that fit under the WHERE clause and the PREWHERE clause of the query. |
| 28 | /// Only elements of the outer conjunction are considered, depending only on the columns present in the block. |
| 29 | /// Returns true if at least one row is discarded. |
| 30 | void filterBlockWithQuery(const ASTPtr & query, Block & block, const Context & context); |
| 31 | |
| 32 | /// Extract from the input stream a set of `name` column values |
| 33 | template <typename T> |
| 34 | std::multiset<T> extractSingleValueFromBlock(const Block & block, const String & name) |
| 35 | { |
| 36 | std::multiset<T> res; |
| 37 | const ColumnWithTypeAndName & data = block.getByName(name); |
| 38 | size_t rows = block.rows(); |
| 39 | for (size_t i = 0; i < rows; ++i) |
| 40 | res.insert((*data.column)[i].get<T>()); |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | |
| 46 | } |
| 47 | |