mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Every function in its own file, part 10
This commit is contained in:
parent
66acafe70e
commit
aa234b402a
@ -1,38 +0,0 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct NameVisitParamHas { static constexpr auto name = "visitParamHas"; };
|
||||
struct NameVisitParamExtractUInt { static constexpr auto name = "visitParamExtractUInt"; };
|
||||
struct NameVisitParamExtractInt { static constexpr auto name = "visitParamExtractInt"; };
|
||||
struct NameVisitParamExtractFloat { static constexpr auto name = "visitParamExtractFloat"; };
|
||||
struct NameVisitParamExtractBool { static constexpr auto name = "visitParamExtractBool"; };
|
||||
struct NameVisitParamExtractRaw { static constexpr auto name = "visitParamExtractRaw"; };
|
||||
struct NameVisitParamExtractString { static constexpr auto name = "visitParamExtractString"; };
|
||||
|
||||
|
||||
using FunctionVisitParamHas = FunctionsStringSearch<ExtractParamImpl<HasParam>, NameVisitParamHas>;
|
||||
using FunctionVisitParamExtractUInt = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<UInt64>>, NameVisitParamExtractUInt>;
|
||||
using FunctionVisitParamExtractInt = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<Int64>>, NameVisitParamExtractInt>;
|
||||
using FunctionVisitParamExtractFloat = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<Float64>>, NameVisitParamExtractFloat>;
|
||||
using FunctionVisitParamExtractBool = FunctionsStringSearch<ExtractParamImpl<ExtractBool>, NameVisitParamExtractBool>;
|
||||
using FunctionVisitParamExtractRaw = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractRaw>, NameVisitParamExtractRaw>;
|
||||
using FunctionVisitParamExtractString = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractString>, NameVisitParamExtractString>;
|
||||
|
||||
|
||||
void registerFunctionsVisitParam(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamHas>();
|
||||
factory.registerFunction<FunctionVisitParamExtractUInt>();
|
||||
factory.registerFunction<FunctionVisitParamExtractInt>();
|
||||
factory.registerFunction<FunctionVisitParamExtractFloat>();
|
||||
factory.registerFunction<FunctionVisitParamExtractBool>();
|
||||
factory.registerFunction<FunctionVisitParamExtractRaw>();
|
||||
factory.registerFunction<FunctionVisitParamExtractString>();
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Poco/UTF8Encoding.h>
|
||||
#include <Poco/Unicode.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <DataTypes/DataTypeFixedString.h>
|
||||
#include <Columns/ColumnString.h>
|
||||
#include <Columns/ColumnArray.h>
|
||||
#include <Columns/ColumnFixedString.h>
|
||||
#include <Common/hex.h>
|
||||
#include <Common/Volnitsky.h>
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Functions/FunctionHelpers.h>
|
||||
@ -43,15 +38,6 @@ namespace ErrorCodes
|
||||
extern const int ILLEGAL_COLUMN;
|
||||
}
|
||||
|
||||
struct HasParam
|
||||
{
|
||||
using ResultType = UInt8;
|
||||
|
||||
static UInt8 extract(const UInt8 *, const UInt8 *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename NumericType>
|
||||
struct ExtractNumericType
|
||||
@ -78,77 +64,6 @@ struct ExtractNumericType
|
||||
}
|
||||
};
|
||||
|
||||
struct ExtractBool
|
||||
{
|
||||
using ResultType = UInt8;
|
||||
|
||||
static UInt8 extract(const UInt8 * begin, const UInt8 * end)
|
||||
{
|
||||
return begin + 4 <= end && 0 == strncmp(reinterpret_cast<const char *>(begin), "true", 4);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ExtractRaw
|
||||
{
|
||||
using ExpectChars = PODArrayWithStackMemory<char, 64>;
|
||||
|
||||
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
|
||||
{
|
||||
ExpectChars expects_end;
|
||||
UInt8 current_expect_end = 0;
|
||||
|
||||
for (auto extract_begin = pos; pos != end; ++pos)
|
||||
{
|
||||
if (current_expect_end && *pos == current_expect_end)
|
||||
{
|
||||
expects_end.pop_back();
|
||||
current_expect_end = expects_end.empty() ? 0 : expects_end.back();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*pos)
|
||||
{
|
||||
case '[':
|
||||
current_expect_end = ']';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '{':
|
||||
current_expect_end = '}';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '"' :
|
||||
current_expect_end = '"';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '\\':
|
||||
/// skip backslash
|
||||
if (pos + 1 < end && pos[1] == '"')
|
||||
pos++;
|
||||
break;
|
||||
default:
|
||||
if (!current_expect_end && (*pos == ',' || *pos == '}'))
|
||||
{
|
||||
res_data.insert(extract_begin, pos);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ExtractString
|
||||
{
|
||||
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
|
||||
{
|
||||
size_t old_size = res_data.size();
|
||||
ReadBufferFromMemory in(pos, end - pos);
|
||||
if (!tryReadJSONStringInto(res_data, in))
|
||||
res_data.resize(old_size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Searches for occurrences of a field in the visit parameter and calls ParamExtractor
|
||||
* for each occurrence of the field, passing it a pointer to the part of the string,
|
||||
@ -285,6 +200,4 @@ struct ExtractParamToStringImpl
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ void registerFunctionsExternalDictionaries(FunctionFactory &);
|
||||
void registerFunctionsExternalModels(FunctionFactory &);
|
||||
void registerFunctionsFormatting(FunctionFactory &);
|
||||
void registerFunctionsHashing(FunctionFactory &);
|
||||
void registerFunctionsConsistentHashing(FunctionFactory &);
|
||||
void registerFunctionsHigherOrder(FunctionFactory &);
|
||||
void registerFunctionsLogical(FunctionFactory &);
|
||||
void registerFunctionsMiscellaneous(FunctionFactory &);
|
||||
@ -41,7 +40,7 @@ void registerFunctionsNull(FunctionFactory &);
|
||||
void registerFunctionsFindCluster(FunctionFactory &);
|
||||
void registerFunctionsJSON(FunctionFactory &);
|
||||
void registerFunctionsIntrospection(FunctionFactory &);
|
||||
void registerFunctionsConsistentHashing(FunctionFactory & factory)
|
||||
void registerFunctionsConsistentHashing(FunctionFactory & factory);
|
||||
|
||||
void registerFunctions()
|
||||
{
|
||||
|
25
dbms/src/Functions/registerFunctionsVisitParam.cpp
Normal file
25
dbms/src/Functions/registerFunctionsVisitParam.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class FunctionFactory;
|
||||
|
||||
void registerFunctionVisitParamHas(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractUInt(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractInt(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractFloat(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractBool(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractRaw(FunctionFactory & factory);
|
||||
void registerFunctionVisitParamExtractString(FunctionFactory & factory);
|
||||
|
||||
void registerFunctionsVisitParam(FunctionFactory & factory)
|
||||
{
|
||||
registerFunctionVisitParamHas(factory);
|
||||
registerFunctionVisitParamExtractUInt(factory);
|
||||
registerFunctionVisitParamExtractInt(factory);
|
||||
registerFunctionVisitParamExtractFloat(factory);
|
||||
registerFunctionVisitParamExtractBool(factory);
|
||||
registerFunctionVisitParamExtractRaw(factory);
|
||||
registerFunctionVisitParamExtractString(factory);
|
||||
}
|
||||
|
||||
}
|
28
dbms/src/Functions/visitParamExtractBool.cpp
Normal file
28
dbms/src/Functions/visitParamExtractBool.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct ExtractBool
|
||||
{
|
||||
using ResultType = UInt8;
|
||||
|
||||
static UInt8 extract(const UInt8 * begin, const UInt8 * end)
|
||||
{
|
||||
return begin + 4 <= end && 0 == strncmp(reinterpret_cast<const char *>(begin), "true", 4);
|
||||
}
|
||||
};
|
||||
|
||||
struct NameVisitParamExtractBool { static constexpr auto name = "visitParamExtractBool"; };
|
||||
using FunctionVisitParamExtractBool = FunctionsStringSearch<ExtractParamImpl<ExtractBool>, NameVisitParamExtractBool>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractBool(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractBool>();
|
||||
}
|
||||
|
||||
}
|
18
dbms/src/Functions/visitParamExtractFloat.cpp
Normal file
18
dbms/src/Functions/visitParamExtractFloat.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct NameVisitParamExtractFloat { static constexpr auto name = "visitParamExtractFloat"; };
|
||||
using FunctionVisitParamExtractFloat = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<Float64>>, NameVisitParamExtractFloat>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractFloat(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractFloat>();
|
||||
}
|
||||
|
||||
}
|
18
dbms/src/Functions/visitParamExtractInt.cpp
Normal file
18
dbms/src/Functions/visitParamExtractInt.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct NameVisitParamExtractInt { static constexpr auto name = "visitParamExtractInt"; };
|
||||
using FunctionVisitParamExtractInt = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<Int64>>, NameVisitParamExtractInt>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractInt(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractInt>();
|
||||
}
|
||||
|
||||
}
|
67
dbms/src/Functions/visitParamExtractRaw.cpp
Normal file
67
dbms/src/Functions/visitParamExtractRaw.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct ExtractRaw
|
||||
{
|
||||
using ExpectChars = PODArrayWithStackMemory<char, 64>;
|
||||
|
||||
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
|
||||
{
|
||||
ExpectChars expects_end;
|
||||
UInt8 current_expect_end = 0;
|
||||
|
||||
for (auto extract_begin = pos; pos != end; ++pos)
|
||||
{
|
||||
if (current_expect_end && *pos == current_expect_end)
|
||||
{
|
||||
expects_end.pop_back();
|
||||
current_expect_end = expects_end.empty() ? 0 : expects_end.back();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (*pos)
|
||||
{
|
||||
case '[':
|
||||
current_expect_end = ']';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '{':
|
||||
current_expect_end = '}';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '"' :
|
||||
current_expect_end = '"';
|
||||
expects_end.push_back(current_expect_end);
|
||||
break;
|
||||
case '\\':
|
||||
/// skip backslash
|
||||
if (pos + 1 < end && pos[1] == '"')
|
||||
pos++;
|
||||
break;
|
||||
default:
|
||||
if (!current_expect_end && (*pos == ',' || *pos == '}'))
|
||||
{
|
||||
res_data.insert(extract_begin, pos);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct NameVisitParamExtractRaw { static constexpr auto name = "visitParamExtractRaw"; };
|
||||
using FunctionVisitParamExtractRaw = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractRaw>, NameVisitParamExtractRaw>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractRaw(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractRaw>();
|
||||
}
|
||||
|
||||
}
|
29
dbms/src/Functions/visitParamExtractString.cpp
Normal file
29
dbms/src/Functions/visitParamExtractString.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct ExtractString
|
||||
{
|
||||
static void extract(const UInt8 * pos, const UInt8 * end, ColumnString::Chars & res_data)
|
||||
{
|
||||
size_t old_size = res_data.size();
|
||||
ReadBufferFromMemory in(pos, end - pos);
|
||||
if (!tryReadJSONStringInto(res_data, in))
|
||||
res_data.resize(old_size);
|
||||
}
|
||||
};
|
||||
|
||||
struct NameVisitParamExtractString { static constexpr auto name = "visitParamExtractString"; };
|
||||
using FunctionVisitParamExtractString = FunctionsStringSearchToString<ExtractParamToStringImpl<ExtractString>, NameVisitParamExtractString>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractString(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractString>();
|
||||
}
|
||||
|
||||
}
|
18
dbms/src/Functions/visitParamExtractUInt.cpp
Normal file
18
dbms/src/Functions/visitParamExtractUInt.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct NameVisitParamExtractUInt { static constexpr auto name = "visitParamExtractUInt"; };
|
||||
using FunctionVisitParamExtractUInt = FunctionsStringSearch<ExtractParamImpl<ExtractNumericType<UInt64>>, NameVisitParamExtractUInt>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamExtractUInt(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamExtractUInt>();
|
||||
}
|
||||
|
||||
}
|
28
dbms/src/Functions/visitParamHas.cpp
Normal file
28
dbms/src/Functions/visitParamHas.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Functions/FunctionsVisitParam.h>
|
||||
#include <Functions/FunctionsStringSearch.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct HasParam
|
||||
{
|
||||
using ResultType = UInt8;
|
||||
|
||||
static UInt8 extract(const UInt8 *, const UInt8 *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct NameVisitParamHas { static constexpr auto name = "visitParamHas"; };
|
||||
using FunctionVisitParamHas = FunctionsStringSearch<ExtractParamImpl<HasParam>, NameVisitParamHas>;
|
||||
|
||||
|
||||
void registerFunctionVisitParamHas(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionVisitParamHas>();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user