From c3c56e3dc557127c61b5502b43d65a7a4b0b1c8b Mon Sep 17 00:00:00 2001 From: avogar Date: Tue, 17 Sep 2024 18:19:45 +0000 Subject: [PATCH] Better comments --- src/Functions/FunctionDynamicAdaptor.h | 4 ++++ src/Functions/IFunction.cpp | 1 + src/Functions/IFunction.h | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/src/Functions/FunctionDynamicAdaptor.h b/src/Functions/FunctionDynamicAdaptor.h index fce909e7c58..85ae83d746a 100644 --- a/src/Functions/FunctionDynamicAdaptor.h +++ b/src/Functions/FunctionDynamicAdaptor.h @@ -5,6 +5,8 @@ namespace DB { +/// Special adapter classes that implement functions execution with Dynamic arguments. + class ExecutableFunctionDynamicAdaptor final : public IExecutableFunction { public: @@ -31,6 +33,7 @@ protected: private: ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count, bool dry_run) const; + /// We remember the original IFunctionOverloadResolver to be able to build function for types inside Dynamic column. std::shared_ptr function_overload_resolver; size_t dynamic_argument_index; }; @@ -65,6 +68,7 @@ public: bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo &) const override { return true; } private: + /// We remember the original IFunctionOverloadResolver to be able to build function for types inside Dynamic column. std::shared_ptr function_overload_resolver; DataTypes arguments; DataTypePtr return_type; diff --git a/src/Functions/IFunction.cpp b/src/Functions/IFunction.cpp index d222da674c6..bafd76b3966 100644 --- a/src/Functions/IFunction.cpp +++ b/src/Functions/IFunction.cpp @@ -450,6 +450,7 @@ DataTypePtr IFunctionOverloadResolver::getReturnType(const ColumnsWithTypeAndNam FunctionBasePtr IFunctionOverloadResolver::build(const ColumnsWithTypeAndName & arguments) const { + /// Use FunctionBaseDynamicAdaptor if default implementation for Dynamic is enabled and we have Dynamic type in arguments. if (useDefaultImplementationForDynamic()) { for (const auto & arg : arguments) diff --git a/src/Functions/IFunction.h b/src/Functions/IFunction.h index 64b4510598a..c3ba4be7419 100644 --- a/src/Functions/IFunction.h +++ b/src/Functions/IFunction.h @@ -371,6 +371,8 @@ public: /// (for functions like isNull(x)) virtual ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t number_of_arguments [[maybe_unused]]) const { return {}; } + /// Returns type that should be used as the result type in default implementation for Dynamic. + /// Function should implement this method if its result type doesn't depend on the arguments types. virtual DataTypePtr getReturnTypeForDefaultImplementationForDynamic() const { return nullptr; } protected: @@ -427,6 +429,15 @@ protected: /// If it isn't, will convert all ColumnLowCardinality arguments to full columns. virtual bool canBeExecutedOnLowCardinalityDictionary() const { return true; } + /** If useDefaultImplementationForDynamic() is true, then special FunctionBaseDynamicAdaptor will be used + * if function arguments has Dynamic column. This adaptor will build and execute this function for all + * internal types inside Dynamic column separately and construct result based on results for these types. + * If getReturnTypeForDefaultImplementationForDynamic() returns T, then result of such function + * will be Nullable(T), otherwise the result will be Dynamic. + * + * We cannot use default implementation for Dynamic if function doesn't use default implementation for NULLs, + * because Dynamic column can contain NULLs and we should know how to process them. + */ virtual bool useDefaultImplementationForDynamic() const { return useDefaultImplementationForNulls(); } private: