Cleanup code

This commit is contained in:
Dmitry Novik 2022-11-30 18:48:09 +00:00
parent 4d5868d05d
commit 15b8c48ca9
21 changed files with 39 additions and 40 deletions

View File

@ -74,7 +74,7 @@ namespace
/// groupBitmap needs to know about the data type that was used to create bitmaps. /// groupBitmap needs to know about the data type that was used to create bitmaps.
/// We need to look inside the type of its argument to obtain it. /// We need to look inside the type of its argument to obtain it.
const DataTypeAggregateFunction & datatype_aggfunc = dynamic_cast<const DataTypeAggregateFunction &>(*argument_type_ptr); const DataTypeAggregateFunction & datatype_aggfunc = dynamic_cast<const DataTypeAggregateFunction &>(*argument_type_ptr);
ConstAggregateFunctionPtr aggfunc = datatype_aggfunc.getFunction(); AggregateFunctionPtr aggfunc = datatype_aggfunc.getFunction();
if (aggfunc->getName() != AggregateFunctionGroupBitmapData<UInt8>::name()) if (aggfunc->getName() != AggregateFunctionGroupBitmapData<UInt8>::name())
throw Exception( throw Exception(

View File

@ -49,8 +49,7 @@ using AggregateDataPtr = char *;
using ConstAggregateDataPtr = const char *; using ConstAggregateDataPtr = const char *;
class IAggregateFunction; class IAggregateFunction;
using AggregateFunctionPtr = std::shared_ptr<IAggregateFunction>; using AggregateFunctionPtr = std::shared_ptr<const IAggregateFunction>;
using ConstAggregateFunctionPtr = std::shared_ptr<const IAggregateFunction>;
struct AggregateFunctionProperties; struct AggregateFunctionProperties;

View File

@ -40,12 +40,12 @@ ColumnsWithTypeAndName FunctionNode::getArgumentTypes() const
FunctionBasePtr FunctionNode::getFunction() const FunctionBasePtr FunctionNode::getFunction() const
{ {
return std::dynamic_pointer_cast<IFunctionBase>(function); return std::dynamic_pointer_cast<const IFunctionBase>(function);
} }
AggregateFunctionPtr FunctionNode::getAggregateFunction() const AggregateFunctionPtr FunctionNode::getAggregateFunction() const
{ {
return std::dynamic_pointer_cast<IAggregateFunction>(function); return std::dynamic_pointer_cast<const IAggregateFunction>(function);
} }
bool FunctionNode::isAggregateFunction() const bool FunctionNode::isAggregateFunction() const

View File

@ -15,10 +15,10 @@ class IFunctionOverloadResolver;
using FunctionOverloadResolverPtr = std::shared_ptr<IFunctionOverloadResolver>; using FunctionOverloadResolverPtr = std::shared_ptr<IFunctionOverloadResolver>;
class IFunctionBase; class IFunctionBase;
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
class IAggregateFunction; class IAggregateFunction;
using AggregateFunctionPtr = std::shared_ptr<IAggregateFunction>; using AggregateFunctionPtr = std::shared_ptr<const IAggregateFunction>;
/** Function node represents function in query tree. /** Function node represents function in query tree.
* Function syntax: function_name(parameter_1, ...)(argument_1, ...). * Function syntax: function_name(parameter_1, ...)(argument_1, ...).

View File

@ -28,7 +28,7 @@ namespace ErrorCodes
} }
static String getTypeString(const ConstAggregateFunctionPtr & func, std::optional<size_t> version = std::nullopt) static String getTypeString(const AggregateFunctionPtr & func, std::optional<size_t> version = std::nullopt)
{ {
WriteBufferFromOwnString stream; WriteBufferFromOwnString stream;
@ -62,18 +62,18 @@ static String getTypeString(const ConstAggregateFunctionPtr & func, std::optiona
} }
ColumnAggregateFunction::ColumnAggregateFunction(const ConstAggregateFunctionPtr & func_, std::optional<size_t> version_) ColumnAggregateFunction::ColumnAggregateFunction(const AggregateFunctionPtr & func_, std::optional<size_t> version_)
: func(func_), type_string(getTypeString(func, version_)), version(version_) : func(func_), type_string(getTypeString(func, version_)), version(version_)
{ {
} }
ColumnAggregateFunction::ColumnAggregateFunction(const ConstAggregateFunctionPtr & func_, const ConstArenas & arenas_) ColumnAggregateFunction::ColumnAggregateFunction(const AggregateFunctionPtr & func_, const ConstArenas & arenas_)
: foreign_arenas(arenas_), func(func_), type_string(getTypeString(func)) : foreign_arenas(arenas_), func(func_), type_string(getTypeString(func))
{ {
} }
void ColumnAggregateFunction::set(const ConstAggregateFunctionPtr & func_, size_t version_) void ColumnAggregateFunction::set(const AggregateFunctionPtr & func_, size_t version_)
{ {
func = func_; func = func_;
version = version_; version = version_;

View File

@ -70,7 +70,7 @@ private:
ArenaPtr my_arena; ArenaPtr my_arena;
/// Used for destroying states and for finalization of values. /// Used for destroying states and for finalization of values.
ConstAggregateFunctionPtr func; AggregateFunctionPtr func;
/// Source column. Used (holds source from destruction), /// Source column. Used (holds source from destruction),
/// if this column has been constructed from another and uses all or part of its values. /// if this column has been constructed from another and uses all or part of its values.
@ -92,9 +92,9 @@ private:
/// Create a new column that has another column as a source. /// Create a new column that has another column as a source.
MutablePtr createView() const; MutablePtr createView() const;
explicit ColumnAggregateFunction(const ConstAggregateFunctionPtr & func_, std::optional<size_t> version_ = std::nullopt); explicit ColumnAggregateFunction(const AggregateFunctionPtr & func_, std::optional<size_t> version_ = std::nullopt);
ColumnAggregateFunction(const ConstAggregateFunctionPtr & func_, const ConstArenas & arenas_); ColumnAggregateFunction(const AggregateFunctionPtr & func_, const ConstArenas & arenas_);
ColumnAggregateFunction(const ColumnAggregateFunction & src_); ColumnAggregateFunction(const ColumnAggregateFunction & src_);
@ -103,10 +103,10 @@ private:
public: public:
~ColumnAggregateFunction() override; ~ColumnAggregateFunction() override;
void set(const ConstAggregateFunctionPtr & func_, size_t version_); void set(const AggregateFunctionPtr & func_, size_t version_);
ConstAggregateFunctionPtr getAggregateFunction() { return func; } AggregateFunctionPtr getAggregateFunction() { return func; }
ConstAggregateFunctionPtr getAggregateFunction() const { return func; } AggregateFunctionPtr getAggregateFunction() const { return func; }
/// If we have another column as a source (owner of data), copy all data to ourself and reset source. /// If we have another column as a source (owner of data), copy all data to ourself and reset source.
/// This is needed before inserting new elements, because we must own these elements (to destroy them in destructor), /// This is needed before inserting new elements, because we must own these elements (to destroy them in destructor),

View File

@ -13,7 +13,7 @@ namespace ErrorCodes
} }
class IFunctionBase; class IFunctionBase;
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
/** A column containing a lambda expression. /** A column containing a lambda expression.
* Behaves like a constant-column. Contains an expression, but not input or output data. * Behaves like a constant-column. Contains an expression, but not input or output data.

View File

@ -24,6 +24,6 @@ public:
virtual ~IResolvedFunction() = default; virtual ~IResolvedFunction() = default;
}; };
using IResolvedFunctionPtr = std::shared_ptr<IResolvedFunction>; using IResolvedFunctionPtr = std::shared_ptr<const IResolvedFunction>;
} }

View File

@ -19,7 +19,7 @@ namespace DB
class DataTypeAggregateFunction final : public IDataType class DataTypeAggregateFunction final : public IDataType
{ {
private: private:
ConstAggregateFunctionPtr function; AggregateFunctionPtr function;
DataTypes argument_types; DataTypes argument_types;
Array parameters; Array parameters;
mutable std::optional<size_t> version; mutable std::optional<size_t> version;
@ -30,7 +30,7 @@ private:
public: public:
static constexpr bool is_parametric = true; static constexpr bool is_parametric = true;
DataTypeAggregateFunction(ConstAggregateFunctionPtr function_, const DataTypes & argument_types_, DataTypeAggregateFunction(AggregateFunctionPtr function_, const DataTypes & argument_types_,
const Array & parameters_, std::optional<size_t> version_ = std::nullopt) const Array & parameters_, std::optional<size_t> version_ = std::nullopt)
: function(std::move(function_)) : function(std::move(function_))
, argument_types(argument_types_) , argument_types(argument_types_)
@ -40,7 +40,7 @@ public:
} }
String getFunctionName() const { return function->getName(); } String getFunctionName() const { return function->getName(); }
ConstAggregateFunctionPtr getFunction() const { return function; } AggregateFunctionPtr getFunction() const { return function; }
String doGetName() const override; String doGetName() const override;
String getNameWithoutVersion() const; String getNameWithoutVersion() const;

View File

@ -108,14 +108,14 @@ void SerializationAggregateFunction::deserializeBinaryBulk(IColumn & column, Rea
} }
} }
static String serializeToString(const ConstAggregateFunctionPtr & function, const IColumn & column, size_t row_num, size_t version) static String serializeToString(const AggregateFunctionPtr & function, const IColumn & column, size_t row_num, size_t version)
{ {
WriteBufferFromOwnString buffer; WriteBufferFromOwnString buffer;
function->serialize(assert_cast<const ColumnAggregateFunction &>(column).getData()[row_num], buffer, version); function->serialize(assert_cast<const ColumnAggregateFunction &>(column).getData()[row_num], buffer, version);
return buffer.str(); return buffer.str();
} }
static void deserializeFromString(const ConstAggregateFunctionPtr & function, IColumn & column, const String & s, size_t version) static void deserializeFromString(const AggregateFunctionPtr & function, IColumn & column, const String & s, size_t version)
{ {
ColumnAggregateFunction & column_concrete = assert_cast<ColumnAggregateFunction &>(column); ColumnAggregateFunction & column_concrete = assert_cast<ColumnAggregateFunction &>(column);

View File

@ -11,14 +11,14 @@ namespace DB
class SerializationAggregateFunction final : public ISerialization class SerializationAggregateFunction final : public ISerialization
{ {
private: private:
ConstAggregateFunctionPtr function; AggregateFunctionPtr function;
String type_name; String type_name;
size_t version; size_t version;
public: public:
static constexpr bool is_parametric = true; static constexpr bool is_parametric = true;
SerializationAggregateFunction(const ConstAggregateFunctionPtr & function_, String type_name_, size_t version_) SerializationAggregateFunction(const AggregateFunctionPtr & function_, String type_name_, size_t version_)
: function(function_), type_name(std::move(type_name_)), version(version_) {} : function(function_), type_name(std::move(type_name_)), version(version_) {}
/// NOTE These two functions for serializing single values are incompatible with the functions below. /// NOTE These two functions for serializing single values are incompatible with the functions below.

View File

@ -1736,7 +1736,7 @@ namespace
} }
const std::shared_ptr<const DataTypeAggregateFunction> aggregate_function_data_type; const std::shared_ptr<const DataTypeAggregateFunction> aggregate_function_data_type;
ConstAggregateFunctionPtr aggregate_function; AggregateFunctionPtr aggregate_function;
String text_buffer; String text_buffer;
}; };

View File

@ -895,7 +895,7 @@ class FunctionBinaryArithmetic : public IFunction
const ColumnAggregateFunction & column = typeid_cast<const ColumnAggregateFunction &>( const ColumnAggregateFunction & column = typeid_cast<const ColumnAggregateFunction &>(
agg_state_is_const ? assert_cast<const ColumnConst &>(agg_state_column).getDataColumn() : agg_state_column); agg_state_is_const ? assert_cast<const ColumnConst &>(agg_state_column).getDataColumn() : agg_state_column);
ConstAggregateFunctionPtr function = column.getAggregateFunction(); AggregateFunctionPtr function = column.getAggregateFunction();
size_t size = agg_state_is_const ? 1 : input_rows_count; size_t size = agg_state_is_const ? 1 : input_rows_count;
@ -960,7 +960,7 @@ class FunctionBinaryArithmetic : public IFunction
const ColumnAggregateFunction & rhs = typeid_cast<const ColumnAggregateFunction &>( const ColumnAggregateFunction & rhs = typeid_cast<const ColumnAggregateFunction &>(
rhs_is_const ? assert_cast<const ColumnConst &>(rhs_column).getDataColumn() : rhs_column); rhs_is_const ? assert_cast<const ColumnConst &>(rhs_column).getDataColumn() : rhs_column);
ConstAggregateFunctionPtr function = lhs.getAggregateFunction(); AggregateFunctionPtr function = lhs.getAggregateFunction();
size_t size = (lhs_is_const && rhs_is_const) ? 1 : input_rows_count; size_t size = (lhs_is_const && rhs_is_const) ? 1 : input_rows_count;

View File

@ -285,7 +285,7 @@ public:
}; };
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
/** Creates IFunctionBase from argument types list (chooses one function overload). /** Creates IFunctionBase from argument types list (chooses one function overload).

View File

@ -91,7 +91,7 @@ public:
if (arguments.size() == 2) if (arguments.size() == 2)
column_with_groups = arguments[1].column; column_with_groups = arguments[1].column;
ConstAggregateFunctionPtr aggregate_function_ptr = column_with_states->getAggregateFunction(); AggregateFunctionPtr aggregate_function_ptr = column_with_states->getAggregateFunction();
const IAggregateFunction & agg_func = *aggregate_function_ptr; const IAggregateFunction & agg_func = *aggregate_function_ptr;
AlignedBuffer place(agg_func.sizeOfData(), agg_func.alignOfData()); AlignedBuffer place(agg_func.sizeOfData(), agg_func.alignOfData());

View File

@ -17,7 +17,7 @@ class IExecutableFunction;
using ExecutableFunctionPtr = std::shared_ptr<IExecutableFunction>; using ExecutableFunctionPtr = std::shared_ptr<IExecutableFunction>;
class IFunctionBase; class IFunctionBase;
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
class IFunctionOverloadResolver; class IFunctionOverloadResolver;
using FunctionOverloadResolverPtr = std::shared_ptr<IFunctionOverloadResolver>; using FunctionOverloadResolverPtr = std::shared_ptr<IFunctionOverloadResolver>;

View File

@ -263,7 +263,7 @@ public:
return result; return result;
} }
static void applyFunction(IFunctionBase & function, Field & value) static void applyFunction(const IFunctionBase & function, Field & value)
{ {
const auto & type = function.getArgumentTypes().at(0); const auto & type = function.getArgumentTypes().at(0);
ColumnsWithTypeAndName args{{type->createColumnConst(1, value), type, "x" }}; ColumnsWithTypeAndName args{{type->createColumnConst(1, value), type, "x" }};

View File

@ -18,7 +18,7 @@ struct Range;
class Context; class Context;
class IFunctionBase; class IFunctionBase;
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
class Chunk; class Chunk;

View File

@ -945,7 +945,7 @@ bool KeyCondition::transformConstantWithValidFunctions(
DataTypePtr & out_key_column_type, DataTypePtr & out_key_column_type,
Field & out_value, Field & out_value,
DataTypePtr & out_type, DataTypePtr & out_type,
std::function<bool(IFunctionBase &, const IDataType &)> always_monotonic) const std::function<bool(const IFunctionBase &, const IDataType &)> always_monotonic) const
{ {
const auto & sample_block = key_expr->getSampleBlock(); const auto & sample_block = key_expr->getSampleBlock();
@ -1076,7 +1076,7 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
out_key_column_type, out_key_column_type,
out_value, out_value,
out_type, out_type,
[](IFunctionBase & func, const IDataType & type) [](const IFunctionBase & func, const IDataType & type)
{ {
if (!func.hasInformationAboutMonotonicity()) if (!func.hasInformationAboutMonotonicity())
return false; return false;
@ -1131,7 +1131,7 @@ bool KeyCondition::canConstantBeWrappedByFunctions(
out_key_column_type, out_key_column_type,
out_value, out_value,
out_type, out_type,
[](IFunctionBase & func, const IDataType &) [](const IFunctionBase & func, const IDataType &)
{ {
return func.isDeterministic(); return func.isDeterministic();
}); });

View File

@ -19,7 +19,7 @@ namespace DB
class ASTFunction; class ASTFunction;
class Context; class Context;
class IFunction; class IFunction;
using FunctionBasePtr = std::shared_ptr<IFunctionBase>; using FunctionBasePtr = std::shared_ptr<const IFunctionBase>;
class ExpressionActions; class ExpressionActions;
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>; using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
struct ActionDAGNodes; struct ActionDAGNodes;
@ -427,7 +427,7 @@ private:
DataTypePtr & out_key_column_type, DataTypePtr & out_key_column_type,
Field & out_value, Field & out_value,
DataTypePtr & out_type, DataTypePtr & out_type,
std::function<bool(IFunctionBase &, const IDataType &)> always_monotonic) const; std::function<bool(const IFunctionBase &, const IDataType &)> always_monotonic) const;
bool canConstantBeWrappedByMonotonicFunctions( bool canConstantBeWrappedByMonotonicFunctions(
const RPNBuilderTreeNode & node, const RPNBuilderTreeNode & node,

View File

@ -61,7 +61,7 @@ void checkTTLExpression(const ExpressionActionsPtr & ttl_expression, const Strin
{ {
if (action.node->type == ActionsDAG::ActionType::FUNCTION) if (action.node->type == ActionsDAG::ActionType::FUNCTION)
{ {
IFunctionBase & func = *action.node->function_base; const IFunctionBase & func = *action.node->function_base;
if (!func.isDeterministic()) if (!func.isDeterministic())
throw Exception( throw Exception(
"TTL expression cannot contain non-deterministic functions, " "TTL expression cannot contain non-deterministic functions, "