2020-12-03 21:11:38 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include "ExtractFirstSignificantSubdomain.h"
|
|
|
|
#include "FirstSignificantSubdomainCustomImpl.h"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-10-22 11:01:33 +00:00
|
|
|
template <bool without_www, bool conform_rfc>
|
2020-12-03 21:11:38 +00:00
|
|
|
struct CutToFirstSignificantSubdomainCustom
|
|
|
|
{
|
|
|
|
static size_t getReserveLengthForElement() { return 15; }
|
|
|
|
|
2021-03-21 07:58:31 +00:00
|
|
|
static void execute(FirstSignificantSubdomainCustomLookup & tld_lookup, const Pos data, const size_t size, Pos & res_data, size_t & res_size)
|
2020-12-03 21:11:38 +00:00
|
|
|
{
|
|
|
|
res_data = data;
|
|
|
|
res_size = 0;
|
|
|
|
|
|
|
|
Pos tmp_data;
|
|
|
|
size_t tmp_length;
|
|
|
|
Pos domain_end;
|
2022-10-22 11:01:33 +00:00
|
|
|
ExtractFirstSignificantSubdomain<without_www, conform_rfc>::executeCustom(tld_lookup, data, size, tmp_data, tmp_length, &domain_end);
|
2020-12-03 21:11:38 +00:00
|
|
|
|
|
|
|
if (tmp_length == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
res_data = tmp_data;
|
|
|
|
res_size = domain_end - tmp_data;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NameCutToFirstSignificantSubdomainCustom { static constexpr auto name = "cutToFirstSignificantSubdomainCustom"; };
|
2022-10-22 11:01:33 +00:00
|
|
|
using FunctionCutToFirstSignificantSubdomainCustom = FunctionCutToFirstSignificantSubdomainCustomImpl<CutToFirstSignificantSubdomainCustom<true, false>, NameCutToFirstSignificantSubdomainCustom>;
|
2020-12-03 21:11:38 +00:00
|
|
|
|
|
|
|
struct NameCutToFirstSignificantSubdomainCustomWithWWW { static constexpr auto name = "cutToFirstSignificantSubdomainCustomWithWWW"; };
|
2022-10-22 11:01:33 +00:00
|
|
|
using FunctionCutToFirstSignificantSubdomainCustomWithWWW = FunctionCutToFirstSignificantSubdomainCustomImpl<CutToFirstSignificantSubdomainCustom<false, false>, NameCutToFirstSignificantSubdomainCustomWithWWW>;
|
|
|
|
|
|
|
|
struct NameCutToFirstSignificantSubdomainCustomRFC { static constexpr auto name = "cutToFirstSignificantSubdomainCustomRFC"; };
|
|
|
|
using FunctionCutToFirstSignificantSubdomainCustomRFC = FunctionCutToFirstSignificantSubdomainCustomImpl<CutToFirstSignificantSubdomainCustom<true, true>, NameCutToFirstSignificantSubdomainCustomRFC>;
|
|
|
|
|
|
|
|
struct NameCutToFirstSignificantSubdomainCustomWithWWWRFC { static constexpr auto name = "cutToFirstSignificantSubdomainCustomWithWWWRFC"; };
|
|
|
|
using FunctionCutToFirstSignificantSubdomainCustomWithWWWRFC = FunctionCutToFirstSignificantSubdomainCustomImpl<CutToFirstSignificantSubdomainCustom<false, true>, NameCutToFirstSignificantSubdomainCustomWithWWWRFC>;
|
2020-12-03 21:11:38 +00:00
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(CutToFirstSignificantSubdomainCustom)
|
2020-12-03 21:11:38 +00:00
|
|
|
{
|
2022-10-25 17:18:32 +00:00
|
|
|
factory.registerFunction<FunctionCutToFirstSignificantSubdomainCustom>(
|
|
|
|
{
|
|
|
|
R"(
|
|
|
|
Returns the part of the domain that includes top-level subdomains up to the first significant subdomain. Accepts custom TLD list name.
|
|
|
|
|
|
|
|
Can be useful if you need fresh TLD list or you have custom.
|
|
|
|
)",
|
|
|
|
Documentation::Examples{
|
|
|
|
{"cutToFirstSignificantSubdomainCustom", "SELECT cutToFirstSignificantSubdomainCustom('bar.foo.there-is-no-such-domain', 'public_suffix_list');"},
|
|
|
|
},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
|
|
|
factory.registerFunction<FunctionCutToFirstSignificantSubdomainCustomWithWWW>(
|
|
|
|
{
|
|
|
|
R"(
|
|
|
|
Returns the part of the domain that includes top-level subdomains up to the first significant subdomain without stripping `www`.
|
|
|
|
Accepts custom TLD list name from config.
|
|
|
|
|
|
|
|
Can be useful if you need fresh TLD list or you have custom.
|
|
|
|
)",
|
|
|
|
Documentation::Examples{{"cutToFirstSignificantSubdomainCustomWithWWW", "SELECT cutToFirstSignificantSubdomainCustomWithWWW('www.foo', 'public_suffix_list')"}},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
|
|
|
factory.registerFunction<FunctionCutToFirstSignificantSubdomainCustomRFC>(
|
|
|
|
{
|
|
|
|
R"(Similar to `cutToFirstSignificantSubdomainCustom` but follows stricter rules according to RFC 3986.)",
|
|
|
|
Documentation::Examples{},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
|
|
|
factory.registerFunction<FunctionCutToFirstSignificantSubdomainCustomWithWWWRFC>(
|
|
|
|
{
|
|
|
|
R"(Similar to `cutToFirstSignificantSubdomainCustomWithWWW` but follows stricter rules according to RFC 3986.)",
|
|
|
|
Documentation::Examples{},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
2020-12-03 21:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|