mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
Add a basename function
This commit is contained in:
parent
97c532c0f0
commit
95141804fb
38
dbms/src/Functions/basename.cpp
Normal file
38
dbms/src/Functions/basename.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionStringToString.h>
|
||||
#include <Functions/FunctionsURL.h>
|
||||
#include <common/find_symbols.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct ExtractBasename
|
||||
{
|
||||
static size_t getReserveLengthForElement() { return 25; }
|
||||
|
||||
static void execute(Pos data, size_t size, Pos & res_data, size_t & res_size)
|
||||
{
|
||||
res_data = data;
|
||||
res_size = size;
|
||||
|
||||
Pos pos = data;
|
||||
Pos end = pos + size;
|
||||
|
||||
if ((pos = find_last_symbols_or_null<'/', '\\'>(pos, end)))
|
||||
{
|
||||
++pos;
|
||||
res_data = pos;
|
||||
res_size = end - pos;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct NameBasename { static constexpr auto name = "basename"; };
|
||||
using FunctionBasename = FunctionStringToString<ExtractSubstringImpl<ExtractBasename>, NameBasename>;
|
||||
|
||||
void registerFunctionBasename(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionBasename>();
|
||||
}
|
||||
|
||||
}
|
@ -42,6 +42,7 @@ void registerFunctionLowCardinalityKeys(FunctionFactory &);
|
||||
void registerFunctionsIn(FunctionFactory &);
|
||||
void registerFunctionJoinGet(FunctionFactory &);
|
||||
void registerFunctionFilesystem(FunctionFactory &);
|
||||
void registerFunctionBasename(FunctionFactory &);
|
||||
|
||||
void registerFunctionsMiscellaneous(FunctionFactory & factory)
|
||||
{
|
||||
@ -84,6 +85,7 @@ void registerFunctionsMiscellaneous(FunctionFactory & factory)
|
||||
registerFunctionsIn(factory);
|
||||
registerFunctionJoinGet(factory);
|
||||
registerFunctionFilesystem(factory);
|
||||
registerFunctionBasename(factory);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user