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

Function parseShape

src/Processors/Formats/Impl/NpyRowInputFormat.cpp:127–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127std::vector<size_t> parseShape(String shape_string)
128{
129 if (!shape_string.starts_with('(') || !shape_string.ends_with(')'))
130 throw Exception(ErrorCodes::INCORRECT_DATA, "Incorrect shape format: {}", shape_string);
131 std::vector<std::string> result_str;
132 boost::split(result_str, std::string_view(shape_string.data() + 1, shape_string.size() - 2), boost::is_any_of(","));
133
134 std::vector<size_t> shape;
135 if (result_str[result_str.size()-1].empty())
136 result_str.pop_back();
137 if (result_str.empty())
138 throw Exception(ErrorCodes::INCORRECT_DATA, "Npy shape must have at least one dimension, got: {}", shape_string);
139
140 shape.reserve(result_str.size());
141 for (const String & item : result_str)
142 {
143 ReadBufferFromString buf(item);
144 skipWhitespaceIfAny(buf);
145 /// Reject negative values before parsing as unsigned.
146 if (!buf.eof() && *buf.position() == '-')
147 throw Exception(ErrorCodes::INCORRECT_DATA, "Negative shape dimension in shape {}", shape_string);
148 size_t value = 0;
149 if (!tryReadIntText(value, buf))
150 throw Exception(ErrorCodes::INCORRECT_DATA, "Invalid shape format: {}", shape_string);
151 shape.push_back(value);
152 }
153 return shape;
154}
155
156NumpyHeader parseHeader(ReadBuffer &buf)
157{

Callers 1

parseHeaderFunction · 0.85

Calls 13

string_viewClass · 0.85
skipWhitespaceIfAnyFunction · 0.85
ExceptionClass · 0.50
splitFunction · 0.50
tryReadIntTextFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
pop_backMethod · 0.45
reserveMethod · 0.45
eofMethod · 0.45
positionMethod · 0.45

Tested by

no test coverage detected