Data query method and apparatus, storage medium, and device
Abstract
This specification discloses a method. The method includes: when a received match statement includes a filtering condition of a path pattern, a node that matches a path in the path pattern is queried from all nodes in the graph database based on the path, to obtain a first node set. A node that meets a matching condition in the match statement is determined from all the nodes in the graph database based on the matching condition. For each node that meets the matching condition, whether the node falls within the first node set is determined. Whether the node belongs to a query result of the match statement is determined based on a determining result. Traversing, based on the path pattern, a path of a node that matches the match statement can be simplified as matching between a node and a node set.
Claims
exact text as granted — not AI-modifiedWhat is claimed is:
1 . A data query method, wherein the data query method is applied to a graph database, and the method comprises:
receiving a match statement, wherein the match statement is configured by a user in a user interface; respectively performing syntax parsing and verification by a syntax parser and a verifier; generating, by an execution plan generator, an execution plan after the syntax parsing and the verification are succeed; determining that the match statement comprises a filtering condition of a path pattern; when the match statement comprises the filtering condition of the path pattern, optimizing the execution plan by an execution plan optimizer, and querying a node that matches a path in the filtering condition of the path pattern from all nodes in the graph database based on the path, to obtain a first node set; determining a node that meets a matching condition in the match statement from all the nodes in the graph database based on the matching condition; for each node that meets the matching condition, determining whether the node falls within the first node set; and determining, based on a determining result, whether the node belongs to a query result of the match statement, specifically comprising:
when the filtering condition of the path pattern corresponds to positive semantics of a target keyword and the node falls within the first node set, determining that the node belongs to the query result of the match statement;
when the filtering condition of the path pattern corresponds to positive semantics of the target keyword and the node does not fall within the first node set, determining that the node does not belong to the query result of the match statement;
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node falls within the first node set, determining that the node does not belong to the query result of the match statement; and
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node does not fall within the first node set, determining that the node belongs to the query result of the match statement.
2 . The method according to claim 1 , wherein the querying a node that matches a path in the filtering condition of the path pattern from all nodes in the graph database based on the path, to obtain a first node set specifically comprises:
using the filtering condition of the path pattern as a target condition, and determining another filtering condition in the match statement; determining another condition associated with the target condition from the another filtering condition based on a node identifier in the filtering condition of the path pattern and a node identifier in the another filtering condition; fusing the filtering condition of the path pattern and the another condition based on the node identifier in the filtering condition of the path pattern and the node identifier in the another condition associated with the target condition, to obtain a fused filtering condition of the path pattern; and querying a node that matches a path in the fused filtering condition of the path pattern from all the nodes in the graph database based on the path, to obtain the first node set.
3 . The method according to claim 2 , wherein the fusing the filtering condition of the path pattern and the another condition based on the node identifier in the filtering condition of the path pattern and the node identifier in the another condition associated with the target condition, to obtain a fused filtering condition of the path pattern specifically comprises:
determining an attribute value of an attribute corresponding to the node identifier in the another condition associated with the target condition; determining, as a target identifier from the node identifier in the filtering condition of the path pattern, a node identifier the same as a node identifier corresponding to the attribute value; assigning a value to an attribute of the target identifier based on the attribute value; and using, as the fused filtering condition of the path pattern, a filtering condition of the path pattern after a value is assigned to the attribute of the target identifier.
4 . The method according to claim 1 , further comprising:
when the match statement comprises the filtering condition of the path pattern, determining a first matching condition as a first statement segment based on the filtering condition of the path pattern; determining a set identifier of a node set obtained through matching based on the first statement segment; using an original matching condition in the match statement as a second matching condition, and updating the filtering condition based on the set identifier and a node identifier of a node queried based on the match statement, to obtain an updated filtering condition; generating a second statement segment based on the second matching condition and the updated filtering condition; generating an optimized match statement based on the first statement segment and the second statement segment; and executing the optimized match statement, to determine a query result.
5 . The method according to claim 4 , wherein the generating an optimized match statement based on the first statement segment and the second statement segment specifically comprises:
obtaining a preset statement template, wherein the statement template comprises an aggregation function template; determining a node identifier corresponding to a node obtained through matching based on the first statement segment; determining an aggregation function based on the node identifier corresponding to a node obtained through matching based on the first statement segment, the set identifier, and the aggregation function template, wherein the aggregation function is used to store, in the node set, the node obtained through matching based on the first statement segment; determining a connection clause based on the statement template and the aggregation function; and generating the optimized match statement based on the first statement segment, the connection clause, and the second statement segment, wherein the connection clause is used to input an output of the first statement segment into the second statement segment determined based on the match statement.
6 . A non-transitory computer-readable storage medium, having stored therein instructions that, when executed by a processor of a computing device, cause the processor to:
receive a match statement, wherein the match statement is configured by a user in a user interface; respectively perform syntax parsing and verification by a syntax parser and a verifier; generate, by an execution plan generator, an execution plan after the syntax parsing and the verification are succeed; determine that the match statement comprises a filtering condition of a path pattern; when the match statement comprises the filtering condition of the path pattern, optimize the execution plan by an execution plan optimizer, and query a node that matches a path in the filtering condition of the path pattern from all nodes in a graph database based on the path, to obtain a first node set; determine a node that meets a matching condition in the match statement from all the nodes in the graph database based on the matching condition; for each node that meets the matching condition, determine whether the node falls within the first node set; and determine, based on a determining result, whether the node belongs to a query result of the match statement, specifically comprising:
when the filtering condition of the path pattern corresponds to positive semantics of a target keyword and the node falls within the first node set, determine that the node belongs to the query result of the match statement;
when the filtering condition of the path pattern corresponds to positive semantics of the target keyword and the node does not fall within the first node set, determine that the node does not belong to the query result of the match statement;
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node falls within the first node set, determine that the node does not belong to the query result of the match statement; and
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node does not fall within the first node set, determine that the node belongs to the query result of the match statement.
7 . An electronic device, comprising a memory, a processor, wherein the memory stores executable instructions that, in response to execution by the processor, cause the processor to:
receive a match statement, wherein the match statement is configured by a user in a user interface; respectively perform syntax parsing and verification by a syntax parser and a verifier; generate, by an execution plan generator, an execution plan after the syntax parsing and the verification are succeed; determine that the match statement comprises a filtering condition of a path pattern; when the match statement comprises the filtering condition of the path pattern, optimize the execution plan by an execution plan optimizer, and query a node that matches a path in the filtering condition of the path pattern from all nodes in a graph database based on the path, to obtain a first node set; determine a node that meets a matching condition in the match statement from all the nodes in the graph database based on the matching condition; for each node that meets the matching condition, determine whether the node falls within the first node set; and determine, based on a determining result, whether the node belongs to a query result of the match statement, specifically comprising:
when the filtering condition of the path pattern corresponds to positive semantics of a target keyword and the node falls within the first node set, determine that the node belongs to the query result of the match statement;
when the filtering condition of the path pattern corresponds to positive semantics of the target keyword and the node does not fall within the first node set, determine that the node does not belong to the query result of the match statement;
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node falls within the first node set, determine that the node does not belong to the query result of the match statement; and
when the filtering condition of the path pattern corresponds to negative semantics of the target keyword and the node does not fall within the first node set, determine that the node belongs to the query result of the match statement.Join the waitlist — get patent alerts
Track US12475122B2 — get alerts on status changes and closely related new filings.
We store only your email — no account needed. See our privacy policy.