MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / splitSubcolumnName

Function splitSubcolumnName

src/DataTypes/DataTypeDynamic.cpp:853–886  ·  view source on GitHub ↗

Split Dynamic subcolumn name into 2 parts: type name and subcolumn of this type. We cannot simply split by '.' because type name can also contain dots. For example: Tuple(`a.b` UInt32). But in all such cases this '.' will be inside back quotes. To split subcolumn name correctly we search for the first '.' that is not inside back quotes.

Source from the content-addressed store, hash-verified

851/// But in all such cases this '.' will be inside back quotes. To split subcolumn name correctly
852/// we search for the first '.' that is not inside back quotes.
853std::pair<std::string_view, std::string_view> splitSubcolumnName(std::string_view subcolumn_name)
854{
855 bool inside_quotes = false;
856 const char * pos = subcolumn_name.data();
857 const char * end = subcolumn_name.data() + subcolumn_name.size();
858 while (true)
859 {
860 pos = find_first_symbols<'`', '.', '\\'>(pos, end);
861 if (pos == end)
862 break;
863
864 if (*pos == '`')
865 {
866 inside_quotes = !inside_quotes;
867 ++pos;
868 }
869 else if (*pos == '\\')
870 {
871 ++pos;
872 }
873 else if (*pos == '.')
874 {
875 if (inside_quotes)
876 ++pos;
877 else
878 break;
879 }
880 }
881
882 if (pos == end)
883 return {subcolumn_name, {}};
884
885 return {std::string_view(subcolumn_name.data(), pos), std::string_view(pos + 1, end)}; /// NOLINT(bugprone-suspicious-stringview-data-usage)
886}
887
888}
889

Callers 1

Calls 3

string_viewClass · 0.85
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected