Merge pull request #11846 from ClickHouse/prohibit-array-join-in-higher-order-functions

Don't allow arrayJoin inside higher order functions
This commit is contained in:
alexey-milovidov 2020-06-22 03:00:51 +03:00 committed by GitHub
commit dd31bcff66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View File

@ -8,11 +8,13 @@
#include <Columns/ColumnFunction.h>
#include <DataTypes/DataTypesNumber.h>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int BAD_ARGUMENTS;
}
class ExecutableFunctionExpression : public IExecutableFunctionImpl
@ -203,6 +205,11 @@ public:
const String & expression_return_name_)
: expression_actions(std::move(expression_actions_))
{
/// Check that expression does not contain unusual actions that will break blocks structure.
for (const auto & action : expression_actions->getActions())
if (action.type == ExpressionAction::Type::JOIN || action.type == ExpressionAction::Type::ARRAY_JOIN)
throw Exception("Expression with arrayJoin or other unusual action cannot be captured", ErrorCodes::BAD_ARGUMENTS);
std::unordered_map<std::string, DataTypePtr> arguments_map;
const auto & all_arguments = expression_actions->getRequiredColumnsWithTypes();

View File

@ -33,7 +33,8 @@ namespace ErrorCodes
* arrayMap(x1,...,xn -> expression, array1,...,arrayn) - apply the expression to each element of the array (or set of parallel arrays).
* arrayFilter(x -> predicate, array) - leave in the array only the elements for which the expression is true.
*
* For some functions arrayCount, arrayExists, arrayAll, an overload of the form f(array) is available, which works in the same way as f(x -> x, array).
* For some functions arrayCount, arrayExists, arrayAll, an overload of the form f(array) is available,
* which works in the same way as f(x -> x, array).
*
* See the example of Impl template parameter in arrayMap.cpp
*/

View File

@ -0,0 +1 @@
SELECT arrayMap(x -> arrayJoin([x, 1]), [1, 2]); -- { serverError 36 }