MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / bindQueryNode

Method bindQueryNode

src/binder/bind/bind_graph_pattern.cpp:562–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560}
561
562std::shared_ptr<NodeExpression> Binder::bindQueryNode(const NodePattern& nodePattern,
563 QueryGraph& queryGraph) {
564 auto parsedName = nodePattern.getVariableName();
565 std::shared_ptr<NodeExpression> queryNode;
566 if (scope.contains(parsedName)) { // bind to node in scope
567 auto prevVariable = scope.getExpression(parsedName);
568 if (!ExpressionUtil::isNodePattern(*prevVariable)) {
569 if (!scope.hasNodeReplacement(parsedName)) {
570 throw BinderException(std::format("Cannot bind {} as node pattern.", parsedName));
571 }
572 queryNode = scope.getNodeReplacement(parsedName);
573 queryNode->addPropertyDataExpr(InternalKeyword::ID, queryNode->getInternalID());
574 } else {
575 queryNode = std::static_pointer_cast<NodeExpression>(prevVariable);
576 // E.g. MATCH (a:person) MATCH (a:organisation)
577 // We bind to a single node with both labels
578 if (!nodePattern.getTableNames().empty()) {
579 auto otherNodeEntries = bindNodeTableEntries(nodePattern.getTableNames());
580 queryNode->addEntries(otherNodeEntries.first);
581 }
582 }
583 } else {
584 queryNode = createQueryNode(nodePattern);
585 if (!parsedName.empty()) {
586 addToScope(parsedName, queryNode);
587 }
588 }
589 for (auto& [propertyName, rhs] : nodePattern.getPropertyKeyVals()) {
590 auto boundLhs = expressionBinder.bindNodeOrRelPropertyExpression(*queryNode, propertyName);
591 auto boundRhs = expressionBinder.bindExpression(*rhs);
592 // For ANY graphs, properties are stored as JSON in the data column
593 // Skip forceCast for ANY type as it cannot be cast to
594 if (boundLhs->dataType.getLogicalTypeID() != LogicalTypeID::ANY) {
595 boundRhs = expressionBinder.forceCast(boundRhs, boundLhs->dataType);
596 }
597 queryNode->addPropertyDataExpr(propertyName, std::move(boundRhs));
598 }
599 queryGraph.addQueryNode(queryNode);
600 return queryNode;
601}
602
603std::shared_ptr<NodeExpression> Binder::createQueryNode(const NodePattern& nodePattern) {
604 auto parsedName = nodePattern.getVariableName();

Callers

nothing calls this directly

Calls 13

hasNodeReplacementMethod · 0.80
getNodeReplacementMethod · 0.80
getTableNamesMethod · 0.80
addEntriesMethod · 0.80
bindExpressionMethod · 0.80
getLogicalTypeIDMethod · 0.80
forceCastMethod · 0.80
getVariableNameMethod · 0.45
containsMethod · 0.45
getExpressionMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected