HappenLee commented on code in PR #42488: URL: https://github.com/apache/doris/pull/42488#discussion_r1817873603
########## be/src/vec/functions/url/domain.h: ########## @@ -144,4 +145,138 @@ struct ExtractDomain { } }; +struct ExtractTopLevelDomain { + static size_t get_reserve_length_for_element() { return 5; } + + static void execute(const char* data, size_t size, const char*& res_data, size_t& res_size) { + StringRef host = get_url_host(data, size); + + if (host.size == 0) { + res_data = data; + res_size = 0; + } else { + auto host_view = host.to_string_view(); + if (host_view[host_view.size() - 1] == '.') { + host_view.remove_suffix(1); + } + + const auto* host_end = host_view.data() + host_view.size(); + const char* last_dot = find_last_symbols_or_null<'.'>(host_view.data(), host_end); + if (!last_dot) { + return; + } + + /// For IPv4 addresses select nothing. + /// + /// NOTE: it is safe to access last_dot[1] + /// since getURLHost() will not return a host if there is symbol after dot. + if (is_numeric_ascii(last_dot[1])) { + return; + } + + res_data = last_dot + 1; + res_size = host_end - res_data; + } + } +}; + +struct FirstSignificantSubdomainDefaultLookup { + bool operator()(StringRef host) const { return tldLookup::isValid(host.data, host.size); } +}; + +struct ExtractFirstSignificantSubdomain { + static size_t get_reserve_length_for_element() { return 10; } + + static void execute(const Pos data, const size_t size, Pos& res_data, size_t& res_size, + Pos* out_domain_end = nullptr) { + FirstSignificantSubdomainDefaultLookup loookup; Review Comment: why here we need a class, not direct call the static func `tldLooup::is_valid` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org