mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
add test
This commit is contained in:
parent
8a1a41f77b
commit
ec87254abe
63
src/Functions/logTrace.cpp
Normal file
63
src/Functions/logTrace.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include <Columns/ColumnConst.h>
|
||||||
|
#include <Columns/ColumnString.h>
|
||||||
|
#include <DataTypes/DataTypeString.h>
|
||||||
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
|
#include <Functions/FunctionFactory.h>
|
||||||
|
#include <Functions/FunctionHelpers.h>
|
||||||
|
#include <Functions/IFunctionImpl.h>
|
||||||
|
#include <Functions/castTypeToEither.h>
|
||||||
|
|
||||||
|
#include <common/logger_useful.h>
|
||||||
|
|
||||||
|
namespace DB
|
||||||
|
{
|
||||||
|
namespace ErrorCodes
|
||||||
|
{
|
||||||
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class FunctionLogTrace : public IFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr auto name = "logTrace";
|
||||||
|
static FunctionPtr create(const Context &) { return std::make_shared<FunctionLogTrace>(); }
|
||||||
|
|
||||||
|
String getName() const override { return name; }
|
||||||
|
|
||||||
|
size_t getNumberOfArguments() const override { return 1; }
|
||||||
|
|
||||||
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
|
||||||
|
{
|
||||||
|
if (!isString(arguments[0]))
|
||||||
|
throw Exception(
|
||||||
|
"Illegal type " + arguments[0]->getName() + " of argument of function " + getName(),
|
||||||
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
|
return std::make_shared<DataTypeUInt8>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t) const override
|
||||||
|
{
|
||||||
|
String message;
|
||||||
|
if (const ColumnConst * col = checkAndGetColumnConst<ColumnString>(block.getByPosition(arguments[0]).column.get()))
|
||||||
|
message = col->getDataAt(0).data;
|
||||||
|
else
|
||||||
|
throw Exception(
|
||||||
|
"First argument for function " + getName() + " must be Constant string", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||||
|
|
||||||
|
static auto * log = &Poco::Logger::get("logTrace");
|
||||||
|
LOG_TRACE(log, message);
|
||||||
|
|
||||||
|
block.getByPosition(result).column = DataTypeUInt8().createColumnConst(1, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void registerFunctionLogTrace(FunctionFactory & factory)
|
||||||
|
{
|
||||||
|
factory.registerFunction<FunctionLogTrace>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -41,6 +41,7 @@ void registerFunctionsUnixTimestamp64(FunctionFactory & factory);
|
|||||||
void registerFunctionBayesAB(FunctionFactory &);
|
void registerFunctionBayesAB(FunctionFactory &);
|
||||||
#endif
|
#endif
|
||||||
void registerFunctionTid(FunctionFactory & factory);
|
void registerFunctionTid(FunctionFactory & factory);
|
||||||
|
void registerFunctionLogTrace(FunctionFactory & factory);
|
||||||
|
|
||||||
|
|
||||||
void registerFunctions()
|
void registerFunctions()
|
||||||
@ -87,6 +88,7 @@ void registerFunctions()
|
|||||||
registerFunctionBayesAB(factory);
|
registerFunctionBayesAB(factory);
|
||||||
#endif
|
#endif
|
||||||
registerFunctionTid(factory);
|
registerFunctionTid(factory);
|
||||||
|
registerFunctionLogTrace(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
namespace ErrorCodes
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class FunctionTid : public IFunction
|
class FunctionTid : public IFunction
|
||||||
|
1
tests/queries/0_stateless/01514_tid_function.sql
Normal file
1
tests/queries/0_stateless/01514_tid_function.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
SELECT tid() FORMAT Null
|
@ -0,0 +1 @@
|
|||||||
|
0
|
1
tests/queries/0_stateless/01515_logtrace_function.sql
Normal file
1
tests/queries/0_stateless/01515_logtrace_function.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
SELECT logTrace('message')
|
Loading…
Reference in New Issue
Block a user