A graph data query method and device
By deploying target fields of the entry type in GraphQL queries, the problem of unchangeable data topology relationships is solved, enabling dynamic associations between data at different levels and improving the flexibility of the query system and user experience.
Patent Information
- Application Number
- CN202210991887.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-17
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2042-08-17
AI Technical Summary
When querying with GraphQL, the topological relationships of the data cannot be changed, making it impossible to achieve dynamic associations between data at different topological levels. Furthermore, modifying the definition file will cause the query system to restart, affecting the user experience.
By deploying the target field of the entry type, the parsing logic of the target field in the query statement is implemented, so that the target field can be parsed into a query instruction that calls the parser of the entry field. Thus, after calling the parser of the entry field, the graph data can jump from one level to another, realizing dynamic association between different levels.
It enables dynamic association between different levels and types of data without modifying the definition file, improving the flexibility of the query system and the user experience.
Smart Images

Figure CN115238138B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of data query, and in particular, to a graph data query method and device. BACKGROUND
[0002] GraphQL is a query language for application programming interface (API), which can also represent a data query system using the query language. A client can query data from a server on demand through a GraphQL query statement. The server defines the types and fields of data through a schema file, so that the data is organized in the form of a graph, and then provides a parsing function for each field on each type to build a GraphQL service.
[0003] The GraphQL runtime describes the topological graph of data through a schema. When querying, the established topological relationship of data must be strictly followed. Therefore, the result of a specific query is a projection of the overall data graph described by the schema. The topological relationship of data cannot be changed, and the structure of the query result cannot be changed. SUMMARY
[0004] The embodiments of the present disclosure at least provide a graph data query method and device.
[0005] In a first aspect, the embodiments of the present disclosure provide a graph data query method, comprising:
[0006] In response to a data query request, determining a query statement indicated by the data query request;
[0007] Based on a target definition file of graph data and a plurality of field parsers corresponding to the target definition file, sequentially parsing each query field in the query statement in a predefined order. If the currently parsed query field is a target field of an entry type, the target field is parsed as a target query instruction for calling a target field parser. The target field parser is used to parse the query field of the entry type.
[0008] According to the query instructions of each query field obtained by parsing, performing data query from the graph data to generate a query result corresponding to the query statement.
[0009] In an optional implementation, the sequentially parsing each query field in the query statement based on the target definition file of graph data and the plurality of field parsers corresponding to the target definition file in a predefined order comprises:
[0010] According to a predefined order, for each query field, find the type corresponding to the query field from the target definition file;
[0011] From the plurality of field parsers corresponding to the type of the query field, filter out the field parser matching the query field;
[0012] Based on the filtered field parser, parse the query field.
[0013] In an optional implementation, if the currently parsed query field is a target field of a set entry type, the target field is parsed into a target query instruction for calling a target field parser, including:
[0014] If the currently parsed query field is a target field of a set entry type in the target definition file, a target field parser corresponding to the target field is filtered out from a plurality of field parsers corresponding to the entry type, and the target field is parsed into a target query instruction for calling a target field parser based on the target field parser.
[0015] In an optional implementation, before responding to the data query request, the method further includes:
[0016] Obtain an initial definition file of the graph data;
[0017] Add declaration information of the target field to declaration information of each type in the initial definition file to obtain the target definition file; the declaration information of the target field indicates that there is a type of the target field; the type of the target field is an entry type declared in the initial definition file.
[0018] In an optional implementation, before responding to the data query request, the method further includes:
[0019] Obtain a plurality of initial field parsers corresponding to the initial definition file;
[0020] Generate a target field parser for calling an entry field parser, and take the target field parser as a field parser corresponding to the target field;
[0021] Take the plurality of initial field parsers and the target field parser as a plurality of field parsers corresponding to the target definition file.
[0022] In an optional implementation, the method further includes:
[0023] If the current parsed query field carries the set first hidden instruction, the query result corresponding to the query field is set to be hidden.
[0024] In an optional implementation, the data query from the graph data according to the query instructions of the parsed query fields comprises:
[0025] When the query instruction indicates that the query statement is an introspection query statement for querying available data types, each type declared in the target definition file is determined to obtain a type cluster corresponding to the target definition file.
[0026] In a case where the second hidden instruction is carried in the declaration information of the entry type, the entry type is deleted from the type cluster to obtain a target type cluster.
[0027] The target type cluster is taken as the query result corresponding to the query statement.
[0028] In a second aspect, the embodiments of the present disclosure further provide a graph data query device, comprising:
[0029] A determination module is configured to determine a query statement indicated by a data query request in response to the data query request.
[0030] A parsing module is configured to parse each query field in the query statement in a predefined order based on a target definition file of graph data and a plurality of field parsers corresponding to the target definition file, and if the currently parsed query field is a target field of an entry type, the target field is parsed into a target query instruction for calling a target field parser; the target field parser is configured to parse a query field of an entry type.
[0031] A query module is configured to perform data query from the graph data according to the query instructions of the parsed query fields to generate a query result corresponding to the query statement.
[0032] In an optional implementation, when the parsing module parses each query field in the query statement in a predefined order based on a target definition file of graph data and a plurality of field parsers corresponding to the target definition file, the parsing module is configured to:
[0033] According to the predefined order, for each query field, the type corresponding to the query field is searched from the target definition file.
[0034] From the plurality of field parsers corresponding to the type of the query field, a field parser matched with the query field is screened out.
[0035] The parsing module is further configured to: based on the field parser obtained through the screening, parse the query field.
[0036] In an optional implementation, the parsing module is configured to, when performing the parsing on the query field and finding that the query field is a target field of an entry type set by the system, parse the target field into a target query instruction for invoking a target field parser.
[0037] If the target definition file indicates that the query field being parsed is a target field of an entry type set by the system, the parsing module is configured to: screen a target field parser corresponding to the target field from a plurality of field parsers corresponding to the entry type, and parse the target field into a target query instruction for invoking the target field parser based on the target field parser.
[0038] In an optional implementation, the apparatus further includes a preprocessing module configured to:
[0039] obtain an initial definition file of the graph data;
[0040] add declaration information of the target field to declaration information of each type in the initial definition file to obtain the target definition file; the declaration information of the target field indicates that the target field has a type; and the type of the target field is an entry type declared in the initial definition file.
[0041] In an optional implementation, the preprocessing module is further configured to:
[0042] obtain a plurality of initial field parsers corresponding to the initial definition file;
[0043] generate a target field parser for invoking an entry field parser, and use the target field parser as the field parser corresponding to the target field;
[0044] use the plurality of initial field parsers and the target field parser as a plurality of field parsers corresponding to the target definition file.
[0045] In an optional implementation, the parsing module is further configured to:
[0046] If the query field being parsed carries a first hidden instruction set by the system, the parsing module is configured to: set a query result corresponding to the query field as hidden.
[0047] In an optional implementation, the query module is specifically configured to:
[0048] If the query instruction indicates that the query statement is an introspection query statement for querying available data types, the query module is configured to: determine each type declared in the target definition file to obtain a type cluster corresponding to the target definition file.
[0049] In a case where the second hidden instruction is carried in the declaration information of the entry type, the entry type is deleted from the type cluster to obtain a target type cluster;
[0050] The target type cluster is taken as a query result corresponding to the query statement.
[0051] In a third aspect, the embodiments of the present disclosure further provide an electronic device, including a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the electronic device is running, the processor and the memory communicate through the bus, and the machine readable instructions are executed by the processor to perform the steps of the above first aspect or any possible implementation manner in the first aspect.
[0052] In a fourth aspect, the embodiments of the present disclosure further provide a computer readable storage medium, the computer readable storage medium stores a computer program, and the computer program is executed by a processor to perform the steps of the above first aspect or any possible implementation manner in the first aspect.
[0053] The method and device for querying graph data provided by the embodiments of the present disclosure respond to a data query request, determine a query statement indicated by the data query request, parse each query field in the query statement in a predefined order based on a target definition file of graph data and a plurality of field parsers corresponding to the target definition file, if the currently parsed query field is a target field of an entry type, parse the target field into a target query instruction for calling a target field parser, the target field parser is used to parse the query field of the entry type, and data query is performed from the graph data according to the query instructions of each parsed query field to generate a query result corresponding to the query statement. The embodiments of the present disclosure realize the parsing logic of the target field in the query statement by deploying the target field of the entry type, so that the target field can be parsed into a query instruction for calling the parser of the entry field, thereby realizing the parsing of the target field of the entry type after calling the parser of the entry field, and realizing the query of other types through the query instruction of the subsequent query statement, jumping from one level to another level of the graph data, and realizing the dynamic association between different levels and different types of data.
[0054] In order to make the above objectives, features and advantages of the present disclosure more apparent and understandable, the following preferred embodiments are specifically described below with reference to the accompanying drawings. BRIEF DESCRIPTION OF DRAWINGS
[0055] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings needed to be used in the embodiments. The drawings incorporated into the specification and form a part of the specification, which show the embodiments consistent with the present disclosure, and are used to explain the technical solutions of the present disclosure together with the specification. It should be understood that the following drawings only show some of the embodiments of the present disclosure, and therefore should not be considered as a limitation to the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor.
[0056] Figure 1 A flow chart of a graph data query method provided by an embodiment of the present disclosure is shown;
[0057] Figure 2 A schematic diagram of a data graph provided by an embodiment of the present disclosure is shown;
[0058] Figure 3 One of the schematic diagrams of an enhanced data graph provided by an embodiment of the present disclosure is shown;
[0059] Figure 4 The second schematic diagram of an enhanced data graph provided by an embodiment of the present disclosure is shown;
[0060] Figure 5 The third schematic diagram of an enhanced data graph provided by an embodiment of the present disclosure is shown;
[0061] Figure 6 A flow chart of another graph data query method provided by an embodiment of the present disclosure is shown;
[0062] Figure 7 A schematic diagram of a graph data query device provided by an embodiment of the present disclosure is shown;
[0063] Figure 8 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0064] In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure clearer, the following will combine the drawings in the embodiments of the present disclosure to make a clear and complete description of the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only some of the embodiments of the present disclosure, but not all the embodiments. The components of the embodiments of the present disclosure described and shown in the drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the claimed present disclosure, but only represents selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present disclosure.
[0065] It should be noted that similar reference numerals and letters refer to like items throughout the accompanying drawings, and once an item is defined in one drawing, it is not necessary to further define and explain it in subsequent drawings.
[0066] The term "and / or", used herein, merely describes an associated relationship, which means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the term "at least one" used herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0067] It is found through research that the GraphQL runtime describes the topological relationship diagram of data through the schema, and the query needs to strictly follow the established topological relationship of data, therefore, the result of a specific query must be a projection of the overall data graph described by the schema, the topological relationship of data cannot be changed, and the structure of the result obtained by the query cannot be changed, and dynamic association between different topological levels of data cannot be achieved without modifying the definition file, and modifying the definition file will cause the query system to restart, affecting user experience.
[0068] Based on the above research, the present disclosure provides a graph data query method, which deploys a target field of an entry type, implements target field parsing logic in a query statement, enables the target field to be parsed as a query instruction for calling a parser of an entry field, and thereby jumps from one level to another level of graph data after calling the parser of the entry field, to achieve dynamic association between different levels.
[0069] In order to facilitate the understanding of the present embodiment, first, a graph data query method disclosed by the present embodiment is introduced in detail, and the execution subject of the graph data query method provided by the present embodiment is generally a computer device with certain computing power, which includes, for example, a terminal device or a server or other processing device. In some possible implementation manners, the graph data query method can be realized by calling computer readable instructions stored in the memory by the processor.
[0070] Referring to Figure 1 The graph data query method provided by the present embodiment is shown in the flowchart, and the method includes steps S101-S102, wherein:
[0071] S101, in response to a data query request, determining a query statement indicated by the data query request.
[0072] In this step, the data query request can be a query request for graph data, and the above query statement can be a graph data query statement. The graph data query system can perform data query based on the query statement and return the queried data.
[0073] Among them, the query statement must conform to the query syntax adopted by the query system. For a graph data query system, the graph data query system can organize the data structure according to the definition file. The data organization is called graph data. The definition file can represent the topological structure of the graph data. The query statement must also conform to the topological structure defined in the definition file in order to be correctly recognized by the data query system.
[0074] The initial definition file mentioned above can be a definition file written by the developer based on the query syntax of the graph data query system. For example, the initial definition file can take the form shown below:
[0075]
[0076] The data types declared can be identified by the "Type" field. The "Type Query" field indicates the "Query" type and defines that the "Query" type includes the "Get A" field, whose type is "Class A". The "Class A" type includes the fields "A1", "A2", and "A3". The type of "A1" is "String", the type of "A2" is "Class C", and the type of "A3" is "Class D". The "Class C" type includes the field "C1", whose type is "String", and the "Class D" type includes the field "D1", whose type is "String". Here, "String" is a scalar type, while the "Class A", "Class B", "Class C", and "Class D" types are advanced data types that can have reference relationships with each other. "Query" is the entry type among the advanced data types.
[0077] Based on the initial definition file mentioned above, a data graph can be obtained, see [link / reference]. Figure 2 The diagram shown is a schematic representation of a data graph provided in this embodiment of the present disclosure. This data graph is obtained based on the initial definition file of the example described above. It includes query nodes, A-type nodes, C-type nodes, and D-type nodes. Each node identifies the data type contained in the graph data. The connection relationships between nodes represent the reference relationships between different types, and the fields corresponding to these reference relationships. It can be seen that starting from the root query node, there are two branches. There is no reference relationship between the leaf nodes of the two branches. If, after querying the data corresponding to node A2, the data corresponding to node A3 is then queried, it is necessary to return to the A-type node and then query the data corresponding to node A3. In the corresponding query statements and results, the data corresponding to node A2 and the data corresponding to node A3 are at different levels and cannot be directly associated with the same level.
[0078] For example, the query statement in the initial definition file of the above example can be as follows:
[0079]
[0080] As can be seen, in the above query statements, the query statements for data D1 and C1 cannot be placed at the same level.
[0081] Therefore, the embodiments of this disclosure preprocess the initial definition file to obtain the target definition file mentioned above. The preprocessed definition file can prevent query statements that query data D1 and C1 from being placed at the same level, thereby realizing the dynamic association of different levels of data in the query statements and query results.
[0082] In one possible implementation, the declaration information of the target field can be added to the declaration information of each field in the initial definition file to obtain the target definition file; the declaration information of the target field indicates the type of the target field; the type of the target field is the entry type declared in the initial definition file.
[0083] The target field can be a user-defined field that does not exist in the initial definition file mentioned above, in order to prevent the parser of fields that already exist in the initial definition file from being triggered.
[0084] For example, the target definition file may include:
[0085]
[0086]
[0087] The target definition file is obtained by preprocessing the initial definition file of the example above. The preprocessing adds the declaration information of the target field "_entry" to the declaration information of each field in the initial definition file. Specifically, the initial definition file can include multiple levels, each level can represent a type, and each level contains the field corresponding to that level. For example, the declaration information of the target field can be "_entry: query", where "query" is the entry type. The declaration information of the target field can be added to the declaration information of each type. Since the type of the target field is the entry type, the declaration of the target field does not need to be added to the declaration of the entry type.
[0088] After preprocessing, each type in the target definition file is associated with the entry type. See [link / reference]. Figure 3 As shown, this is one of the schematic diagrams of the enhanced data graph provided in the embodiments of this disclosure. The enhanced data graph is a data graph of the target definition file. It can be seen that the nodes corresponding to each type in the enhanced data graph can be returned to the entry node through the target field_entry.
[0089] After preprocessing the initial definition file, a field parser for the target field can be generated, enabling the target field to become a meaningful field in the query statement. The field parser can be used to parse the fields in the query statement, converting them into corresponding query instructions. The target field parser can also parse the target field into a parser that calls the entry field.
[0090] In this way, query statements can be used to dynamically associate fields at different levels. For example, when a target field exists, the above query statement can be expressed in the following form:
[0091]
[0092]
[0093] See Figure 4 and Figure 5 As shown, Figure 4 This is a second schematic diagram of the enhanced data graph provided in the embodiments of this disclosure. Figure 5 This is a third schematic diagram of the enhanced data graph provided in the embodiments of this disclosure. Under the above-mentioned query statement containing the target field, the corresponding enhanced data graph can be as follows: Figure 4 As shown, the above query statement jumps to class A by retrieving field A, then to class C by retrieving field A2, then back to the entry type by the target field_entry point, then to class A by retrieving field A again, and finally to class D by retrieving field A3. If the currently parsed query field, such as the target field and the second retrieved field A, carries a set first hidden instruction, such as "@unboxing", then the inner-level field corresponding to that instruction can be directly exposed to the outer level, achieving the effect of hiding the outer level, thus realizing the following... Figure 5 The effect shown Figure 5 In this system, queries can jump directly from category C to category D, enabling dynamic association between different levels of types.
[0094] S102. Based on the target definition file of the graph data and the multiple field parsers corresponding to the target definition file, each query field in the query statement is parsed in a predefined order. If the currently parsed query field is a target field of the set entry type, the target field is parsed into a target query instruction that calls the target field parser. The target field parser is used to parse the query field of the entry type.
[0095] In this step, the type of the query field in the query statement can be found from the target definition file. After successfully finding it, the field parser corresponding to the query field can be found among the multiple field parsers corresponding to that type, and the query field can be parsed using the found field parser.
[0096] Specifically, the predefined order can be determined according to the syntax of the query statement. According to the syntax of the query statement, the parsing order of the query field can be determined. The field parser corresponding to the query field can store the query function corresponding to the query field, which is used to query the data corresponding to the query field, and can generate a response to the query.
[0097] If the currently parsed query field is a target field, such as the above-mentioned “_entry” field, and the target field is indicated in the target definition file as an entry type field, the target field parser corresponding to the target field can be selected from the plurality of field parsers corresponding to the entry type, and a query instruction calling the target field parser can be generated.
[0098] The target field parser can be generated before the query system is started. The target field parser can have a query instruction calling the entry field parser. The plurality of initial field parsers corresponding to the initial definition file and the target field parser can be used as the plurality of field parsers corresponding to the target definition file.
[0099] In this way, when the target definition file defines a target field and the target field parser corresponding to the target field exists, the dynamic association of different levels and different types of data can be achieved without awareness.
[0100] S103, according to the query instructions of each query field parsed, performing data query from the graph data to generate the query result corresponding to the query statement.
[0101] In this step, the parsed query instruction can be executed to obtain the query result.
[0102] Further, if the query statement is an introspection query statement for querying available data types, the types declared in the target definition file can be determined to obtain a type cluster corresponding to the target definition file. Then, if the second hidden instruction, such as @hidden, is carried in the declaration information of the entry type, the entry type can be deleted from the type cluster to obtain a target type cluster, and the target type cluster can be used as the query result of the query statement.
[0103] Referring to Figure 6As shown, another graph data query method provided by the embodiment of the present disclosure is provided, the method is that the initial definition file is developed by the back-end developer, and the corresponding field parser is implemented, before the graph data query system starts to run, the initial definition file and the field parser can be initialized first, the initial definition file is enhanced, the special field_entrance is added, and the field parser corresponding to the _entrance field is generated, then the enhanced definition file and each field parser are used to initialize the graph data query system engine, and the extended instructions such as @unbox instruction and @hidden instruction are registered, so that when the query statement is constructed in the front end, the query dynamic type association can be realized by sending the query statement referring to the _entrance field and the @unbox instruction to the system, and the query data is requested, when the introspection query (the query statement is the introspection query statement described above) is carried out in the front end by integrating the integrated development environment (Integrated Development Environment, IDE), if the type referring to the @hidden instruction exists in the definition file, the field carrying the @hidden instruction can be hidden when the feedback data structure is hidden.
[0104] The graph data query method provided by the embodiment of the present disclosure responds to the data query request, determines the query statement indicated by the data query request, and sequentially analyzes each query field in the query statement in a pre-defined order based on the target definition file of the graph data and the plurality of field parsers corresponding to the target definition file, if the current analyzed query field is a target field of the set entrance type, the target field is analyzed as a target query instruction calling the target field parser, the target field parser is used to analyze the query field of the entrance type, and the query result corresponding to the query statement is generated by querying the data from the graph data according to the query instruction of each query field obtained by analysis. The embodiment of the present disclosure realizes the analysis logic of the target field in the query statement by deploying the target field of the entrance type, so that the target field can be analyzed as the query instruction calling the parser of the entrance field, thereby realizing the analysis of the entrance type after calling the parser of the entrance field, and realizing the query of other types through the query instruction of the subsequent query statement, jumping from one level to another level of the graph data, and realizing the dynamic association between different levels and different types of data.
[0105] Those skilled in the art can understand that in the above method of the specific embodiment, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process, and the specific execution order of each step should be determined by its function and possible internal logic.
[0106] Based on the same inventive concept, the embodiment of the present disclosure also provides a graph data query device corresponding to the graph data query method. Since the principle of the device in the embodiment of the present disclosure solves the problem is similar to the above-mentioned graph data query method of the embodiment of the present disclosure, the implementation of the device can be referred to the implementation of the method, and the repeated parts will not be described here.
[0107] Referring to Figure 7 FIG. 7 shows a schematic diagram of a graph data query device provided by the embodiment of the present disclosure. The device comprises:
[0108] The determining module 710 is configured to determine a query statement indicated by the data query request in response to the data query request.
[0109] The parsing module 720 is configured to parse each query field in the query statement in a predefined order based on a target definition file of the graph data and a plurality of field parsers corresponding to the target definition file. If the currently parsed query field is a target field of the set entry type, the target field is parsed into a target query instruction for calling a target field parser. The target field parser is configured to parse the query field of the entry type.
[0110] The query module 730 is configured to perform data query from the graph data according to the query instructions of the parsed query fields, and generate a query result corresponding to the query statement.
[0111] In an optional implementation, when the parsing module 720 parses each query field in the query statement in a predefined order based on a target definition file of the graph data and a plurality of field parsers corresponding to the target definition file, the parsing module 720 is configured to:
[0112] According to the predefined order, for each query field, the type corresponding to the query field is searched from the target definition file.
[0113] From the plurality of field parsers corresponding to the type of the query field, the field parser matching the query field is screened out.
[0114] The query field is parsed based on the screened field parser.
[0115] In an optional implementation, when the parsing module 720 executes the operation of parsing the target field into a target query instruction for calling a target field parser if the currently parsed query field is a target field of the set entry type, the parsing module 720 is configured to:
[0116] If the query field currently being parsed is indicated in the target definition file as a target field of an entry type set, a target field parser corresponding to the target field is selected from a plurality of field parsers corresponding to the entry type, and the target field is parsed into a target query instruction for calling the target field parser based on the target field parser.
[0117] In an optional implementation, the apparatus further includes a preprocessing module configured to:
[0118] obtain an initial definition file of the graph data;
[0119] add declaration information of the target field to declaration information of each type in the initial definition file to obtain the target definition file; the declaration information of the target field indicates that the target field is of a type; the type of the target field is an entry type declared in the initial definition file.
[0120] In an optional implementation, the preprocessing module is further configured to:
[0121] obtain a plurality of initial field parsers corresponding to the initial definition file;
[0122] generate a target field parser for calling an entry field parser, and use the target field parser as a field parser corresponding to the target field;
[0123] use the plurality of initial field parsers and the target field parser as a plurality of field parsers corresponding to the target definition file.
[0124] In an optional implementation, the parsing module 720 is further configured to:
[0125] if the query field currently being parsed carries a first hidden instruction set, a query result corresponding to the query field is set to be hidden.
[0126] In an optional implementation, the query module 730 is specifically configured to:
[0127] if the query instruction indicates that the query statement is an introspection query statement for querying available data types, determine each type declared in the target definition file to obtain a type cluster corresponding to the target definition file;
[0128] if the declaration information of the entry type carries a second hidden instruction, remove the entry type from the type cluster to obtain a target type cluster;
[0129] use the target type cluster as a query result corresponding to the query statement.
[0130] The description of the processing flow of each module in the device and the interaction flow between the modules can refer to the related description in the above method embodiments, which will not be described in detail here.
[0131] Corresponding to Figure 1 the graph data query method in the method embodiment, the electronic device 800 provided by the embodiment of the present disclosure is shown in Figure 8 , which is a structural schematic diagram of the electronic device 800 provided by the embodiment of the present disclosure, which includes:
[0132] The processor 81, the memory 82, and the bus 83; the memory 82 is used to store the execution instructions, including the internal memory 821 and the external memory 822; the internal memory 821 here is also called the internal memory, which is used to temporarily store the operation data in the processor 81 and the data exchanged with the external memory 822 such as a hard disk; the processor 81 exchanges data with the external memory 822 through the internal memory 821; when the electronic device 800 is running, the processor 81 and the memory 82 communicate through the bus 83, so that the processor 81 executes the following instructions:
[0133] In response to the data query request, determine the query statement indicated by the data query request;
[0134] Based on the target definition file of the graph data and the plurality of field parsers corresponding to the target definition file, sequentially parse each query field in the query statement in a predefined order, if the currently parsed query field is a target field of the set entry type, parse the target field into a target query instruction for calling the target field parser; the target field parser is used to parse the query field of the entry type;
[0135] According to the query instructions of each query field obtained by parsing, perform data query from the graph data to generate the query result corresponding to the query statement.
[0136] In an optional implementation, in the instructions executed by the processor 81, the target definition file based on the graph data and the plurality of field parsers corresponding to the target definition file sequentially parse each query field in the query statement in a predefined order, including:
[0137] According to the predefined order, for each query field, find the type corresponding to the query field from the target definition file;
[0138] From the plurality of field parsers corresponding to the type of the query field, filter out the field parser matched with the query field;
[0139] Based on the filtered field parser, parse the query field.
[0140] In an optional implementation, if the current parsed query field is a target field of the set entry type, the processor 81 executes instructions to parse the target field into a target query instruction for calling a target field parser.
[0141] If the current parsed query field is a target field of the set entry type, the processor 81 executes instructions to select a target field parser corresponding to the target field from a plurality of field parsers corresponding to the entry type, and parse the target field into a target query instruction for calling the target field parser based on the target field parser.
[0142] In an optional implementation, before responding to the data query request, the processor 81 further executes instructions to:
[0143] Obtain an initial definition file of the graph data.
[0144] Add declaration information of the target field to declaration information of each type in the initial definition file to obtain the target definition file; the declaration information of the target field indicates that the target field is of a type; the type of the target field is an entry type declared in the initial definition file.
[0145] In an optional implementation, before responding to the data query request, the processor 81 further executes instructions to:
[0146] Obtain a plurality of initial field parsers corresponding to the initial definition file.
[0147] Generate a target field parser for calling an entry field parser, and set the target field parser as a field parser corresponding to the target field.
[0148] Set the plurality of initial field parsers and the target field parser as a plurality of field parsers corresponding to the target definition file.
[0149] In an optional implementation, the processor 81 further executes instructions to:
[0150] If the current parsed query field carries a set first hidden instruction, set a query result corresponding to the query field as hidden.
[0151] In an optional implementation, the processor 81 executes instructions to generate a query result corresponding to the query statement from the graph data according to the parsed query instruction of each query field, including:
[0152] When the query instruction indicates that the query statement is an introspection query statement for querying available data types, each type declared in the target definition file is determined to obtain a type cluster corresponding to the target definition file;
[0153] When the second hidden instruction is carried in the declaration information of the entry type, the entry type is deleted from the type cluster to obtain a target type cluster;
[0154] The target type cluster is taken as a query result corresponding to the query statement.
[0155] The embodiment of the disclosure further provides a computer readable storage medium, and the computer readable storage medium stores a computer program. When the computer program is run by a processor, steps of the graph data query method described in the method embodiment are executed. The storage medium can be a volatile or non-volatile computer readable storage medium.
[0156] The embodiment of the disclosure further provides a computer program product, and the computer program product carries a program code. The instructions included in the program code can be used to execute the steps of the graph data query method described in the method embodiment. For details, refer to the method embodiment, and details are not described herein.
[0157] The computer program product can be specifically implemented by means of hardware, software or a combination thereof. In an optional embodiment, the computer program product is specifically embodied as a computer storage medium, and in another optional embodiment, the computer program product is specifically embodied as a software product, such as a software development kit (SDK) and the like.
[0158] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein. In several embodiments provided in the disclosure, it should be understood that the disclosed system, device and method can be implemented by other ways. The device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some communication interface, device or unit, which can be electrical, mechanical or other forms.
[0159] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e., may be located in one place, or may be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0160] In addition, each functional unit in various embodiments of the present disclosure can be integrated into one processing unit, or each unit can exist physically, or two or more units can be integrated into one unit.
[0161] If the functions are realized in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer readable storage medium executable by a processor. Based on this understanding, the technical solutions of the present disclosure essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk, and various program code storage media.
[0162] Finally, it should be noted that: the above-described embodiments are only specific embodiments of the present disclosure, used to illustrate the technical solutions of the present disclosure, and not to limit them. The protection scope of the present disclosure is not limited thereto, although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any skilled person familiar with the technical field can modify or easily think of changes to the technical solutions described in the foregoing embodiments within the technical range disclosed by the present disclosure, or make equivalent replacements to some technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A method for graph data query, characterized in that, The method comprises the following steps: obtaining an initial definition file of the graph data; adding declaration information of a target field to declaration information of each type in the initial definition file to obtain a target definition file; the declaration information of the target field indicates that the target field is of a type; the type of the target field is an entry type declared in the initial definition file, and each type of the target definition file is associated with the entry type; generating a target field parser for calling an entry field parser, and taking the target field parser as a field parser corresponding to the target field; in response to a data query request, determining a query statement indicated by the data query request; based on the target definition file of the graph data and a plurality of field parsers corresponding to the target definition file, sequentially parsing each query field in the query statement in a predefined order, if the currently parsed query field is a target field of the set entry type, parsing the target field into a target query instruction for calling a target field parser; generating a query result corresponding to the query statement from the graph data according to the query instructions of the parsed query fields.
2. The method of claim 1, wherein, The method comprises the following steps: according to the predefined order, for each query field, searching for a type corresponding to the query field in the target definition file; from the plurality of field parsers corresponding to the type of the query field, screening out a field parser matched with the query field; based on the screened field parser, parsing the query field.
3. The method of claim 1, wherein, If the currently parsed query field is a target field of the set entry type, the target field is parsed into a target query instruction for calling a target field parser. Before responding to the data query request, the method further comprises the following steps:
4. The method of claim 1, wherein, obtaining a plurality of initial field parsers corresponding to the initial definition file; taking the plurality of initial field parsers and the target field parser as a plurality of field parsers corresponding to the target definition file. The method further comprises the following steps:
5. The method of claim 1, wherein, if the currently parsed query field carries a set first hidden instruction, the query result corresponding to the query field is hidden. The method further comprises the following steps:
6. The method of claim 1, wherein, when the query instruction indicates that the query statement is an introspection query statement for querying available data types, determining each type declared in the target definition file to obtain a type cluster corresponding to the target definition file; In a case that the second hidden instruction is carried in the declaration information of the entry type, the entry type is deleted from the type cluster to obtain a target type cluster; The target type cluster is taken as a query result corresponding to the query statement.
7. A graph data query apparatus, comprising: The method comprises the steps of: A first obtaining module is configured to obtain an initial definition file of the graph data; A second obtaining module is configured to add declaration information of a target field to declaration information of each type in the initial definition file to obtain a target definition file; the declaration information of the target field indicates a type of the target field; the type of the target field is an entry type declared in the initial definition file, and each type of the target definition file is associated with the entry type; A generating module is configured to generate a target field parser for calling an entry field parser and take the target field parser as a field parser corresponding to the target field; A determining module is configured to determine a query statement indicated by a data query request in response to the data query request; An analyzing module is configured to analyze each query field in the query statement in a predefined order based on the target definition file of the graph data and a plurality of field parsers corresponding to the target definition file, and analyze the target field of the entry type set if the query field currently analyzed is the target field of the entry type set. A querying module is configured to perform data query from the graph data according to the query instruction of each query field obtained by analysis to generate a query result corresponding to the query statement.
8. An electronic device, comprising: The method comprises the steps of: A processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the electronic device is running, the processor and the memory communicate through the bus, the machine readable instructions are executed by the processor to execute the steps of the graph data query method in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to execute the steps of the graph data query method in any one of claims 1 to 6.
Citation Information
Patent Citations
Data query method and device applied to big data, equipment and product
CN113722600A
Graph model-based GraphQL query overhead optimization method
CN114896470A