2018-11-25 23:24:26 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionStringToString.h>
|
2019-06-20 15:49:54 +00:00
|
|
|
#include "domain.h"
|
2018-11-25 23:24:26 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct NameDomainWithoutWWW { static constexpr auto name = "domainWithoutWWW"; };
|
2022-10-22 11:01:33 +00:00
|
|
|
using FunctionDomainWithoutWWW = FunctionStringToString<ExtractSubstringImpl<ExtractDomain<true, false>>, NameDomainWithoutWWW>;
|
|
|
|
|
|
|
|
struct NameDomainWithoutWWWRFC { static constexpr auto name = "domainWithoutWWWRFC"; };
|
|
|
|
using FunctionDomainWithoutWWWRFC = FunctionStringToString<ExtractSubstringImpl<ExtractDomain<true, true>>, NameDomainWithoutWWWRFC>;
|
2018-11-25 23:24:26 +00:00
|
|
|
|
|
|
|
|
2022-07-04 07:01:39 +00:00
|
|
|
REGISTER_FUNCTION(DomainWithoutWWW)
|
2018-11-25 23:24:26 +00:00
|
|
|
{
|
2022-10-25 17:18:32 +00:00
|
|
|
factory.registerFunction<FunctionDomainWithoutWWW>(
|
|
|
|
{
|
|
|
|
R"(
|
|
|
|
Extracts the hostname from a URL, removing the leading "www." if present.
|
|
|
|
|
|
|
|
The URL can be specified with or without a scheme.
|
|
|
|
If the argument can't be parsed as URL, the function returns an empty string.
|
|
|
|
)",
|
|
|
|
Documentation::Examples{{"domainWithoutWWW", "SELECT domainWithoutWWW('https://www.clickhouse.com')"}},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
|
|
|
factory.registerFunction<FunctionDomainWithoutWWWRFC>(
|
|
|
|
{
|
|
|
|
R"(Similar to `domainWithoutWWW` but follows stricter rules to be compatible with RFC 3986 and less performant.)",
|
|
|
|
Documentation::Examples{},
|
|
|
|
Documentation::Categories{"URL"}
|
|
|
|
});
|
2018-11-25 23:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|