Skip to content

Commit 4ea2b5e

Browse files
committed
Restrict argument types for __actionName
1 parent 4ce35b1 commit 4ea2b5e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Functions/identity.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
namespace DB
77
{
88

9+
namespace ErrorCodes
10+
{
11+
extern const int BAD_ARGUMENTS;
12+
}
13+
914
template<typename Name>
1015
class FunctionIdentityBase : public IFunction
1116
{
@@ -54,6 +59,23 @@ class FunctionActionName : public FunctionIdentityBase<ActionNameName>
5459
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionActionName>(); }
5560
size_t getNumberOfArguments() const override { return 2; }
5661
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {0, 1}; }
62+
63+
/// Do not allow any argument to have type other than String
64+
bool useDefaultImplementationForNulls() const override { return false; }
65+
bool useDefaultImplementationForNothing() const override { return false; }
66+
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
67+
68+
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
69+
{
70+
for (const auto & arg : arguments)
71+
{
72+
if (WhichDataType(arg).isString())
73+
continue;
74+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Function __actionName is internal nad should not be used directly");
75+
}
76+
77+
return FunctionIdentityBase<ActionNameName>::getReturnTypeImpl(arguments);
78+
}
5779
};
5880

5981
}

src/Processors/Transforms/MergeJoinTransform.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ static void prepareChunk(Chunk & chunk)
338338

339339
void MergeJoinAlgorithm::initialize(Inputs inputs)
340340
{
341+
LOG_DEBUG(&Poco::Logger::get("XXXX"), "{}:{}: {} - '{}'", __FILE__, __LINE__, 0, inputs[0].chunk.dumpStructure());
342+
LOG_DEBUG(&Poco::Logger::get("XXXX"), "{}:{}: {} - '{}'", __FILE__, __LINE__, 1, inputs[1].chunk.dumpStructure());
341343
if (inputs.size() != 2)
342344
throw Exception(ErrorCodes::LOGICAL_ERROR, "Two inputs are required, got {}", inputs.size());
343345

@@ -349,6 +351,8 @@ void MergeJoinAlgorithm::initialize(Inputs inputs)
349351

350352
void MergeJoinAlgorithm::consume(Input & input, size_t source_num)
351353
{
354+
LOG_DEBUG(&Poco::Logger::get("XXXX"), "{}:{}: {} - '{}'", __FILE__, __LINE__, source_num, input.chunk.dumpStructure());
355+
352356
if (input.skip_last_row)
353357
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "skip_last_row is not supported");
354358

@@ -812,8 +816,17 @@ IMergingAlgorithm::Status MergeJoinAlgorithm::merge()
812816
if (!cursors[1]->cursor.isValid() && !cursors[1]->fullyCompleted())
813817
return Status(1);
814818

819+
for (size_t i = 0; i < 2; ++i)
820+
{
821+
LOG_DEBUG(&Poco::Logger::get("XXXX"), "{}:{}: sampleColumns {} '{}'", __FILE__, __LINE__, i, cursors[i]->sampleBlock().dumpStructure());
822+
}
823+
824+
815825
if (auto result = handleAllJoinState())
826+
{
827+
LOG_DEBUG(&Poco::Logger::get("XXXX"), "{}:{}: '{}'", __FILE__, __LINE__, result ? result->chunk.dumpStructure() : "NA");
816828
return std::move(*result);
829+
}
817830

818831
if (cursors[0]->fullyCompleted() || cursors[1]->fullyCompleted())
819832
{

tests/queries/0_stateless/03035_internal_functions_direct_call.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ SELECT __actionName('aaa', materialize('aaa')); -- { serverError BAD_ARGUMENTS,I
99
SELECT __actionName(materialize('aaa'), 'aaa'); -- { serverError ILLEGAL_COLUMN }
1010
SELECT __actionName('aaa', 'aaa');
1111

12+
SELECT concat(__actionName('aaa', toNullable('x')), '1') GROUP BY __actionName('aaa', 'x'); -- { serverError BAD_ARGUMENTS }
13+
1214
SELECT __getScalar('aaa'); -- { serverError BAD_ARGUMENTS }
1315
SELECT __getScalar(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
1416
SELECT __getScalar(1); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }

0 commit comments

Comments
 (0)