MCPcopy Create free account
hub / github.com/apache/arrow / FromDotPath

Method FromDotPath

cpp/src/arrow/type.cc:1997–2067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1995}
1996
1997Result<FieldRef> FieldRef::FromDotPath(const std::string& dot_path_arg) {
1998 if (dot_path_arg.empty()) {
1999 return FieldRef();
2000 }
2001
2002 std::vector<FieldRef> children;
2003
2004 std::string_view dot_path = dot_path_arg;
2005
2006 auto parse_name = [&] {
2007 std::string name;
2008 for (;;) {
2009 auto segment_end = dot_path.find_first_of("\\[.");
2010 if (segment_end == std::string_view::npos) {
2011 // dot_path doesn't contain any other special characters; consume all
2012 name.append(dot_path.data(), dot_path.length());
2013 dot_path = "";
2014 break;
2015 }
2016
2017 if (dot_path[segment_end] != '\\') {
2018 // segment_end points to a subscript for a new FieldRef
2019 name.append(dot_path.data(), segment_end);
2020 dot_path = dot_path.substr(segment_end);
2021 break;
2022 }
2023
2024 if (dot_path.size() == segment_end + 1) {
2025 // dot_path ends with backslash; consume it all
2026 name.append(dot_path.data(), dot_path.length());
2027 dot_path = "";
2028 break;
2029 }
2030
2031 // append all characters before backslash, then the character which follows it
2032 name.append(dot_path.data(), segment_end);
2033 name.push_back(dot_path[segment_end + 1]);
2034 dot_path = dot_path.substr(segment_end + 2);
2035 }
2036 return name;
2037 };
2038
2039 while (!dot_path.empty()) {
2040 auto subscript = dot_path[0];
2041 dot_path = dot_path.substr(1);
2042 switch (subscript) {
2043 case '.': {
2044 // next element is a name
2045 children.emplace_back(parse_name());
2046 continue;
2047 }
2048 case '[': {
2049 auto subscript_end = dot_path.find_first_not_of("0123456789");
2050 if (subscript_end == std::string_view::npos || dot_path[subscript_end] != ']') {
2051 return Status::Invalid("Dot path '", dot_path_arg,
2052 "' contained an unterminated index");
2053 }
2054 children.emplace_back(std::atoi(dot_path.data()));

Callers

nothing calls this directly

Calls 11

substrMethod · 0.80
push_backMethod · 0.80
emplace_backMethod · 0.80
FieldRefFunction · 0.70
InvalidFunction · 0.70
emptyMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45
FlattenMethod · 0.45

Tested by

no test coverage detected