mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Applied clang-format #2272
This commit is contained in:
parent
723cc53948
commit
02f8757bef
@ -1,23 +1,20 @@
|
||||
#include <Common/Exception.h>
|
||||
#include <Interpreters/ExpressionActions.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Interpreters/ExpressionAnalyzer.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Interpreters/ProjectionManipulation.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Interpreters/ExpressionActions.h>
|
||||
#include <Interpreters/ExpressionAnalyzer.h>
|
||||
#include <Interpreters/ProjectionManipulation.h>
|
||||
#include <Common/Exception.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
namespace DB {
|
||||
namespace DB
|
||||
{
|
||||
ProjectionManipulatorBase::~ProjectionManipulatorBase() {}
|
||||
|
||||
ProjectionManipulatorBase::~ProjectionManipulatorBase()
|
||||
{}
|
||||
|
||||
DefaultProjectionManipulator::DefaultProjectionManipulator(ScopeStack & scopes)
|
||||
: scopes(scopes)
|
||||
{}
|
||||
DefaultProjectionManipulator::DefaultProjectionManipulator(ScopeStack & scopes) : scopes(scopes) {}
|
||||
|
||||
bool DefaultProjectionManipulator::tryToGetFromUpperProjection(const std::string & column_name)
|
||||
{
|
||||
@ -34,22 +31,19 @@ std::string DefaultProjectionManipulator::getProjectionExpression()
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string DefaultProjectionManipulator::getProjectionSourceColumn() const {
|
||||
std::string DefaultProjectionManipulator::getProjectionSourceColumn() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
ConditionalTree::Node::Node()
|
||||
: projection_expression_string(),
|
||||
parent_node(0),
|
||||
is_root(false)
|
||||
{}
|
||||
ConditionalTree::Node::Node() : projection_expression_string(), parent_node(0), is_root(false) {}
|
||||
|
||||
size_t ConditionalTree::Node::getParentNode() const
|
||||
{
|
||||
if (is_root)
|
||||
{
|
||||
throw Exception("Failed to get parent projection node of node " + projection_expression_string,
|
||||
ErrorCodes::CONDITIONAL_TREE_PARENT_NOT_FOUND);
|
||||
throw Exception(
|
||||
"Failed to get parent projection node of node " + projection_expression_string, ErrorCodes::CONDITIONAL_TREE_PARENT_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -75,22 +69,19 @@ std::string ConditionalTree::getColumnName(const std::string & col_name) const
|
||||
return getColumnNameByIndex(col_name, current_node);
|
||||
}
|
||||
|
||||
std::string ConditionalTree::getProjectionColumnName(const std::string & first_projection_expr,
|
||||
const std::string & second_projection_expr) const
|
||||
std::string ConditionalTree::getProjectionColumnName(
|
||||
const std::string & first_projection_expr, const std::string & second_projection_expr) const
|
||||
{
|
||||
return std::string("P<") + first_projection_expr + "><" + second_projection_expr + ">";
|
||||
}
|
||||
|
||||
std::string ConditionalTree::getProjectionColumnName(const size_t first_index, const size_t second_index) const
|
||||
{
|
||||
return getProjectionColumnName(
|
||||
nodes[first_index].projection_expression_string,
|
||||
nodes[second_index].projection_expression_string);
|
||||
return getProjectionColumnName(nodes[first_index].projection_expression_string, nodes[second_index].projection_expression_string);
|
||||
}
|
||||
|
||||
void ConditionalTree::buildProjectionCompositionRecursive(const std::vector<size_t> & path,
|
||||
const size_t child_index,
|
||||
const size_t parent_index)
|
||||
void ConditionalTree::buildProjectionCompositionRecursive(
|
||||
const std::vector<size_t> & path, const size_t child_index, const size_t parent_index)
|
||||
{
|
||||
std::string projection_name = getProjectionColumnName(path[parent_index], path[child_index]);
|
||||
if (parent_index - child_index >= 2 && !scopes.getSampleBlock().has(projection_name))
|
||||
@ -98,15 +89,12 @@ void ConditionalTree::buildProjectionCompositionRecursive(const std::vector<size
|
||||
size_t middle_index = (child_index + parent_index) / 2;
|
||||
buildProjectionCompositionRecursive(path, child_index, middle_index);
|
||||
buildProjectionCompositionRecursive(path, middle_index, parent_index);
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get(
|
||||
"__inner_build_projection_composition__", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(
|
||||
function_builder,
|
||||
{
|
||||
getProjectionColumnName(path[parent_index], path[middle_index]),
|
||||
getProjectionColumnName(path[middle_index], path[child_index])
|
||||
},
|
||||
projection_name, getProjectionSourceColumn()));
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("__inner_build_projection_composition__", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(function_builder,
|
||||
{getProjectionColumnName(path[parent_index], path[middle_index]),
|
||||
getProjectionColumnName(path[middle_index], path[child_index])},
|
||||
projection_name,
|
||||
getProjectionSourceColumn()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,7 +114,8 @@ void ConditionalTree::buildProjectionComposition(const size_t child_node, const
|
||||
buildProjectionCompositionRecursive(path, 0, path.size() - 1);
|
||||
}
|
||||
|
||||
std::string ConditionalTree::getProjectionSourceColumn(size_t node) const {
|
||||
std::string ConditionalTree::getProjectionSourceColumn(size_t node) const
|
||||
{
|
||||
if (nodes[node].is_root)
|
||||
{
|
||||
return "";
|
||||
@ -138,11 +127,7 @@ std::string ConditionalTree::getProjectionSourceColumn(size_t node) const {
|
||||
}
|
||||
|
||||
ConditionalTree::ConditionalTree(ScopeStack & scopes, const Context & context)
|
||||
: current_node(0),
|
||||
nodes(1),
|
||||
scopes(scopes),
|
||||
context(context),
|
||||
projection_expression_index()
|
||||
: current_node(0), nodes(1), scopes(scopes), context(context), projection_expression_index()
|
||||
{
|
||||
nodes[0].is_root = true;
|
||||
}
|
||||
@ -155,14 +140,16 @@ void ConditionalTree::goToProjection(const std::string & field_name)
|
||||
if (!scopes.getSampleBlock().has(projection_column_name))
|
||||
{
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("one_or_zero", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(function_builder, {getColumnName(field_name)}, projection_column_name,
|
||||
getProjectionSourceColumn()));
|
||||
scopes.addAction(ExpressionAction::applyFunction(
|
||||
function_builder, {getColumnName(field_name)}, projection_column_name, getProjectionSourceColumn()));
|
||||
nodes.emplace_back(Node());
|
||||
nodes.back().projection_expression_string = new_projection_name;
|
||||
nodes.back().parent_node = current_node;
|
||||
current_node = nodes.size() - 1;
|
||||
projection_expression_index[projection_column_name] = current_node;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
current_node = projection_expression_index[projection_column_name];
|
||||
}
|
||||
}
|
||||
@ -179,27 +166,20 @@ std::string ConditionalTree::buildRestoreProjectionAndGetName(const size_t level
|
||||
}
|
||||
|
||||
void ConditionalTree::restoreColumn(
|
||||
const std::string & default_values_name,
|
||||
const std::string & new_values_name,
|
||||
const size_t levels_up,
|
||||
const std::string & result_name
|
||||
)
|
||||
const std::string & default_values_name, const std::string & new_values_name, const size_t levels_up, const std::string & result_name)
|
||||
{
|
||||
size_t target_node = current_node;
|
||||
for (size_t i = 0; i < levels_up; ++i)
|
||||
{
|
||||
target_node = nodes[target_node].getParentNode();
|
||||
}
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("__inner_restore_projection__",
|
||||
context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(
|
||||
function_builder,
|
||||
{
|
||||
getProjectionColumnName(target_node, current_node),
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("__inner_restore_projection__", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(function_builder,
|
||||
{getProjectionColumnName(target_node, current_node),
|
||||
getColumnNameByIndex(default_values_name, current_node),
|
||||
getColumnNameByIndex(new_values_name, current_node)
|
||||
},
|
||||
getColumnNameByIndex(result_name, target_node), getProjectionSourceColumn()));
|
||||
getColumnNameByIndex(new_values_name, current_node)},
|
||||
getColumnNameByIndex(result_name, target_node),
|
||||
getProjectionSourceColumn()));
|
||||
}
|
||||
|
||||
void ConditionalTree::goUp(const size_t levels_up)
|
||||
@ -220,15 +200,11 @@ bool ConditionalTree::tryToGetFromUpperProjection(const std::string & column_nam
|
||||
if (node != current_node)
|
||||
{
|
||||
buildProjectionComposition(current_node, node);
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("__inner_project__",
|
||||
context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(
|
||||
function_builder,
|
||||
{
|
||||
getColumnNameByIndex(column_name, node),
|
||||
getProjectionColumnName(node, current_node)
|
||||
},
|
||||
getColumnName(column_name), getProjectionSourceColumn(node)));
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("__inner_project__", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(function_builder,
|
||||
{getColumnNameByIndex(column_name, node), getProjectionColumnName(node, current_node)},
|
||||
getColumnName(column_name),
|
||||
getProjectionSourceColumn(node)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -246,36 +222,32 @@ std::string ConditionalTree::getProjectionExpression()
|
||||
return nodes[current_node].projection_expression_string;
|
||||
}
|
||||
|
||||
std::string ConditionalTree::getProjectionSourceColumn() const {
|
||||
std::string ConditionalTree::getProjectionSourceColumn() const
|
||||
{
|
||||
return getProjectionSourceColumn(current_node);
|
||||
}
|
||||
|
||||
void DefaultProjectionAction::preArgumentAction()
|
||||
{}
|
||||
void DefaultProjectionAction::preArgumentAction() {}
|
||||
|
||||
void DefaultProjectionAction::postArgumentAction(const std::string & /*argument_name*/)
|
||||
{
|
||||
}
|
||||
void DefaultProjectionAction::postArgumentAction(const std::string & /*argument_name*/) {}
|
||||
|
||||
void DefaultProjectionAction::preCalculation()
|
||||
{}
|
||||
void DefaultProjectionAction::preCalculation() {}
|
||||
|
||||
bool DefaultProjectionAction::isCalculationRequired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AndOperatorProjectionAction::AndOperatorProjectionAction(ScopeStack & scopes,
|
||||
ProjectionManipulatorPtr projection_manipulator,
|
||||
const std::string & expression_name,
|
||||
const Context & context)
|
||||
: scopes(scopes),
|
||||
projection_manipulator(projection_manipulator),
|
||||
previous_argument_name(),
|
||||
projection_levels_count(0),
|
||||
expression_name(expression_name),
|
||||
context(context)
|
||||
{}
|
||||
AndOperatorProjectionAction::AndOperatorProjectionAction(
|
||||
ScopeStack & scopes, ProjectionManipulatorPtr projection_manipulator, const std::string & expression_name, const Context & context)
|
||||
: scopes(scopes)
|
||||
, projection_manipulator(projection_manipulator)
|
||||
, previous_argument_name()
|
||||
, projection_levels_count(0)
|
||||
, expression_name(expression_name)
|
||||
, context(context)
|
||||
{
|
||||
}
|
||||
|
||||
std::string AndOperatorProjectionAction::getZerosColumnName()
|
||||
{
|
||||
@ -292,9 +264,10 @@ void AndOperatorProjectionAction::createZerosColumn(const std::string & restore_
|
||||
auto zeros_column_name = projection_manipulator->getColumnName(getZerosColumnName());
|
||||
if (!scopes.getSampleBlock().has(zeros_column_name))
|
||||
{
|
||||
scopes.addAction(ExpressionAction::addColumn(ColumnWithTypeAndName(
|
||||
ColumnUInt8::create(0, 1), std::make_shared<DataTypeUInt8>(), zeros_column_name),
|
||||
restore_projection_name, true));
|
||||
scopes.addAction(ExpressionAction::addColumn(
|
||||
ColumnWithTypeAndName(ColumnUInt8::create(0, 1), std::make_shared<DataTypeUInt8>(), zeros_column_name),
|
||||
restore_projection_name,
|
||||
true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,7 +282,8 @@ void AndOperatorProjectionAction::preArgumentAction()
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Illegal projection manipulator used in AndOperatorProjectionAction", ErrorCodes::ILLEGAL_PROJECTION_MANIPULATOR);
|
||||
throw Exception(
|
||||
"Illegal projection manipulator used in AndOperatorProjectionAction", ErrorCodes::ILLEGAL_PROJECTION_MANIPULATOR);
|
||||
}
|
||||
++projection_levels_count;
|
||||
}
|
||||
@ -326,17 +300,13 @@ void AndOperatorProjectionAction::preCalculation()
|
||||
{
|
||||
auto final_column = getFinalColumnName();
|
||||
const FunctionBuilderPtr & function_builder = FunctionFactory::instance().get("one_or_zero", context);
|
||||
scopes.addAction(ExpressionAction::applyFunction(
|
||||
function_builder,
|
||||
{
|
||||
projection_manipulator->getColumnName(previous_argument_name)
|
||||
},
|
||||
projection_manipulator->getColumnName(final_column),
|
||||
projection_manipulator->getProjectionSourceColumn()));
|
||||
scopes.addAction(ExpressionAction::applyFunction(function_builder,
|
||||
{projection_manipulator->getColumnName(previous_argument_name)},
|
||||
projection_manipulator->getColumnName(final_column),
|
||||
projection_manipulator->getProjectionSourceColumn()));
|
||||
std::string restore_projection_name = conditional_tree->buildRestoreProjectionAndGetName(projection_levels_count);
|
||||
createZerosColumn(restore_projection_name);
|
||||
conditional_tree->restoreColumn(getZerosColumnName(), final_column,
|
||||
projection_levels_count, expression_name);
|
||||
conditional_tree->restoreColumn(getZerosColumnName(), final_column, projection_levels_count, expression_name);
|
||||
conditional_tree->goUp(projection_levels_count);
|
||||
}
|
||||
else
|
||||
@ -350,14 +320,13 @@ bool AndOperatorProjectionAction::isCalculationRequired()
|
||||
return false;
|
||||
}
|
||||
|
||||
ProjectionActionBase::~ProjectionActionBase()
|
||||
{}
|
||||
ProjectionActionBase::~ProjectionActionBase() {}
|
||||
|
||||
ProjectionActionPtr getProjectionAction(const std::string & node_name,
|
||||
ScopeStack & scopes,
|
||||
ProjectionManipulatorPtr projection_manipulator,
|
||||
const std::string & expression_name,
|
||||
const Context & context)
|
||||
ScopeStack & scopes,
|
||||
ProjectionManipulatorPtr projection_manipulator,
|
||||
const std::string & expression_name,
|
||||
const Context & context)
|
||||
{
|
||||
if (typeid_cast<ConditionalTree *>(projection_manipulator.get()) && node_name == "and")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user