Applied clang-format #2272

This commit is contained in:
Alexey Milovidov 2018-05-07 05:06:55 +03:00
parent e26abf0ab4
commit 1dc1ccc1d8
3 changed files with 59 additions and 49 deletions

View File

@ -1,10 +1,10 @@
#include <Functions/FunctionsProjection.h>
#include <DataTypes/DataTypesNumber.h>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <DataTypes/DataTypesNumber.h>
#include <Functions/FunctionsProjection.h>
namespace DB { namespace DB
{
FunctionPtr FunctionOneOrZero::create(const Context &) FunctionPtr FunctionOneOrZero::create(const Context &)
{ {
return std::make_shared<FunctionOneOrZero>(); return std::make_shared<FunctionOneOrZero>();
@ -64,8 +64,8 @@ DataTypePtr FunctionProject::getReturnTypeImpl(const DataTypes & arguments) cons
{ {
if (!checkAndGetDataType<DataTypeUInt8>(arguments[1].get())) if (!checkAndGetDataType<DataTypeUInt8>(arguments[1].get()))
{ {
throw Exception("Illegal type " + arguments[1]->getName() + " of 2nd argument of function " + getName(), throw Exception(
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); "Illegal type " + arguments[1]->getName() + " of 2nd argument of function " + getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
} }
return arguments[0]; return arguments[0];
} }
@ -116,14 +116,16 @@ DataTypePtr FunctionBuildProjectionComposition::getReturnTypeImpl(const DataType
{ {
if (!checkAndGetDataType<DataTypeUInt8>(arguments[i].get())) if (!checkAndGetDataType<DataTypeUInt8>(arguments[i].get()))
{ {
throw Exception("Illegal type " + arguments[i]->getName() + " of " + std::to_string(i + 1) + " argument of function " + getName(), throw Exception(
"Illegal type " + arguments[i]->getName() + " of " + std::to_string(i + 1) + " argument of function " + getName(),
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
} }
} }
return std::make_shared<DataTypeUInt8>(); return std::make_shared<DataTypeUInt8>();
} }
void FunctionBuildProjectionComposition::executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) void FunctionBuildProjectionComposition::executeImpl(
Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/)
{ {
const auto & first_projection_column = block.getByPosition(arguments[0]).column; const auto & first_projection_column = block.getByPosition(arguments[0]).column;
const auto & second_projection_column = block.getByPosition(arguments[1]).column; const auto & second_projection_column = block.getByPosition(arguments[1]).column;
@ -145,8 +147,8 @@ void FunctionBuildProjectionComposition::executeImpl(Block & block, const Column
} }
if (current_reserve_index != second_projection_column->size()) if (current_reserve_index != second_projection_column->size())
{ {
throw Exception("Second argument size is not appropriate: " + std::to_string(second_projection_column->size()) throw Exception("Second argument size is not appropriate: " + std::to_string(second_projection_column->size()) + " instead of "
+ " instead of " + std::to_string(current_reserve_index), + std::to_string(current_reserve_index),
ErrorCodes::BAD_ARGUMENTS); ErrorCodes::BAD_ARGUMENTS);
} }
block.getByPosition(result).column = std::move(col_res); block.getByPosition(result).column = std::move(col_res);
@ -162,7 +164,8 @@ String FunctionRestoreProjection::getName() const
return name; return name;
} }
bool FunctionRestoreProjection::isVariadic() const { bool FunctionRestoreProjection::isVariadic() const
{
return true; return true;
} }

View File

@ -3,13 +3,14 @@
#include <Functions/IFunction.h> #include <Functions/IFunction.h>
#include "FunctionsConversion.h" #include "FunctionsConversion.h"
namespace DB { namespace DB
{
/* /*
* This function accepts one column and converts it to UInt8, replacing values, which evaluate to true, with 1, and values, * This function accepts one column and converts it to UInt8, replacing values, which evaluate to true, with 1, and values,
* which evaluate to false with 0 * which evaluate to false with 0
*/ */
class FunctionOneOrZero final : public IFunction { class FunctionOneOrZero final : public IFunction
{
public: public:
static constexpr auto name = "one_or_zero"; static constexpr auto name = "one_or_zero";
static FunctionPtr create(const Context &); static FunctionPtr create(const Context &);
@ -25,7 +26,8 @@ public:
* This function builds a column of a smaller, which contains values of the data column at the positions where * This function builds a column of a smaller, which contains values of the data column at the positions where
* the projection column contained 1. The size of result column equals the count of ones in the projection column. * the projection column contained 1. The size of result column equals the count of ones in the projection column.
*/ */
class FunctionProject final : public IFunction { class FunctionProject final : public IFunction
{
public: public:
static constexpr auto name = "__inner_project__"; static constexpr auto name = "__inner_project__";
static FunctionPtr create(const Context &); static FunctionPtr create(const Context &);
@ -39,7 +41,8 @@ public:
* FunctionBuildProjectionComposition constructs the composition of two projection columns. The size of * FunctionBuildProjectionComposition constructs the composition of two projection columns. The size of
* second projection column should equal the count of ones in the first input projection column. * second projection column should equal the count of ones in the first input projection column.
*/ */
class FunctionBuildProjectionComposition final : public IFunction { class FunctionBuildProjectionComposition final : public IFunction
{
public: public:
static constexpr auto name = "__inner_build_projection_composition__"; static constexpr auto name = "__inner_build_projection_composition__";
static FunctionPtr create(const Context &); static FunctionPtr create(const Context &);
@ -53,7 +56,8 @@ public:
* Accepts mapping column with values from range [0, N) and N more columns as arguments. * Accepts mapping column with values from range [0, N) and N more columns as arguments.
* Forms a column by taking value from column, which number is in the mapping column. * Forms a column by taking value from column, which number is in the mapping column.
*/ */
class FunctionRestoreProjection final : public IFunction { class FunctionRestoreProjection final : public IFunction
{
public: public:
static constexpr auto name = "__inner_restore_projection__"; static constexpr auto name = "__inner_restore_projection__";
static FunctionPtr create(const Context &); static FunctionPtr create(const Context &);

View File

@ -3,21 +3,23 @@
#include <string> #include <string>
#include <Interpreters/ExpressionAnalyzer.h> #include <Interpreters/ExpressionAnalyzer.h>
namespace DB { namespace DB
{
class ExpressionAnalyzer; class ExpressionAnalyzer;
struct ScopeStack; struct ScopeStack;
namespace ErrorCodes { namespace ErrorCodes
extern const int CONDITIONAL_TREE_PARENT_NOT_FOUND; {
extern const int ILLEGAL_PROJECTION_MANIPULATOR; extern const int CONDITIONAL_TREE_PARENT_NOT_FOUND;
extern const int ILLEGAL_PROJECTION_MANIPULATOR;
} }
/* /*
* This is a base class for the ConditionalTree. Look at the description of ConditionalTree. * This is a base class for the ConditionalTree. Look at the description of ConditionalTree.
*/ */
struct ProjectionManipulatorBase { struct ProjectionManipulatorBase
{
public: public:
virtual bool tryToGetFromUpperProjection(const std::string & column_name) = 0; virtual bool tryToGetFromUpperProjection(const std::string & column_name) = 0;
@ -37,9 +39,11 @@ using ProjectionManipulatorPtr = std::shared_ptr<ProjectionManipulatorBase>;
* For the better understanding of what ProjectionManipulator does, * For the better understanding of what ProjectionManipulator does,
* look at the description of ConditionalTree. * look at the description of ConditionalTree.
*/ */
struct DefaultProjectionManipulator : public ProjectionManipulatorBase { struct DefaultProjectionManipulator : public ProjectionManipulatorBase
{
private: private:
ScopeStack & scopes; ScopeStack & scopes;
public: public:
explicit DefaultProjectionManipulator(ScopeStack & scopes); explicit DefaultProjectionManipulator(ScopeStack & scopes);
@ -86,9 +90,11 @@ public:
* understand whether we need to scan the expression deeply, or can it be easily computed just with the projection * understand whether we need to scan the expression deeply, or can it be easily computed just with the projection
* from one of the higher projection layers. * from one of the higher projection layers.
*/ */
struct ConditionalTree : public ProjectionManipulatorBase { struct ConditionalTree : public ProjectionManipulatorBase
{
private: private:
struct Node { struct Node
{
Node(); Node();
size_t getParentNode() const; size_t getParentNode() const;
@ -103,21 +109,20 @@ private:
ScopeStack & scopes; ScopeStack & scopes;
const Context & context; const Context & context;
std::unordered_map<std::string, size_t> projection_expression_index; std::unordered_map<std::string, size_t> projection_expression_index;
private: private:
std::string getColumnNameByIndex(const std::string & col_name, size_t node) const; std::string getColumnNameByIndex(const std::string & col_name, size_t node) const;
std::string getProjectionColumnName(const std::string & first_projection_expr, std::string getProjectionColumnName(const std::string & first_projection_expr, const std::string & second_projection_expr) const;
const std::string & second_projection_expr) const;
std::string getProjectionColumnName(size_t first_index, size_t second_index) const; std::string getProjectionColumnName(size_t first_index, size_t second_index) const;
void buildProjectionCompositionRecursive(const std::vector<size_t> & path, void buildProjectionCompositionRecursive(const std::vector<size_t> & path, size_t child_index, size_t parent_index);
size_t child_index,
size_t parent_index);
void buildProjectionComposition(size_t child_node, size_t parent_node); void buildProjectionComposition(size_t child_node, size_t parent_node);
std::string getProjectionSourceColumn(size_t node) const; std::string getProjectionSourceColumn(size_t node) const;
public: public:
ConditionalTree(ScopeStack & scopes, const Context & context); ConditionalTree(ScopeStack & scopes, const Context & context);
@ -128,11 +133,7 @@ public:
std::string buildRestoreProjectionAndGetName(size_t levels_up); std::string buildRestoreProjectionAndGetName(size_t levels_up);
void restoreColumn( void restoreColumn(
const std::string & default_values_name, const std::string & default_values_name, const std::string & new_values_name, size_t levels_up, const std::string & result_name);
const std::string & new_values_name,
size_t levels_up,
const std::string & result_name
);
void goUp(size_t levels_up); void goUp(size_t levels_up);
@ -150,7 +151,8 @@ using ConditionalTreePtr = std::shared_ptr<ConditionalTree>;
* This class has two inherited classes: DefaultProjectionAction, which does nothing, and AndOperatorProjectionAction, * This class has two inherited classes: DefaultProjectionAction, which does nothing, and AndOperatorProjectionAction,
* which represents how function "and" uses projection manipulator. * which represents how function "and" uses projection manipulator.
*/ */
class ProjectionActionBase { class ProjectionActionBase
{
public: public:
/* /*
* What to do before scanning the function argument (each of it) * What to do before scanning the function argument (each of it)
@ -177,7 +179,8 @@ public:
using ProjectionActionPtr = std::shared_ptr<ProjectionActionBase>; using ProjectionActionPtr = std::shared_ptr<ProjectionActionBase>;
class DefaultProjectionAction : public ProjectionActionBase { class DefaultProjectionAction : public ProjectionActionBase
{
public: public:
void preArgumentAction() final; void preArgumentAction() final;
@ -191,7 +194,8 @@ public:
/* /*
* This is a specification of ProjectionAction specifically for the 'and' operation * This is a specification of ProjectionAction specifically for the 'and' operation
*/ */
class AndOperatorProjectionAction : public ProjectionActionBase { class AndOperatorProjectionAction : public ProjectionActionBase
{
private: private:
ScopeStack & scopes; ScopeStack & scopes;
ProjectionManipulatorPtr projection_manipulator; ProjectionManipulatorPtr projection_manipulator;
@ -205,11 +209,10 @@ private:
std::string getFinalColumnName(); std::string getFinalColumnName();
void createZerosColumn(const std::string & restore_projection_name); void createZerosColumn(const std::string & restore_projection_name);
public: public:
AndOperatorProjectionAction(ScopeStack & scopes, AndOperatorProjectionAction(
ProjectionManipulatorPtr projection_manipulator, ScopeStack & scopes, ProjectionManipulatorPtr projection_manipulator, const std::string & expression_name, const Context & context);
const std::string & expression_name,
const Context& context);
/* /*
* Before scanning each argument, we should go to the next projection layer. For example, if the expression is * Before scanning each argument, we should go to the next projection layer. For example, if the expression is