MCPcopy Create free account
hub / github.com/bytedance/bolt / toSubfield

Method toSubfield

bolt/expression/ExprToSubfieldFilter.cpp:178–217  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

176
177// static
178bool ExprToSubfieldFilterParser::toSubfield(
179 const core::ITypedExpr* field,
180 common::Subfield& subfield) {
181 std::vector<std::unique_ptr<common::Subfield::PathElement>> path;
182 for (auto* current = field;;) {
183 if (auto* fieldAccess =
184 dynamic_cast<const core::FieldAccessTypedExpr*>(current)) {
185 path.push_back(
186 std::make_unique<common::Subfield::NestedField>(fieldAccess->name()));
187 } else if (
188 auto* dereference =
189 dynamic_cast<const core::DereferenceTypedExpr*>(current)) {
190 const auto& name = dereference->name();
191 // When the field name is empty string, it typically means that the
192 // field name was not set in the parent type.
193 if (name.empty()) {
194 return false;
195 }
196 path.push_back(std::make_unique<common::Subfield::NestedField>(name));
197 } else if (dynamic_cast<const core::InputTypedExpr*>(current) == nullptr) {
198 return false;
199 } else {
200 break;
201 }
202
203 if (current->inputs().empty()) {
204 break;
205 }
206 if (current->inputs().size() != 1) {
207 return false;
208 }
209 current = current->inputs()[0].get();
210 if (current == nullptr) {
211 return false;
212 }
213 }
214 std::reverse(path.begin(), path.end());
215 subfield = common::Subfield(std::move(path));
216 return true;
217}
218
219// static
220std::unique_ptr<common::Filter> ExprToSubfieldFilterParser::makeNotEqualFilter(

Callers

nothing calls this directly

Calls 9

reverseFunction · 0.85
SubfieldClass · 0.85
push_backMethod · 0.45
nameMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected