Query statement generation method and device in graph query language

By analyzing and replacing the path patterns in the query statements, new query statements are generated, which solves the problem of inconsistent graph query language standards and improves generation efficiency and test coverage.

CN120407876APending Publication Date: 2025-08-01ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510457486.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-11
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

The lack of unified standards for the existing graph query languages makes it difficult to generate efficient, clear and elegant query statements. Stress testing and functional testing rely on manual handwriting, making it difficult to cover boundary situations and lack of diversity.

Method used

By analyzing the existing query statements, extracting the path query mode, performing sub-graph query in the pattern definition diagram of the graph data, and replacing the definition type with the query results to generate a new query statement.

Benefits of technology

It realizes automatic generation of diversified query statements, improves generation efficiency, reduces the difficulty of database use, and enhances test coverage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407876A_ABST
    Figure CN120407876A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a query statement generation method and device in a graph query language. According to the method, an existing first query statement written through a graph query language is obtained, a first path query mode of the first query statement is determined, and the first path query mode comprises a path composed of triple elements. Then, the first path query mode serves as a query subgraph, subgraph query is conducted in a mode definition graph of graph data, a plurality of query results are obtained, the query results are paths formed by definition types of triple elements, the definition types in the query results are used for replacing the corresponding definition types in the first query statement, and the query result is obtained; and generating a new query statement. In the query statement generation process, privacy protection needs to be carried out on involved privacy data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of this specification relate to the technical field of graph databases, and in particular, to a method and apparatus for generating query statements in a graph query language. Background Art

[0002] In the field of graph databases, using a Graph Query Language (GQL) to perform query analysis operations on databases or data warehouses has almost become routine for R & D engineers and data analysts. Graph databases can be used to store private data, and privacy protection is required during the data query process. However, since the graph query language has not yet formed a mature unified standard, there are currently multiple graph query languages coexisting. Graph query languages include, for example, ISOGQL, PGQ, Cypher, Gremlin, GSQL, etc. They have a high entry threshold, and it is not easy to write efficient, clear, and elegant GQL scripts. In terms of graph database testing, stress testing and functional testing still heavily rely on manually written test cases, making it difficult to comprehensively cover the boundary conditions in the test cases, and lacking diversity in stress test scenarios.

[0003] Therefore, it is hoped that there can be an improved solution to generate diverse query statements more efficiently. Summary of the Invention

[0004] One or more embodiments of this specification describe a method and apparatus for generating query statements in a graph query language to generate diverse query statements more efficiently. The specific technical solutions are as follows.

[0005] In a first aspect, an embodiment provides a method for generating a query statement in a graph query language, including:

[0006] Obtain an existing first query statement written in a graph query language;

[0007] Determine a first path query pattern of the first query statement, where the first path query pattern includes a path composed of triple elements;

[0008] Use the first path query pattern as a query subgraph to perform a subgraph query in the schema definition graph of the graph data, and obtain several query results, where the query results are paths composed of the defined types of triple elements;

[0009] Use the defined types in the query results to replace the corresponding defined types in the first query statement to generate a new query statement.

[0010] In one implementation, the step of determining the first path query pattern of the first query statement includes: generating a syntax tree corresponding to the first query statement; performing semantic analysis on the nodes in the syntax tree to obtain the first path query pattern.

[0011] In one implementation, the pattern definition graph is stored in a graph database. The step of performing a subgraph query in the pattern definition graph of the graph data includes: generating a second query statement for performing a subgraph query based on a path query statement template constructed by a graph query language and the first path query pattern; performing a subgraph query in the graph database based on the second query statement.

[0012] In one implementation, the step of using the defined type in the query result to replace the corresponding defined type in the first query statement includes:

[0013] Based on the correspondence between the defined type in the query result and the triple elements in the first path query pattern, and the positional correspondence between the triple elements in the first path query pattern and the triple elements in the first query statement, determining the correspondence between the defined type in the query result and the triple elements in the first query statement; based on the determined correspondence, using the defined type in the query result to replace the defined type of the corresponding triple element in the first query statement.

[0014] In one implementation, the first query statement includes attribute-related data of triple elements; the step of generating a new query statement includes:

[0015] Using the defined type in the query result to directly replace the corresponding defined type in the first query statement to obtain an intermediate statement; the intermediate statement includes attribute-related data to be replaced associated with the defined type of the first triple element;

[0016] Based on the attribute instance data of the defined type of the first triple element included in the graph data, determining first attribute-related data;

[0017] Replacing the attribute-related data to be replaced in the intermediate statement with the first attribute-related data to obtain a new query statement.

[0018] In one implementation, the step of determining the first attribute-related data includes: directly selecting attribute instance data from the attribute instance data included in the graph data as the first attribute-related data; or generating first attribute-related data within the range of the attribute instance data included in the graph data.

[0019] In one implementation, any query statement includes a matching part and a return part. The method further includes: determining, based on instance data included in the return part of the first query statement, a second triple element associated with several triple elements included in the matching part of the return part and the first query statement;

[0020] The step of generating a new query statement includes: replacing a corresponding defined type in the first query statement with the defined type in the query result to obtain a matching part of the new query statement; and generating a return part of the new query statement based on the matching part of the new query statement and the second triple element.

[0021] In one implementation, the type of the first path query pattern includes: a single-point query pattern, a one-hop path query pattern, or a multi-hop path query pattern.

[0022] In a second aspect, an embodiment provides a query statement generation device in a graph query language, including:

[0023] A statement acquisition module configured to acquire an existing first query statement written in a graph query language;

[0024] A pattern parsing module configured to determine a first path query pattern of the first query statement, where the first path query pattern includes a path composed of triple elements;

[0025] A subgraph retrieval module configured to use the first path query pattern as a query subgraph to perform a subgraph query in a schema definition graph of graph data to obtain several query results, where the query results are paths composed of defined types of triple elements;

[0026] A new statement generation module configured to replace a corresponding defined type in the first query statement with the defined type in the query result to generate a new query statement.

[0027] In a third aspect, an embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed on a computer, the computer is made to execute the method according to any one of the first aspect.

[0028] In a fourth aspect, an embodiment provides a computing device, including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method according to any one of the first aspect is implemented.

[0029] In the method and apparatus provided in the embodiments of this specification, a first path query pattern is parsed from a first query statement, multiple subgraphs identical to the first path query pattern are queried in the schema definition graph of the graph data, and the definition types of the triple elements in any one of the queried subgraphs are used to replace the corresponding definition types in the first query statement, obtaining a new query statement, so that more diverse query statements can be automatically generated based on the existing query statements, improving the generation efficiency. Description of the Drawings

[0030] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.

[0031] Figure 1 Schematic diagram of the implementation scenario of an embodiment disclosed in this application;

[0032] Figure 2 Schematic flow chart of a method for generating a query statement in a graph query language provided in the embodiment;

[0033] Figure 3 Schematic flow chart of an example of generating a query statement provided in the embodiment;

[0034] Figure 4 Schematic overall flow chart of a process for generating a query statement provided in the embodiment;

[0035] Figure 5 Schematic block diagram of a device for generating a query statement in a graph query language provided in the embodiment. Detailed Embodiments

[0036] The following describes the solutions provided in this specification with reference to the drawings.

[0037] Figure 1 Schematic diagram of the implementation scenario of an embodiment disclosed in this application. It includes a computing device, graph data, a schema definition graph of the graph data, and a query statement library. The graph data and its schema definition graph can be stored in a graph database. The graph database can be implemented in the computing device or in other devices other than the computing device. The computing device can use the existing query statements written in the graph query language as templates, and combine the given graph data and its schema definition graph to generate new query statements, so that more new query statements can be extended from one query statement.

[0038] The newly generated query statements can be stored in the query statement library. The new query statements can be used as test cases to test the query process of the graph database, or can be combined with natural language to form a corpus for training a large model, so that the large model can convert the input query statements expressed in natural language into query statements written in graph query language, realizing the translation process from human-readable natural language to database-understandable query language. That is, the large model is used to perform the task of translating natural language into graph query language (Text2GQL). Through the fine-tuned large model, users can operate on the data in the graph database system through natural language descriptions, complete data query, system operation and maintenance, system tuning, etc., which can greatly reduce the difficulty of using the database.

[0039] In the embodiments of the present application, the query statements mentioned without explicit description usually refer to query statements written using graph query language, which are used to query graph data from the graph database.

[0040] The above-mentioned graph data (dataset instance) is graph data containing instance data. The graph data contains nodes representing entities and connection edges reflecting the association relationships between the nodes. Graph data from different application fields can be used. For example, the graph data can be social network graph data, where the nodes represent users and the edges between the nodes represent the association relationships between users. The graph data can also be graph data in the financial field, where the nodes represent accounts and the edges between the nodes represent transactions between accounts. All user-related data involved in this specification is obtained after user authorization, and strict privacy protection will be carried out on the privacy data during the use process.

[0041] The schema definition of graph data refers to the graph database model, which defines the entity types in the graph data, the relationships between entities, and the attributes of entities, etc. The schema definition includes the definition types and attributes of nodes, the definition types and attributes of edges, and connection constraints. The connection constraints define which definition types of nodes can be connected to each other through which definition types of edges. The definition types of nodes and the definition types of edges can be collectively referred to as the definition types of triple elements. Graph data in different scenarios has corresponding schema definitions.

[0042] The schema definition of a graph database itself can be represented by a graph, called a schema graph (schemagraph). It uses a graph form to express the above schema definition and is also a graph specifically used to describe the graph data structure and constraints. It itself is also a graph, but the nodes and edges in it represent the schema information of the graph data, rather than the actual instance data. The schema graph is a high-level and abstract representation method used to define and manage the structure and rules of graph data. In the schema graph, nodes represent the defined types of nodes in the graph data, and edges reflect the connection constraints between nodes. The schema graph can also contain information such as the attributes of nodes and edges.

[0043] The schema graph can be stored in a graph database such as Neo4j, can be stored as an independent file, or can be stored in a database design tool.

[0044] Figure 1 The shown implementation scenario is just one implementation scenario of the embodiments of this application. Based on this implementation scenario, it can be known that the methods provided by the embodiments of this application can also be applied to more scenarios. The following combines Figure 2 to provide a detailed description of the method of this embodiment.

[0045] Figure 2 It is a flowchart of a method for generating a query statement in a graph query language provided for an embodiment. This method is executed by a computing device, and the computing device can be implemented by any device, equipment, platform, device cluster, etc. with computing and processing capabilities. This method includes the following steps.

[0046] Step S210, obtain an existing first query statement Q1 written in a graph query language (GQL).

[0047] The first query statement Q1 is any query statement written in GQL. The first query statement Q1 can be written manually. In practical applications, multiple manually written query statements can be collected in advance as templates for selection and use.

[0048] Any query statement contains a matching part (match part) and a return part (return part). The first query statement Q1 can contain the defined types and instance data of triple elements. Table 1 is an example of a query statement.

[0049] Table 1

[0050]

[0051] Among them, in the GQL query statement, parentheses are usually used to represent nodes, and square brackets are used to represent edges. The query statement in Table 1 contains instance data. For example, the name attribute of the node type location is China, and the number attribute of node p is returned. location, Developer, and PR are all defined types of nodes, and live_in and issue are defined types of edges.

[0052] The first query statement Q1 is used as a master or template for generating new query statements. The first query statement Q1 may also not contain instance data, but only contain the defined types of triple elements. For example, the query statement: match(l:location)<-[r1:live_in]-(d:Developer)-[r2:issue]->(p:PR)return p.

[0053] Step S220, determine the first path query pattern P1 of the first query statement Q1. The first path query pattern P1 contains a path composed of triple elements.

[0054] The first path query pattern P1 is the path query pattern in the first query statement Q1. The types of the first path query pattern P1 include: single-point query pattern, one-hop path query pattern, or multi-hop path query pattern, etc.

[0055] In the single-point query pattern, the first path query pattern P1 only contains nodes and can be expressed as: () or (a). a represents the node.

[0056] In the one-hop path query pattern, the first path query pattern P1 contains two nodes and one edge and can be expressed as: ()-[]-() or (a)-[b]-(c).

[0057] [[ID=!8]]In the multi-hop path query pattern, the first path query pattern P1 contains multiple nodes and multiple edges. For example, it can be expressed as ()-[]-()-[]-() or (a)-[b]-(c)-[d]-(e). The path query pattern corresponding to the query statement in Table 1 is this kind.

[0058] The first path query pattern P1 contains an abstract path composed of several nodes and edges, does not contain data such as the defined types of nodes or edges and attributes, and only contains the quantity and connection relationship of triple elements. This path can be, but is not limited to, a straight-line path, and can also be a path with forks. For example, (c) in (a)-[b]-(c)-[d]-(e) is also connected to [f]-(g). The nodes and edges in its path usually appear alternately.

[0059] In this step, when determining the first path query pattern P1 of the first query statement Q1, it can be achieved through the following steps 1 and 2.

[0060] Step 1: Generate the syntax tree corresponding to the first query statement Q1.

[0061] Step 2: Perform semantic analysis on the nodes in the syntax tree to obtain the first path query pattern P1.

[0062] Among them, the syntax tree refers to the Abstract Syntax Tree (AST). The AST is a tree-like representation of the abstract syntax structure of the source code, used to describe the syntax structure of the code and express the relationship between the various components of the code in a tree-like form. During the process of parsing the graph query language, it is necessary to perform lexical analysis, syntax analysis, and semantic analysis on the input query statement to obtain the query parse tree or logical plan; in syntax analysis, the tokens generated in lexical analysis will be used to generate the corresponding abstract syntax tree according to the syntax rules.

[0063] When step 1 is executed, the.g4 grammar file corresponding to the graph query language can be obtained, and the lexical analyzer and syntax analyzer corresponding to this grammar file can be generated using the grammar parser generation tool Antlr4. Using this lexical analyzer and syntax analyzer, the AST of the first query statement Q1 can be extracted.

[0064] In step 2, by visiting the nodes in the AST and performing semantic analysis on them, the first path query pattern P1 can be obtained.

[0065] The first query statement Q1 includes a match part and a return part. The generated AST includes nodes generated for the match part and the return part respectively.

[0066] The first path query pattern P1 is usually obtained from the match part of the query statement, that is, the first path query pattern P1 exists in the matching part of the first query statement Q1.

[0067] Step S230: Use the first path query pattern P1 as a query subgraph to perform a subgraph query in the schema definition graph of the graph data, and obtain several query results. Any one of the query results is a path formed by the defined types of triple elements. Several includes one or more.

[0068] When the schema definition graph is stored in a graph database, the second query statement Q2 can be generated using the first path query pattern P1, and a subgraph query can be performed in the graph database based on this second query statement Q2. The second query statement Q2 is used to perform a subgraph query in the graph database storing the schema definition graph.

[0069] Among them, a second query statement Q2 can be generated based on a path query statement template constructed by GQL and a first path query pattern P1. That is, the first path query pattern P1 is combined with the path query statement template to generate the second query statement Q2. The path query statement template constructed by GQL can be, for example, match p = ……, return p.

[0070] The path query statement template may include several slots to be filled. The first path query pattern P1 is filled into the corresponding slots to obtain the second query statement Q2. Alternatively, the path query statement template contains several placeholders, and the first path query pattern P1 is used to replace the corresponding placeholders to obtain the second query statement Q2.

[0071] The path query statement template may also include a matching part and a return part. When generating the second query statement Q2, the first path query pattern P1 is added to the matching part of the path query statement template.

[0072] Suppose the first path query pattern P1 is (a)-[b]-(c)-[d]-(e). Then it can be filled into the above path query statement template, specifically added to the matching part of the path query statement template, to obtain the query statement: match p = (a)-[b]-(c)-[d]-(e), return p. Using this query statement, subgraph queries can be directly performed in the graph database storing the schema definition graph to obtain several matching query results. Each query result contains the defined types of nodes or edges.

[0073] Figure 3 A flowchart of an example for generating a query statement provided for the embodiment. Among them, the path query pattern ()-[]-()-[]-() is obtained from the query statement in Table 1, and a query statement for the schema definition graph is generated based on this path query pattern: match p = (n1)-[e1]-(n2)-[e2]-(n3) return p. The generated query statement is used as a search subgraph, and subgraph search is performed in the database storing the schema definition graph to obtain 3 query results, which are entity type 1 - relationship type 1 - entity type 2 - relationship type 2 - entity type 3, entity type 3 - relationship type 2 - entity type 2 - relationship type 3 - entity type 4, and entity type 2 - relationship type 3 - entity type 4 - relationship type 4 - entity type 5.

[0074] Step S240, use the defined types in the query results to replace the corresponding defined types in the first query statement Q1 to generate a new query statement.

[0075] When several query results are obtained, for each query result, a corresponding new query statement can be obtained through step S240. For example, when the query results include paths such as path 1 and path 2, each path is a query result, and through step S240, corresponding new query statements 1, query statement 2, etc. can be obtained. Taking any one query result (a path) as an example below, the process of generating its corresponding new query statement is described.

[0076] The query result is a path of the defined type containing several triple elements, for example: entity type 1 - relationship type 1 - entity type 2 - relationship type 2 - entity type 3. Specifically, based on the correspondence relationship R1 between the defined type in the query result and the triple elements in the first query statement Q1, the defined type in the query result can be used to replace the defined type of the corresponding triple elements in the first query statement Q1 to obtain a new query statement.

[0077] The above correspondence relationship R1 can be determined based on the correspondence relationship between the defined type in the query result and the triple elements in the first path query pattern P1, and the position correspondence relationship between the triple elements in the first path query pattern P1 and the triple elements in the first query statement Q1.

[0078] For example, the first query statement Q1 is:

[0079] match(l:location)<-[r1:live_in]-(d:Developer)-[r2:issue]->(p:PR)return p (1)

[0080] The first path query pattern P1 is (l)-[r1]-(d)-[r2]-(p); a query result is: entity type 1 (org) - relationship type 1 (work_for) - entity type 2 (Developer) - relationship type 2 (issue) - entity type 3 (PR). The values in the parentheses in this query result are specific defined type values. The correspondence relationship between the defined type in this query result and the triple elements in the first path query pattern P1, and the position correspondence relationship between the triple elements in the first path query pattern P1 and the triple elements in the first query statement Q1 can be seen in Table 2.

[0081] Table 2

[0082]

[0083] In the example shown in Table 2, after using the defined type in the query result to replace the corresponding defined type in the first query statement Q1, the new query statement obtained is:

[0084] match(l:org)<-[r1:work_for]-(d:Developer)-[r2:issue]->(p:PR)return p (2)

[0085] Among them, the letters representing nodes and edges in the new query statement can be the same as those in the first query statement Q1, or different. If a certain triple element in the first query statement Q1 does not have a defined type, when generating the new query statement, the defined type in the query result can be directly inserted into this triple element. This insertion operation can also be understood as a replacement operation. That is to say, this triple element in the obtained new query statement may or may not have a defined type.

[0086] The query statement generation framework provided in this embodiment has multiplicative increase ability, and the number of query statements that this framework can generate is:

[0087] N = n template *n schema *n subgraphs

[0088] Among them, n template is the number of the first query statements Q1, that is, the number of query templates; n schema is the number of graph data in different scenarios, that is, the number of schema definitions; n subgraphs is the number of query results corresponding to each first query statement Q1, that is, the number of subgraphs retrieved from the schema-defined graph.

[0089] When a first query statement Q1 corresponds to n subgraphs query results, at least n subgraphs new query statements can be generated. For multiple query statements collected in advance as templates, several times as many new query statements can be generated. Moreover, the multiple query statements used as templates can be combined with graph data in different scenarios to generate query statements in this scenario. It can be seen that the query statement generation framework provided in this embodiment has adaptability in different scenarios and has multiplicative increase ability, and can generate query statements in multiples.

[0090] The above description is made by taking the example that the first query statement Q1 only contains the defined types of triple elements. In actual applications, there are diverse requirements for query statements, and the query statements can include attribute-related data or other numerical data.

[0091] In another embodiment of the present application, the first query statement Q1 includes attribute-related data of triple elements. Among them, the attributes include attributes of nodes or edges. There are several attributes corresponding to the defined types of triple elements included in the schema definition.

[0092] For example, assume that the first query statement Q1 is:

[0093] match(l:location{name:'China'})<-[r1:live_in]-(d:Developer)-[r2:issue]->(p:PR)return p (3)

[0094] Among them, this query statement contains the name attribute of the node type location. Attribute-related data refers to data associated with attributes.

[0095] When generating a new query statement in step S240, the following steps 3 to 5 can be followed.

[0096] Step 3, directly replace the corresponding defined type in the first query statement Q1 with the defined type in the query result to obtain the intermediate statement M1. Among them, the intermediate statement M1 contains the attribute-related data to be replaced associated with the defined type of the first triple element.

[0097] In this step, the process of directly replacing the corresponding defined type in the first query statement Q1 with the defined type in the query result is the same as the implementation method of step S240 in the previous embodiment. The difference is that the obtained result after replacement cannot be used as a new query statement because the intermediate statement M1 still contains the attribute-related data to be replaced.

[0098] The intermediate statement obtained after replacing the query statement (3) with the query result in Table 2 is:

[0099] match(l:org{name:'China'})<-[r1:work_for]-(d:Developer)-[r2:issue]->(p:PR)return p (4)

[0101] Among them, {name:'China'} in the query statement (4) is the attribute-related data to be replaced associated with the defined type org of the node l. The node l is the first triple element in this example.

[0102] Step 4, determine the first attribute-related data based on the attribute instance data of the defined type of the first triple element included in the graph data. The first triple element can be a node or an edge.

[0103] The graph data can be the graph data stored in the graph database to be tested, which contains instance data. The attribute instance data of the defined type of the first triple element can be stored in a table rather than in the graph database. Therefore, the first attribute-related data can be directly determined based on the data in the table.

[0104] When determining the first attribute-related data, the attribute instance data can be directly selected from the attribute instance data included in the graph data as the first attribute-related data. For example, in the query statement (3), the instance data of the attribute "name" can be obtained by direct selection.

[0105] It can also be to generate the first attribute-related data within the range based on the range of the attribute instance data included in the graph data. For example, for the attribute "high", when generating the first attribute-related data, it can be generated based on the attribute instance data included in "high". Assuming that "high" is in the range from 0 to 100, then the first attribute-related data can be generated within this range, such as {high > 50}.

[0106] Step 5, replace the attribute-related data to be replaced in the intermediate statement M1 with the first attribute-related data to obtain a new query statement.

[0107] For example, in Figure 3 , by using the 3 query results to replace the first query statement Q1 and combining with the attribute instance data in the graph data, at least the following 3 new query statements can be obtained, as shown in Table 3.

[0108] Table 3

[0109]

[0110] The query statements in Table 3 are the new query statements obtained based on the query statements in Table 1. It can be understood that when the query results contain 3, at least 3 new query statements can be obtained. In fact, more new query statements can be obtained by changing the attribute-related data.

[0111] In this embodiment, when the first query statement Q1 contains attribute-related data, the attribute instance data of a certain edge or node in the graph data can be used as the corresponding attribute-related data in the new query statement, thereby improving the diversity of the new query statement. At the same time, it also enables the new query statement to be used as a test case and truly used in the test of the graph database, so that the test process can return the correct query result.

[0112] When the first query statement Q1 also contains numerical-related data, corresponding numerical values can be randomly generated when generating the new query statement to obtain different query statements.

[0113] As described above, any query statement can include a match part and a return part. For the return part, replacement can also be performed to generate new content.

[0114] In another embodiment of the present application, after step S210, the following step 6 can also be executed.

[0115] Step 6: Based on the instance data included in the return part of the first query statement Q1, determine the second triple elements associated with several triple elements included in the match part of the return part and the match part of the first query statement Q1. The second triple elements can be nodes or edges.

[0116] When generating a new query statement in step S240, the defined type in the query result can be used to replace the corresponding defined type in the first query statement Q1 to obtain the match part of the new query statement. Based on the match part of the new query statement and the second triple elements, the return part of the new query statement is generated.

[0117] For example, in the example shown in Table 1, the return part is the number attribute of node p in the match part. After generating the match part of the new query statement, the return part in the new query statement can be generated based on the attributes of node p in the match part. For example, a new attribute can be selected from several attributes of node p as the return part in the new query statement.

[0118] Figure 4 It is a schematic diagram of the overall process of a query statement generation process provided for the embodiment. It includes a parsing process and a query process. In the parsing process, the input data is the existing query statement and the syntax file of the graph query language, and the output data is the path query pattern match pattern of the existing query statement and the return items of the return part. The parser in the parsing process generates an AST based on the input data and obtains the output data based on the analysis of the AST.

[0119] In the query process, the input data is the dataset instance and the schema definition of the dataset, and the output data is the new query statement. In the query process, the pattern definition graph query generator generates a query based on the match pattern and return items obtained in the parsing process, performs a subgraph query in the schema graph, obtains several query results, that is, subgraphs, and replaces the existing query statement based on the several subgraphs to obtain the new query statement.

[0120] In the above embodiments, only the existing query statement itself needs to be used as a template to generate query statements. The process of generating query statements is not complicated, reducing the learning cost of using the framework. Moreover, through the complete retrieval of the schema definition graph in the embodiments, all possible query statements on a single data set under the same query pattern can be generated, achieving the completeness of statement generation.

[0121] In this specification, the "first" in terms such as the first query statement, the first path query pattern, the first triple element, and the first attribute-related data, as well as the corresponding "second" (if any) in the text, are only for the convenience of distinction and description and do not have any limiting meaning.

[0122] The above content describes specific embodiments of this specification, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be executed in a different order than in the embodiments, and the desired results can still be achieved. Additionally, the processes depicted in the drawings do not necessarily have to be executed in the specific order or continuous order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0123] Figure 5 A schematic block diagram of a query statement generation device in a graph query language provided for the embodiments. This device embodiment corresponds to Figure 2 the method embodiment shown. The device 500 is deployed in a computing device and includes:

[0124] A statement acquisition module 510, configured to acquire an existing first query statement written in the graph query language;

[0125] A pattern parsing module 520, configured to determine a first path query pattern of the first query statement, where the first path query pattern includes a path composed of triple elements;

[0126] A subgraph retrieval module 530, configured to use the first path query pattern as a query subgraph to perform a subgraph query in the schema definition graph of the graph data, obtaining several query results, where the query results are paths composed of the defined types of triple elements;

[0127] A new statement generation module 540, configured to generate a new query statement by replacing the corresponding defined type in the first query statement with the defined type in the query results.

[0128] In one implementation, the pattern parsing module 520 is specifically configured to: generate a syntax tree corresponding to the first query statement, and perform semantic analysis on the nodes in the syntax tree to obtain the first path query pattern.

[0129] In one implementation, the pattern definition graph is stored in a graph database. The sub-graph retrieval module 530 includes:

[0130] A statement generation sub-module 31, configured to generate a second query statement for sub-graph query based on a path query statement template constructed by a graph query language and a first path query pattern;

[0131] A sub-graph query sub-module 32, configured to perform a sub-graph query in the graph database based on the second query statement.

[0132] In one implementation, the new statement generation module 540 includes: determining the correspondence between the defined type in the query result and the triple element in the first path query pattern, and the positional correspondence between the triple element in the first path query pattern and the triple element in the first query statement, to determine the correspondence between the defined type in the query result and the triple element in the first query statement; based on the determined correspondence, using the defined type in the query result to replace the defined type of the corresponding triple element in the first query statement.

[0133] In one implementation, the first query statement contains attribute-related data of triple elements. The new statement generation module 540 includes:

[0134] An intermediate language sentence sub-module 41, configured to directly replace the corresponding defined type in the first query statement with the defined type in the query result to obtain an intermediate statement, where the intermediate statement contains the attribute-related data to be replaced associated with the defined type of the first triple element;

[0135] A data determination sub-module 42, configured to determine first attribute-related data based on the attribute instance data of the defined type of the first triple element included in the graph data;

[0136] A statement generation sub-module 43, configured to replace the attribute-related data to be replaced in the intermediate statement with the first attribute-related data to obtain a new query statement.

[0137] In one implementation, the data determination sub-module 42 is specifically configured to directly select attribute instance data from the attribute instance data included in the graph data as the first attribute-related data. Or,

[0138] The data determination sub-module 42 is specifically configured to generate first attribute-related data within the range of the attribute instance data included in the graph data.

[0139] In one implementation, any query statement includes a matching part and a return part. The apparatus 500 further includes: an element association module 550 configured to determine, based on instance data included in the return part of the first query statement, a second triple element associated with a plurality of triple elements included in the matching part of the first query statement in the return part.

[0140] The new statement generation module 540 includes: replacing a corresponding defined type in the first query statement with the defined type in the query result to obtain a matching part of a new query statement; and generating a return part of the new query statement based on the matching part of the new query statement and the second triple element.

[0141] In one implementation, the types of the first path query pattern include: a single-point query pattern, a one-hop path query pattern, or a multi-hop path query pattern.

[0142] The above apparatus embodiments correspond to the method embodiments. For specific descriptions, reference can be made to the descriptions in the method embodiment part, which will not be elaborated here. The apparatus embodiments are obtained based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. For specific descriptions, reference can be made to the corresponding method embodiments.

[0143] The embodiments of the present specification also provide a computer-readable storage medium, on which a computer program is stored. When the computer program is executed on a computer, the computer is made to execute Figures 1 to 4 the method according to any one of the above.

[0144] The embodiments of the present specification also provide a computing device, including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method according to Figures 1 to 4 any one of the above is implemented.

[0145] The embodiments in the present specification are all described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the embodiments of the storage medium and the computing device, since they are basically similar to the method embodiments, the descriptions are relatively simple. For the relevant parts, reference can be made to the partial descriptions of the method embodiments.

[0146] Those skilled in the art should be able to realize that, in one or more of the above examples, the functions described in the embodiments of the present invention can be implemented by hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.

[0147] The specific embodiments described above further elaborate on the objectives, technical solutions, and beneficial effects of the embodiments of the present invention. It should be understood that the above description is only the specific embodiments of the embodiments of the present invention and is not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solutions of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for generating a query statement in a graph query language, comprising: Obtaining an existing first query statement written in the graph query language; Determining a first path query pattern of the first query statement, the first path query pattern including a path composed of triple elements; Using the first path query pattern as a query subgraph to perform a subgraph query in a schema definition graph of graph data, obtaining a plurality of query results, the query results being paths composed of defined types of triple elements; Generating a new query statement by replacing a corresponding defined type in the first query statement with the defined type in the query results.

2. The method according to claim 1, wherein the step of determining the first path query pattern of the first query statement comprises: Generating a syntax tree corresponding to the first query statement; Performing semantic analysis on nodes in the syntax tree to obtain the first path query pattern.

3. The method according to claim 1, wherein the pattern definition graph is stored in a graph database; The step of performing a subgraph query in the schema definition graph of graph data comprises: Based on a path query statement template constructed by the graph query language and the first path query pattern, generating a second query statement for performing a subgraph query; Based on the second query statement, performing a subgraph query in the graph database.

4. The method according to claim 1, wherein the step of replacing a corresponding defined type in the first query statement with the defined type in the query results comprises: Based on the correspondence between the defined type in the query results and the triple elements in the first path query pattern, and the positional correspondence between the triple elements in the first path query pattern and the triple elements in the first query statement, determining the correspondence between the defined type in the query results and the triple elements in the first query statement; Based on the determined correspondence, using the defined type in the query results to replace the defined type of the corresponding triple element in the first query statement.

5. The method according to claim 1, wherein the first query statement includes attribute-related data of triple elements; The step of generating a new query statement comprises: Directly replacing the corresponding defined type in the first query statement with the defined type in the query results to obtain an intermediate statement; the intermediate statement includes data related to a to-be-replaced attribute associated with the defined type of the first triple element; Based on the attribute instance data of the defined type of the first triple element included in the graph data, determining first attribute-related data; Replacing the data related to the to-be-replaced attribute in the intermediate statement with the first attribute-related data to obtain a new query statement.

6. The method according to claim 5, wherein the step of determining the first attribute-related data comprises: Directly selecting attribute instance data from the attribute instance data included in the graph data as the first attribute-related data; Or, Based on the range of the attribute instance data included in the graph data, generating first attribute-related data within the range.

7. The method according to claim 1, wherein Any query statement includes a matching part and a return part; The method further comprises: Determine a second triple element associated with some triple elements included in a matching part of the return part and the first query statement based on instance data included in the return part of the first query statement; The step of generating a new query statement includes: Replace a corresponding defined type in the first query statement with the defined type in the query result to obtain a matching part of the new query statement; Generate a return part of the new query statement based on the matching part of the new query statement and the second triple element.

8. The method according to claim 1, wherein the types of the first path query mode include: Single-point query mode, one-hop path query mode or multi-hop path query mode.

9. A query statement generation device in a graph query language, comprising: A statement acquisition module configured to acquire an existing first query statement written in a graph query language; A mode parsing module configured to determine a first path query mode of the first query statement, where the first path query mode includes a path composed of triple elements; A subgraph retrieval module configured to use the first path query mode as a query subgraph to perform a subgraph query in a schema definition graph of graph data to obtain a plurality of query results, where the query results are paths composed of defined types of triple elements; A new statement generation module configured to generate a new query statement by replacing the corresponding defined type in the first query statement with the defined type in the query result.

10. A computer-readable storage medium, on which a computer program is stored. When the computer program is executed on a computer, the computer is made to execute the method according to any one of claims 1-8.

11. A computing device, including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method according to any one of claims 1-8 is implemented.