diff --git a/dbms/src/Functions/IFunction.cpp b/dbms/src/Functions/IFunction.cpp index d2e39c836c9..e0d1081246a 100644 --- a/dbms/src/Functions/IFunction.cpp +++ b/dbms/src/Functions/IFunction.cpp @@ -314,7 +314,15 @@ bool PreparedFunctionImpl::defaultImplementationForConstantArguments(Block & blo executeWithoutLowCardinalityColumns(temporary_block, temporary_argument_numbers, arguments_size, temporary_block.rows()); - block.getByPosition(result).column = ColumnConst::create(temporary_block.getByPosition(arguments_size).column->cloneResized(1), input_rows_count); + ColumnPtr result_column; + /// extremely rare case, when we have function with completely const arguments + /// but some of them produced by non isDeterministic function + if (temporary_block.getByPosition(arguments_size).column->size() > 1) + result_column = temporary_block.getByPosition(arguments_size).column->cloneResized(1); + else + result_column = temporary_block.getByPosition(arguments_size).column; + + block.getByPosition(result).column = ColumnConst::create(result_column, input_rows_count); return true; } diff --git a/dbms/src/Interpreters/ExpressionActions.cpp b/dbms/src/Interpreters/ExpressionActions.cpp index 4b5ccfde219..1daf0bc3729 100644 --- a/dbms/src/Interpreters/ExpressionActions.cpp +++ b/dbms/src/Interpreters/ExpressionActions.cpp @@ -677,7 +677,8 @@ void ExpressionActions::addImpl(ExpressionAction action, Names & new_names) new_names.push_back(action.result_name); new_names.insert(new_names.end(), action.array_joined_columns.begin(), action.array_joined_columns.end()); - if (action.type == ExpressionAction::APPLY_FUNCTION) + /// Compiled functions are custom functions and them don't need building + if (action.type == ExpressionAction::APPLY_FUNCTION && !action.is_function_compiled) { if (sample_block.has(action.result_name)) throw Exception("Column '" + action.result_name + "' already exists", ErrorCodes::DUPLICATE_COLUMN);