Data generation method and device, equipment and medium
By obtaining the database syntax tree and support information, building a query statement framework and generating candidate hit data, the problem of low efficiency and accuracy of SQL statement data generation in the prior art is solved, and the SQL statement execution hit rate is improved.
Patent Information
- Application Number
- CN202411292920.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-07
AI Technical Summary
In the prior art, in database SQL statement testing, the data generation efficiency and accuracy of complex SQL statements are low, resulting in low SQL statement execution hit rate.
By obtaining the database syntax tree, support function and table information of the target database, a query statement framework is built based on the probability of occurrence of syntax tree nodes, the information to be filled is determined, candidate hit data is generated and integrated, and the target data generation is achieved.
It improves the efficiency and accuracy of data generation, ensures the execution hit rate of data query statements, avoids the process of analyzing the complete SQL statement, and simplifies the data generation process.
Smart Images

Figure CN119271711A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a data generation method, device, equipment and medium. Background Art
[0002] With the continuous increase and improvement of distributed database functions, the number of test scenarios is increasing in the functional alignment of the business logic and Structured Query Language (SQL) syntax of centralized databases and historical databases. It is difficult to cover all of the above scenarios with simple manual testing. At the same time, it is difficult to find problems in empty tables in the database. Therefore, it is necessary to lay the foundation for the test scenario requirements corresponding to the corresponding database in the corresponding testing process.
[0003] In the process of testing database SQL statements in the prior art, the generated complete SQL statements are usually analyzed manually, and the database data corresponding to the SQL statements are constructed based on the corresponding analysis results. As a result, when constructing SQL statements, especially complex SQL statements, the efficiency and accuracy of corresponding data generation are low, which in turn has a negative impact on the hit rate of the corresponding SQL statement execution. Summary of the invention
[0004] The present invention provides a data generation method, device, equipment and medium to improve the efficiency and accuracy of corresponding data generation and ensure the hit rate of corresponding data query statement execution.
[0005] According to one aspect of the present invention, there is provided a data generation method, the method comprising:
[0006] Obtain the database syntax tree, database support functions, and database table information corresponding to the target database;
[0007] According to the pre-configured occurrence probability of each node in the database syntax tree, a framework of the target data query statement is constructed, and according to the database support functions and database table information, information to be filled in corresponding to each hierarchical node of the framework is determined;
[0008] According to the to-be-filled information corresponding to each hierarchical node, candidate hit data corresponding to each hierarchical node is generated, and the candidate hit data corresponding to each hierarchical node is integrated to obtain target hit data corresponding to the target query statement.
[0009] According to another aspect of the present invention, there is provided a data generating device, the device comprising:
[0010] The target database information acquisition module is used to obtain the database syntax tree, each database support function and each database table information corresponding to the target database;
[0011] The module for determining information to be filled is used to construct a framework of the target data query statement according to the pre-configured probability of occurrence of each node in the database syntax tree, and determine the information to be filled corresponding to each hierarchical node of the framework according to each database support function and each database table information;
[0012] The target hit data acquisition module is used to generate candidate hit data corresponding to each hierarchical node according to the to-be-filled information corresponding to each hierarchical node, and integrate the candidate hit data corresponding to each hierarchical node to obtain the target hit data corresponding to the target query statement.
[0013] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data generating method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data generation method described in any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided, comprising a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the data generating method as described in any embodiment of the present invention.
[0019] The technical solution of the embodiment of the present invention obtains the database syntax tree, each database support function and each database table information corresponding to the target database, and then constructs the framework of the target data query statement according to the occurrence probability of each node in the pre-configured database syntax tree, and determines the to-be-filled information corresponding to each hierarchical node of the framework based on the corresponding database support functions and each database table information, so that based on the to-be-filled information corresponding to each hierarchical node, the candidate hit data corresponding to each hierarchical node can be generated, and further the candidate hit data can be integrated to obtain the corresponding target hit data, so that in the process of generating the corresponding data query statement, based on the information filling of each hierarchical node, the corresponding target hit data can be generated synchronously, avoiding the situation where a complete data query statement needs to be generated first and then the corresponding hit data is constructed, eliminating the process of analyzing the complete SQL statement, thereby helping to improve the efficiency and accuracy of the corresponding data generation and ensure the hit rate of the corresponding data query statement execution.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 It is a flowchart of a data generation method provided according to the first embodiment of the present invention.
[0023] Figure 2 is a flowchart of another data generating method provided according to the second embodiment of the present invention.
[0024] Figure 3 is a flowchart of another data generating method provided according to Embodiment 3 of the present invention.
[0025] Figure 4 It is a structural diagram of a data generating device provided according to Embodiment 4 of the present invention.
[0026] Figure 5 It is a structural schematic diagram of an electronic device for implementing the data generating method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Figure 1 This is a flow chart of a data generation method provided in the first embodiment of the present invention. This embodiment is applicable to the case where data generation is performed synchronously during the process of generating a data query statement. The method can be executed by a data generation device, which can be implemented in the form of hardware and / or software and can be configured in an electronic device. Figure 1 Said method comprises:
[0030] S110, obtaining a database syntax tree, various database support functions, and various database table information corresponding to the target database.
[0031] Among them, the target database can be a database determined based on the database name input by the user. The database can exist in multiple types, and different types of databases can use different data query statements. For example, the database can correspond to a relational database management system MySQL, and the data query statement can be an SQL statement. The SQL statement can be a complex SQL statement or a chaotic SQL statement, which is not specifically limited here. The database syntax tree can be a data structure used to process SQL statements in a database system, and the data structure can be a tree structure. Each node in the database syntax tree can be used to represent a syntax unit, and the syntax unit can be, for example, selecting SELECT, FROM from a table, WHERE under what conditions, combining JOIN, grouping GROUP BY, and subqueries. Different databases can correspond to different database syntax trees. Each database support function can be a variety of types of functions supported by the database. The database table can be a table structure used to store data in the database. The target database can include at least one database table, and the database table information can at least include information such as table name, field name, and field type.
[0032] Specifically, after determining the target database, the database syntax tree, various database support functions and various database table information corresponding to the target database can be obtained by reading a preset configuration file corresponding to the target database.
[0033] S120, constructing a framework of a target data query statement according to the pre-configured occurrence probability of each node in the database syntax tree, and determining information to be filled in corresponding to each hierarchical node of the framework according to each database support function and each database table information.
[0034] Among them, the occurrence probability can be the probability of the grammatical unit corresponding to each node in the database syntax tree appearing when constructing a data query statement. The target data query statement can be a statement to be generated for performing data query in the target database. The corresponding framework can include multiple hierarchical nodes, and each hierarchical node can be a grammatical unit corresponding to a node included in the corresponding database syntax tree. The framework can be used to characterize the various grammatical types used by the corresponding target query statement and whether there are subqueries, etc. The information to be filled in can at least include at least one of the column fields in the database table corresponding to the corresponding hierarchical node, the type of database support function, and other expressions.
[0035] Specifically, a mapping relationship database between different occurrence probabilities corresponding to each node and the framework of different data query statements can be pre-established. Accordingly, when determining the occurrence probability corresponding to each node in the database syntax tree corresponding to the target database, the framework of the corresponding data query statement can be matched by traversing the mapping relationship database, and when the framework of the corresponding data query statement is matched, the framework of the data query statement is used as the framework of the target data query statement. It is also possible to randomly select the corresponding database support function, the column field in the database table and / or other expressions as the information to be filled in the corresponding hierarchical node when filling in the information of each layer of hierarchical nodes after obtaining the information of each database support function and each database table. Correspondingly, based on the determined information to be filled in each layer of hierarchical nodes, each layer of nodes can be filled with information to form a complete target data query statement.
[0036] S130. Generate candidate hit data corresponding to each hierarchical node according to the to-be-filled information corresponding to each hierarchical node, and integrate the candidate hit data corresponding to each hierarchical node to obtain target hit data corresponding to the target query statement.
[0037] The candidate hit data may be data expected to be queried based on the data query logic corresponding to the corresponding information to be filled in. The candidate hit data may include data with different values corresponding to each column field in the database.
[0038] Specifically, a database of mapping relationships between different information to be filled and corresponding candidate hit data can also be established. Accordingly, after determining the information to be filled in the corresponding hierarchical node, the mapping relationship database can be traversed to match the corresponding candidate hit data, and the matched candidate hit data can be used as the candidate hit data corresponding to the hierarchical node. Further, based on the candidate hit data corresponding to each hierarchical node, the column fields corresponding to each database table in the target database can be filled, and the data corresponding to each column field in each database table after filling can be used as the target hit data corresponding to the corresponding target query statement.
[0039] In an embodiment of the present invention, by obtaining a database syntax tree, each database support function and each database table information corresponding to a target database, and then constructing a framework of a target data query statement according to the occurrence probability of each node in a pre-configured database syntax tree, and based on the corresponding each database support function and each database table information, determining the information to be filled in corresponding to each hierarchical node of the framework, so that based on the information to be filled in corresponding to each hierarchical node, candidate hit data corresponding to each hierarchical node can be generated, and further by integrating each candidate hit data, corresponding target hit data can be obtained, so that in the process of generating the corresponding data query statement, based on the information filling in each hierarchical node, the corresponding target hit data can be generated synchronously, avoiding the need to generate a complete data query statement first and then construct the corresponding hit data, eliminating the process of analyzing the complete SQL statement, thereby helping to improve the efficiency and accuracy of the corresponding data generation and ensuring the hit rate of the corresponding data query statement execution.
[0040] Figure 2 This is a flow chart of a data generation method provided in the second embodiment of the present invention. This embodiment is further optimized based on the above embodiments. It should be noted that for the parts not described in detail in this embodiment, please refer to the relevant descriptions in other embodiments.
[0041] Furthermore, "determine the information to be filled in corresponding to each hierarchical node of the framework" is refined into "based on the preset filling order, determine the information to be filled in for each hierarchical node corresponding to the framework in turn; wherein the preset filling order is from inside to outside" to improve the mechanism for determining the information to be filled in. Correspondingly, "generate candidate hit data corresponding to each hierarchical node according to the information to be filled in corresponding to each hierarchical node" is refined into "when determining the information to be filled in corresponding to the current hierarchical node, construct the candidate hit data corresponding to the current hierarchical node according to the information to be filled, and use the candidate hit data as the judgment condition corresponding to the hierarchical node of the upper layer, until the generation of candidate hit data corresponding to the outermost hierarchical node is completed" to improve the generation mechanism of candidate hit data corresponding to each hierarchical node.
[0042] refer to Figure 2 , the method specifically comprises the following steps:
[0043] S210: Obtain a database syntax tree, various database support functions, and various database table information corresponding to the target database.
[0044] S220: Construct a framework of a target data query statement according to the pre-configured occurrence probability corresponding to each node in the database syntax tree.
[0045] S230. According to the database support functions and the database table information, based on a preset filling order, determine the information to be filled in for each hierarchical node corresponding to the framework in turn; wherein the preset filling order is from inside to outside.
[0046] Specifically, when filling in information for each hierarchical node corresponding to the corresponding framework, the information to be filled can be determined and filled in each hierarchical node of the framework in order from the innermost layer to the outermost layer. Correspondingly, when the information to be filled in the corresponding hierarchical node of the outermost layer is completely filled, a complete target data query statement can be obtained.
[0047] S240. When determining the information to be filled in corresponding to the current hierarchical node, construct candidate hit data corresponding to the current hierarchical node based on the information to be filled in, and use the candidate hit data as the judgment condition corresponding to the hierarchical node of the previous layer until the generation of candidate hit data corresponding to the outermost hierarchical node is completed.
[0048] Among them, the current hierarchical node can be the innermost hierarchical node of the corresponding framework, or it can be the outer hierarchical node of the hierarchical node corresponding to the information to be filled in the last time. The outer hierarchical node can also be the hierarchical node of the previous layer of the hierarchical node corresponding to the information to be filled in the last time. The judgment condition can be a logical condition in the context corresponding to the information to be filled in the previous layer. For example, the hierarchical node of the previous layer of the current hierarchical node can be a, the current hierarchical node can be a subquery select, and the statement corresponding to the current hierarchical node and the hierarchical node of the previous layer can be a in (select). Correspondingly, the data corresponding to the hierarchical node a of the previous layer is affected by the select of the current hierarchical node. Therefore, the candidate hit data corresponding to the current hierarchical node can be used as the judgment condition of the hierarchical node of the previous layer.
[0049] Specifically, after determining the candidate hit data of the innermost hierarchical node, an iterative mode can be adopted to use the candidate hit data of the innermost hierarchical node as the judgment condition for the hierarchical node in the upper layer, and to cyclically generate the candidate hit data of each hierarchical node until all the candidate hit data corresponding to all hierarchical nodes are fully generated.
[0050] Exemplarily, constructing candidate hit data corresponding to the current hierarchical node according to the information to be filled may include:
[0051] Perform logical analysis on the information to be filled in, determine the data query logic corresponding to the information to be filled in, and judge whether the information to be filled in includes the column fields in the database table; if so, determine the field type and initial value range corresponding to the column field based on the column field and the database table information corresponding to the database table; if not, determine whether the information to be filled in includes the database support function, and when the input parameter of the database support function includes the column fields in the database table, determine the field type and initial value range corresponding to the column field; determine the data generation range of the candidate hit data to be generated according to the data query logic, field type and initial value range, and generate the candidate hit data based on the data generation range.
[0052] The data query logic may be the execution logic for querying the data in each database table in the target database, for example, the corresponding data may be greater than or equal to the set value or the corresponding data may be calculated via the set database support function. The field type may be the field type to which the column field in each database table belongs, for example, it may be an int type or a char type. The initial value range may be the value range pre-configured for each column field in the database table, for example, it may be the corresponding range of the int type value or the corresponding range of the char field size. The input parameter may be the input parameter of the function.
[0053] Specifically, a database of mapping relationships between different data query logics, field types, initial value ranges, and corresponding data generation ranges can be pre-established. Accordingly, when determining the data query logic of the current hierarchical node corresponding to the information to be filled, the field type corresponding to the column field included in the information to be filled, and the initial value range corresponding to the field type, the mapping relationship database can be traversed to match the corresponding data generation range, and the matched data generation range can be used as the data generation range of the candidate hit data to be generated corresponding to the current hierarchical node. Furthermore, data that meets the data generation range can be generated based on preset generation rules, and the data can be used as the corresponding candidate hit data. Among them, the preset generation rules can be random generation or sequential generation, etc., which can be set as needed.
[0054] It can be understood that the data query logic of the corresponding hierarchical node corresponding to the information to be filled is determined through the corresponding logical analysis, and the generation range of the corresponding candidate hit data is determined based on the information to be filled itself and the column fields in the input parameters of the included database support functions, combined with the field type and initial value range of the column field in the corresponding database table. This can accurately determine the column fields and the corresponding data range in the corresponding database table corresponding to the hit of the corresponding hierarchical node, which helps to avoid omissions in the generated hit data and ensure the hit rate of the corresponding data query statement during subsequent execution.
[0055] Optionally, if the input parameter of the corresponding database support function does not include the column fields in the database table, corresponding data can be generated based on the corresponding data query logic, and the data can be used as candidate hit data for the corresponding hierarchical node.
[0056] Exemplarily, determining the data generation range of the candidate hit data to be generated according to the data query logic, field type and initial value range may include:
[0057] According to the data query logic, determine the actual value range corresponding to each field type in the candidate hit data to be generated; calculate the union between the actual value range corresponding to each field type and the initial value range, and use the union as the data generation range of the candidate hit data to be generated.
[0058] Specifically, a mapping relationship database between different data query logics and the actual value ranges corresponding to each field type can be pre-established. Accordingly, after determining the data query logic corresponding to the information to be filled in the corresponding hierarchical node, the mapping relationship database can be traversed to match the actual value ranges corresponding to the corresponding field types, and the actual value ranges corresponding to the matched field types can be used as the actual value ranges corresponding to the field types in the candidate hit data to be generated. Optionally, the actual value ranges corresponding to each field type can also be obtained through calculation and deduction based on the various logical conditions in the corresponding data query logic.
[0059] It can be understood that by using the data query logic of the corresponding hierarchical node corresponding to the information to be filled, the actual value range corresponding to each field type is determined, and the union of the actual value range and the initial value range corresponding to each field type is used as the data generation range of the corresponding candidate hit data. This can avoid repeated redundant generation of data corresponding to each field type, reduce resource usage in the process of generating the corresponding candidate hit data, and also help to improve the generation efficiency of the corresponding candidate hit data.
[0060] S250: Integrate the candidate hit data corresponding to each hierarchical node to obtain target hit data corresponding to the target query statement.
[0061] In an embodiment of the present invention, when filling information for each hierarchical node corresponding to a corresponding framework, starting from the innermost hierarchical node corresponding to the framework, the information to be filled for each hierarchical node of the framework is determined in sequence from the inside to the outside, and when determining the information to be filled corresponding to the current hierarchical node, candidate hit data corresponding to the current hierarchical node is constructed according to the information to be filled, and then the candidate hit data is used as the judgment condition corresponding to the hierarchical node of the upper layer until the generation of the candidate hit data corresponding to the outermost hierarchical node is completed, so that when filling information for each hierarchical node of the corresponding data query statement, corresponding hit data can be generated, and then while realizing the generation of the corresponding data query statement, the generation of the corresponding hit data is also realized, which helps to further improve the efficiency and accuracy of the corresponding data generation and ensure the hit rate of the execution of the corresponding data query statement.
[0062] Figure 3 This is a flow chart of a data generation method provided in Embodiment 3 of the present invention. This embodiment is further optimized based on the above embodiments. It should be noted that for the parts not described in detail in this embodiment, please refer to the relevant descriptions in other embodiments.
[0063] Further, "building the framework of the target data query statement according to the pre-configured occurrence probability corresponding to each node in the database syntax tree" is refined into "selecting one of the nodes as the current hierarchical node according to the occurrence probability corresponding to each node in the database syntax tree; recursively judging whether to continue generating the next hierarchical node based on the current hierarchical node according to the node type of the current hierarchical node and the preset recursive upper limit; wherein the node type includes at least a constant input type; building the framework of the target data query statement based on the determined hierarchical nodes." to improve the construction mechanism of the framework of the target data query statement.
[0064] refer to Figure 3 , the method specifically comprises the following steps:
[0065] S310, obtaining a database syntax tree, various database support functions, and various database table information corresponding to the target database.
[0066] S320: According to the occurrence probability of each node in the database syntax tree, one of the nodes is selected as the current hierarchical node.
[0067] Specifically, a node may be randomly selected as the corresponding current layer node based on the corresponding occurrence probability of each node. Optionally, node association information corresponding to the current layer node may be further recorded. The node association information may include information such as node type and current recursive layer number.
[0068] S330. According to the node type of the current hierarchical node and a preset recursive upper limit, recursively determine whether to continue generating hierarchical nodes of the next layer based on the current hierarchical node; wherein the node type includes at least a constant input type.
[0069] The node type may be the type of the syntax unit corresponding to the corresponding hierarchical node. The node type may include constant input, subquery, JOIN, GROUP BY, etc. The preset recursion upper limit may be a preset number of recursion layers, which may be set as needed.
[0070] Specifically, if the number of recursive layers corresponding to the current hierarchical node exceeds the corresponding preset recursive upper limit, the recursion can be terminated; if the node type of the current hierarchical node is a constant input, the recursion can also be terminated. Correspondingly, if it is determined that the current hierarchical node does not exceed the preset recursion and is not a constant input, a new hierarchical node can be generated based on the current hierarchical node. In addition, if the recursion is terminated at the current hierarchical node, the current hierarchical node can be used as the innermost node of the corresponding frame.
[0071] S340: Based on the determined hierarchical nodes, construct a framework of the target data query statement.
[0072] Specifically, after the recursion is completed, the framework of the target data query statement can be constructed based on the generated hierarchical nodes and the association relationship between the hierarchical nodes. The association relationship between the hierarchical nodes can be a relationship type such as adjacent outer layers or adjacent inner layers.
[0073] S350: Determine the information to be filled in corresponding to each hierarchical node of the framework according to each database support function and each database table information.
[0074] S360. Generate candidate hit data corresponding to each hierarchical node according to the to-be-filled information corresponding to each hierarchical node, and integrate the candidate hit data corresponding to each hierarchical node to obtain target hit data corresponding to the target query statement.
[0075] In an optional embodiment set, after obtaining the target hit data corresponding to the target query statement, the following may also be included:
[0076] Determine other column fields in each database table corresponding to the target hit data, except for the column fields included in the target hit data; based on the database table information corresponding to each database table, determine the field type and initial value range corresponding to the other column fields; according to the field type and initial value range, generate database table data corresponding to the other column fields.
[0077] Among them, other column fields may be column fields in various database tables that are not included in the target hit data.
[0078] Specifically, based on the field type and initial value range corresponding to each column field in the database table, data of the corresponding field type within the initial value range can be randomly generated, and the data can be used as data table data corresponding to the corresponding column field.
[0079] It can be understood that by determining the field type and initial value range corresponding to the other column fields based on the database table information corresponding to each database table, and generating the database table data corresponding to the other column fields according to the field type and the initial value range, it is possible to generate data for all columns included in each database table in the corresponding target database, avoid the problem of empty tables, and help to improve the functions of the corresponding target database.
[0080] In an optional embodiment, before obtaining the database syntax tree, each database support function and each database table information corresponding to the target database, the following may also be included:
[0081] Based on the pre-input target database information, the target database is determined and connected to the target database through a driver; if the target database is successfully connected, the database syntax tree, each database support function and each database table information corresponding to the target database are obtained; if the target database connection fails, the generation of target hit data corresponding to the target database is exited.
[0082] The target database information may include name information or identification information of the target database.
[0083] It can be understood that by judging whether the corresponding target database can be successfully connected through the driver after determining the target database and before starting to generate the corresponding target hit data, it is possible to avoid the waste of resources caused by the failure to successfully connect to the corresponding target database after completing the corresponding target hit data, thereby helping to save computing resources.
[0084] In an embodiment of the present invention, by selecting one of the nodes as the current hierarchical node according to the corresponding occurrence probability of each node in the database syntax tree, and then recursively judging whether to continue to generate the next layer of hierarchical nodes based on the current hierarchical node according to the node type of the current hierarchical node and a preset recursive upper limit, and constructing the framework of the target data query statement based on the determined hierarchical nodes after the recursion is completed, it is possible to automatically generate complex data query statements corresponding to the corresponding target database, thereby helping to improve the efficiency of automated testing for the target database.
[0085] Figure 4This is a schematic diagram of the structure of a data generation device provided by an embodiment of the present invention. This embodiment is applicable to the case where data generation is performed synchronously during the process of generating a data query statement. The device can be implemented in the form of hardware and / or software, and the device can be configured in an electronic device. Figure 4 Said device comprises:
[0086] The target database information acquisition module 410 is used to acquire the database syntax tree, each database support function and each database table information corresponding to the target database;
[0087] The module 420 for determining information to be filled is used to construct a framework of the target data query statement according to the pre-configured occurrence probability of each node in the database syntax tree, and determine the information to be filled corresponding to each hierarchical node of the framework according to each database support function and each database table information;
[0088] The target hit data acquisition module 430 is used to generate candidate hit data corresponding to each hierarchical node according to the to-be-filled information corresponding to each hierarchical node, and integrate the candidate hit data corresponding to each hierarchical node to obtain the target hit data corresponding to the target query statement.
[0089] The technical solution of the embodiment of the present invention obtains the database syntax tree, each database support function and each database table information corresponding to the target database, and then constructs the framework of the target data query statement according to the occurrence probability of each node in the pre-configured database syntax tree, and determines the to-be-filled information corresponding to each hierarchical node of the framework based on the corresponding database support functions and each database table information, so that based on the to-be-filled information corresponding to each hierarchical node, the candidate hit data corresponding to each hierarchical node can be generated, and further the candidate hit data can be integrated to obtain the corresponding target hit data, so that in the process of generating the corresponding data query statement, based on the information filling of each hierarchical node, the corresponding target hit data can be generated synchronously, avoiding the situation where a complete data query statement needs to be generated first and then the corresponding hit data is constructed, eliminating the process of analyzing the complete SQL statement, thereby helping to improve the efficiency and accuracy of the corresponding data generation and ensure the hit rate of the corresponding data query statement execution.
[0090] Optionally, the module 420 for determining information to be filled may include:
[0091] A unit for determining information to be filled, used to determine information to be filled for each hierarchical node corresponding to the framework in sequence based on a preset filling order; wherein the preset filling order is from inside to outside;
[0092] Accordingly, the target hit data acquisition module 430 may include:
[0093] The candidate hit data construction unit is used to construct the candidate hit data corresponding to the current hierarchical node according to the information to be filled in when determining the information to be filled in corresponding to the current hierarchical node, and use the candidate hit data as the judgment condition corresponding to the hierarchical node of the upper layer until the generation of the candidate hit data corresponding to the outermost hierarchical node is completed.
[0094] Optionally, the candidate hit data construction unit may include:
[0095] A logic and field information determination subunit, used to perform logic analysis on the information to be filled, determine the data query logic corresponding to the information to be filled, and determine whether the information to be filled includes the column fields in the database table;
[0096] a type and value range determination subunit, configured to determine, if yes, the field type and initial value range corresponding to the column field based on the column field and the database table information corresponding to the database table;
[0097] a database support function determination subunit, for determining, if not, whether the information to be filled includes the database support function, and when the input parameter of the database support function includes a column field in the database table, determining the field type and initial value range corresponding to the column field;
[0098] The candidate hit data generating subunit is used to determine the data generating range of the candidate hit data to be generated according to the data query logic, field type and initial value range, and generate the candidate hit data based on the data generating range.
[0099] Optionally, the candidate hit data generating subunit may include:
[0100] An actual value range determination subunit is used to determine the actual value range corresponding to each field type in the candidate hit data to be generated according to the data query logic;
[0101] The data generation range determination subunit is used to calculate the union of the actual value range and the initial value range corresponding to each field type, and use the union as the data generation range of the candidate hit data to be generated.
[0102] Optionally, the module 420 for determining information to be filled may include:
[0103] A current hierarchical node selection unit, configured to select one of the nodes as a current hierarchical node according to the occurrence probability of each node in the database syntax tree;
[0104] A recursive judgment unit, configured to recursively judge whether to continue to generate a hierarchical node of a next layer based on the current hierarchical node according to the node type of the current hierarchical node and a preset recursive upper limit; wherein the node type includes at least a constant input type;
[0105] The framework building unit is used to build the framework of the target data query statement based on the determined hierarchical nodes.
[0106] Optionally, the corresponding device may further include:
[0107] Other column field determination module, used for determining other column fields in each database table corresponding to the target hit data, except for each column field included in the target hit data, after obtaining the target hit data corresponding to the target query statement;
[0108] Other column field information determination module, used to determine the field type and initial value range corresponding to the other column field based on the database table information corresponding to each database table;
[0109] The module for generating data corresponding to other column fields is used to generate database table data corresponding to the other column fields according to the field type and the initial value range.
[0110] Optionally, the corresponding device may further include:
[0111] A target database connection module, used to determine the target database and connect to the target database through a driver based on the pre-input target database information before obtaining the database syntax tree, each database support function and each database table information corresponding to the target database;
[0112] A connection status judgment module is used to obtain the database syntax tree, each database support function and each database table information corresponding to the target database if the target database connection is successful;
[0113] The data generation exit module is used to exit the generation of target hit data corresponding to the target database if the target database connection fails.
[0114] The data generation device provided in the embodiment of the present invention can execute any one of the data generation methods provided in the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing each data generation method. For the contents not described in detail in the embodiment of the present invention, reference can be made to the description in any one of the data generation method embodiments of the present invention.
[0115] According to an embodiment of the present invention, the present invention also provides an electronic device, a readable storage medium and a computer program product.
[0116] Figure 5A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0117] like Figure 5 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0118] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0119] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as a data generation method.
[0120] In some embodiments, the data generation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the data generation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the data generation method in any other appropriate manner (e.g., by means of firmware).
[0121] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0122] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0123] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0124] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0125] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0126] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0127] Artificial intelligence is a discipline that studies how to use computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, machine learning / deep learning technology, big data processing technology, knowledge graph technology, and other major directions.
[0128] Cloud computing refers to a technology system that uses network access to elastically scalable shared physical or virtual resource pools. Resources can include servers, operating systems, networks, software, applications, and storage devices, and can be deployed and managed on demand and in a self-service manner. Cloud computing technology can provide efficient and powerful data processing capabilities for technical applications such as artificial intelligence and blockchain, as well as model training.
[0129] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution provided by this disclosure can be achieved, and this document does not limit this.
[0130] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A data generation method, characterized in that: include: Obtain the database syntax tree, database support functions, and database table information corresponding to the target database; According to the pre-configured occurrence probability of each node in the database syntax tree, a framework of the target data query statement is constructed, and according to the database support functions and database table information, information to be filled in corresponding to each hierarchical node of the framework is determined; According to the to-be-filled information corresponding to each hierarchical node, candidate hit data corresponding to each hierarchical node is generated, and the candidate hit data corresponding to each hierarchical node is integrated to obtain target hit data corresponding to the target query statement.
2. The method according to claim 1, characterized in that Determine the information to be filled in corresponding to each hierarchical node of the framework, including: Based on a preset filling order, determine the information to be filled in each hierarchical node corresponding to the framework in turn; wherein the preset filling order is from inside to outside; Correspondingly, according to the to-be-filled information corresponding to each hierarchical node, candidate hit data corresponding to each hierarchical node is generated, including: When determining the information to be filled in corresponding to the current hierarchical node, the candidate hit data corresponding to the current hierarchical node is constructed based on the information to be filled in, and the candidate hit data is used as the judgment condition corresponding to the hierarchical node of the previous layer until the generation of the candidate hit data corresponding to the outermost hierarchical node is completed.
3. The method according to claim 2, characterized in that According to the information to be filled, candidate hit data corresponding to the current hierarchical node is constructed, including: Performing logical analysis on the information to be filled, determining the data query logic corresponding to the information to be filled, and judging whether the information to be filled includes the column fields in the database table; If yes, determining the field type and initial value range corresponding to the column field based on the column field and the database table information corresponding to the database table; If not, determining whether the information to be filled includes the database support function, and when the input parameter of the database support function includes a column field in the database table, determining the field type and initial value range corresponding to the column field; According to the data query logic, field type and initial value range, the data generation range of the candidate hit data to be generated is determined, and based on the data generation range, the candidate hit data is generated.
4. The method according to claim 3, characterized in that According to the data query logic, field type and initial value range, the data generation range of the candidate hit data to be generated is determined, including: According to the data query logic, determine the actual value range corresponding to each field type in the candidate hit data to be generated; The union of the actual value range and the initial value range corresponding to each field type is calculated, and the union is used as the data generation range of the candidate hit data to be generated.
5. The method according to claim 1, characterized in that According to the pre-configured occurrence probability of each node in the database syntax tree, a framework of a target data query statement is constructed, including: According to the occurrence probability of each node in the database syntax tree, one of the nodes is selected as the current hierarchical node; According to the node type of the current hierarchical node and the preset recursive upper limit, recursively determine whether to continue to generate the hierarchical node of the next layer based on the current hierarchical node; wherein the node type at least includes a constant input type; Based on the determined hierarchical nodes, a framework of the target data query statement is constructed.
6. The method according to claim 1, characterized in that After obtaining the target hit data corresponding to the target query statement, the method further includes: Determine other column fields in each database table corresponding to the target hit data, except for the column fields included in the target hit data; Based on the database table information corresponding to each database table, determine the field type and initial value range corresponding to the other column fields; According to the field type and the initial value range, the database table data corresponding to the other column fields are generated.
7. The method according to claim 1, characterized in that Before obtaining the database syntax tree, each database support function and each database table information corresponding to the target database, it also includes: Based on the pre-input target database information, determine the target database and connect to the target database through the driver; If the target database is successfully connected, the database syntax tree, each database support function and each database table information corresponding to the target database are obtained; If the target database connection fails, the generation of target hit data corresponding to the target database is exited.
8. A data generating device, characterized in that: include: The target database information acquisition module is used to obtain the database syntax tree, each database support function and each database table information corresponding to the target database; The module for determining information to be filled is used to construct a framework of the target data query statement according to the pre-configured occurrence probability of each node in the database syntax tree, and determine the information to be filled corresponding to each hierarchical node of the framework according to each database support function and each database table information; The target hit data acquisition module is used to generate candidate hit data corresponding to each hierarchical node according to the to-be-filled information corresponding to each hierarchical node, and integrate the candidate hit data corresponding to each hierarchical node to obtain the target hit data corresponding to the target query statement.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the data generating method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the data generation method according to any one of claims 1 to 7 when executed.