Skip to content

Commit 4ce35b1

Browse files
committed
Fix __actionName, add tests for internal functions direct call
1 parent 47b9eb2 commit 4ce35b1

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/Functions/identity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FunctionActionName : public FunctionIdentityBase<ActionNameName>
5353
using FunctionIdentityBase::FunctionIdentityBase;
5454
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionActionName>(); }
5555
size_t getNumberOfArguments() const override { return 2; }
56-
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1}; }
56+
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {0, 1}; }
5757
};
5858

5959
}

src/Planner/PlannerActionsVisitor.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,17 @@ class ActionNodeNameHelper
159159
const auto & function_node = node->as<FunctionNode &>();
160160
if (function_node.getFunctionName() == "__actionName")
161161
{
162-
result = toString(function_node.getArguments().getNodes().at(1)->as<ConstantNode>()->getValue());
162+
/// Perform sanity check, because user may call this function with unexpected arguments
163+
const auto & function_argument_nodes = function_node.getArguments().getNodes();
164+
if (function_argument_nodes.size() == 2)
165+
{
166+
if (const auto * second_argument = function_argument_nodes.at(1)->as<ConstantNode>())
167+
result = toString(second_argument->getValue());
168+
}
169+
170+
/// Empty node name is not allowed and leads to logical errors
171+
if (result.empty())
172+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Function __actionName is internal nad should not be used directly");
163173
break;
164174
}
165175

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
aaa
2+
(1,1) (1,1)
3+
1
4+
a1 1
5+
1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- This functions should not be called directly, only for internal use.
2+
-- However, we cannot completely forbid it (becasue query can came from another server, for example)
3+
-- Check that usage of these functions does not lead to crash or logical error
4+
5+
SELECT __actionName(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
6+
SELECT __actionName('aaa', 'aaa', 'aaa'); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
7+
SELECT __actionName('aaa', '') SETTINGS allow_experimental_analyzer = 1; -- { serverError BAD_ARGUMENTS }
8+
SELECT __actionName('aaa', materialize('aaa')); -- { serverError BAD_ARGUMENTS,ILLEGAL_COLUMN }
9+
SELECT __actionName(materialize('aaa'), 'aaa'); -- { serverError ILLEGAL_COLUMN }
10+
SELECT __actionName('aaa', 'aaa');
11+
12+
SELECT __getScalar('aaa'); -- { serverError BAD_ARGUMENTS }
13+
SELECT __getScalar(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
14+
SELECT __getScalar(1); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
15+
SELECT __getScalar(materialize('1')); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
16+
17+
WITH ( SELECT (1,1) ) as a SELECT materialize(a), __getScalar('17789833925953107877_7493841889429261611') SETTINGS allow_experimental_analyzer = 1;
18+
19+
SELECT __scalarSubqueryResult('1');
20+
SELECT 'a' || __scalarSubqueryResult(a), materialize('1') as a;
21+
SELECT __scalarSubqueryResult(a, a), materialize('1') as a; -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
22+
23+
SELECT 1 as `__grouping_set`;

0 commit comments

Comments
 (0)