Method and device for generating database association table test data
By obtaining the correlation fields and generation rules of the association table, pre-generate and regenerate test data, and ensuring the correlation and distribution rules of the data based on the distribution model, the problems of poor quality and low generation efficiency in the existing technology are solved, and high-quality test data generation is achieved.
Patent Information
- Application Number
- CN202411654146.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-21
AI Technical Summary
When existing database test data generation tools deal with complex associated data models, they have problems such as poor data correlation, fixed ratio of fact tables to dimension tables, and inability to fully simulate real data distribution, resulting in poor quality of test data and low generation efficiency.
By obtaining the correlation fields, generation rules and quantity of the main table of the association table, pre-generate the initial test data, and regenerate new test data based on the configured distribution model (such as uniform distribution or normal distribution) to form a new data set to ensure that the data correlation and distribution rules conform to the real scenario.
It realizes the generation of high-quality test data, improves the effectiveness of test data and the reliability of test results, improves data quality and generation efficiency, and can better simulate complex business scenarios.
Smart Images

Figure CN119669185A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of database technology, and more specifically, relates to a method and device for generating test data of a database association table. Background Art
[0002] In database testing, tools for automatically generating test data have been widely used and have become an important tool in software development, testing, and continuous integration processes. However, existing data generation methods have certain limitations when dealing with complex relational data models, which are specifically reflected in the following aspects: 1. Random generation lacks relevance: Existing technologies usually rely on randomly generated data, and the relevance between tables is poor. This means that although the generated data meets the field type and format requirements, the foreign keys or associated fields between tables lack logic and consistency, and cannot effectively simulate the complex data relationships in the production environment.
[0003] 2. Fixed ratio generation of fact tables and dimension tables: For some scenarios, existing tools generate data for fact tables and dimension tables based on a fixed ratio, which makes it difficult to reflect the complex data distribution and dynamic ratios in the real production environment. The data model generated in this way cannot accurately simulate actual business scenarios such as many-to-many and one-to-many, affecting the accuracy of the test results.
[0004] 3. Insufficient simulation of real scenarios: Existing data generation tools mainly generate data randomly based on uniform distribution, which makes it difficult to support more diverse distribution models. For example, the normal distribution and discrete distribution commonly seen in production environments cannot be fully simulated, resulting in large differences between the generated data and the actual business scenarios, affecting test coverage and reliability.
[0005] These deficiencies make it impossible for existing technologies to fully and accurately reflect the data relationships and distribution patterns in real business scenarios, thereby affecting the validity of test data and the reliability of test results, resulting in poor data quality and low data generation efficiency in complex scenarios. Summary of the invention
[0006] In view of the defects of the prior art, the purpose of the present application is to provide a method and device for generating test data of a database association table, aiming to solve the problems of poor data quality and low data generation efficiency of test data in complex scenarios.
[0007] To achieve the above object, the present application provides a method for generating test data of a database association table, which is characterized by comprising: Obtaining the associated fields, generation rules and generation quantity of the associated table master table; the associated table is composed of at least two data tables; Pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in the pre-generation set; Determine that the associated field of the main table has been configured with a distribution model, use the initial test data in the pre-generated set as a value range, regenerate new test data based on the distribution model, store the new test data and overwrite the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
[0008] Optionally, when the distribution model is uniform distribution, the method for generating new test data includes: Determine the number of pre-generated sets and the current number of generations; Calculate the length of the pre-generated set, and calculate the first mapping index of the current generation number mapped to the pre-generated set; The corresponding new test data is obtained from the pre-generated set according to the first mapping index and the length of the pre-generated set.
[0009] Optionally, when the distribution model is a normal distribution, the method for generating new test data includes: Determine the mean and standard deviation, and generate normally distributed random numbers; The normally distributed random number is used to obtain a random number, and a boundary adjustment is performed based on the generated random number to ensure that the index value is within the range of the generated number.
[0010] Optionally, the obtaining of random numbers using the normally distributed random numbers and performing boundary adjustment according to the generated random numbers to ensure that the index value is within the range of the generated number include: generating a second mapping subscript based on the mean, the standard deviation, and the normal distribution number; Ensure that the second mapping subscript is between 0 and the generated number. If the second mapping subscript is less than 0, the second mapping subscript is 0. If the second mapping subscript is greater than n, the second mapping subscript is n-1. The corresponding element is obtained from the pre-generated set according to the value of the second mapping index to generate the new test data.
[0011] Optionally, the method further comprises: It is determined that the associated fields of the main table are not configured with a distribution model, and test data for each field in the data table is generated one by one.
[0012] Optionally, after generating test data for each field in the data table one by one, the method further includes: Determining that the field is a relational field; If the field is a main table associated field, the corresponding test data is sequentially obtained from the pre-generated set according to the currently generated quantity; If the field is a slave table associated field and the distribution model is not set, the corresponding test data is sequentially obtained from the pre-generated set according to the current generated quantity; If the field is a slave table associated field and a distribution model has been set, the initial test data in the pre-generated set is used as a value range, and new test data is regenerated based on the distribution model.
[0013] Optionally, it also includes: Determine that the field is a common field; It is determined that the field is not an association table field and does not exist in the pre-generated set, and the test data is generated according to a generation rule and a distribution model.
[0014] In a second aspect, the present application further provides a device for generating test data of a database association table, comprising: An acquisition module, used to acquire the associated fields, generation rules and generation quantity of the associated table master table; the associated table is composed of at least two data tables; A pre-generation module, used to pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in a pre-generation set; A regeneration module, used for determining that the associated fields of the main table have been configured with a distribution model, using the initial test data in the pre-generated set as a value range, regenerating new test data based on the distribution model, storing the new test data and overwriting the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
[0015] In a third aspect, the present application provides an electronic device comprising: at least one memory for storing programs; and at least one processor for executing the programs stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method described in the first aspect or any possible implementation of the first aspect.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method described in the first aspect or any possible implementation of the first aspect.
[0017] In a fifth aspect, the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the method described in the first aspect or any possible implementation of the first aspect.
[0018] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0019] In general, the above technical solutions conceived by this application have the following beneficial effects compared with the prior art: (1) By configuring the associated fields and generation rules of the main table, this application can automatically generate data according to the relational model, reducing the possibility of manual intervention and human errors; and can simultaneously generate data for multiple associated tables and independent tables to ensure consistency and authenticity. This application generates high-quality test data through precise rule settings and diverse distribution models, thereby improving the validity of test data and the reliability of test results, improving the data quality and data generation efficiency of test data in complex scenarios, and can provide effective data support for subsequent test cases.
[0020] (2) By combining distribution models such as uniform distribution and normal distribution, the generation of test data in this application can be more representative in actual scenarios, making the test data as close to the actual distribution as possible. The appropriate distribution model can be flexibly selected according to specific business needs, and appropriate data support can be provided for diverse testing needs.
[0021] (3) Since the present application generates data in memory according to rules, it can efficiently generate a large amount of test data, thereby performing a large amount of data testing in a short period of time. According to the data attributes (such as association relationships and distribution models) generated and configured in advance, the system resources can be used more targetedly when storing and processing data, thereby improving data quality and test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is one of the flow charts of the method for generating database association table test data provided in the embodiment of the present application; Figure 2 This is a second flow chart of a method for generating database association table test data provided in an embodiment of the present application; Figure 3 It is a structural schematic diagram of a device for generating database association table test data provided in an embodiment of the present application; Figure 4 is a user operation timing diagram provided by an embodiment of the present application; Figure 5 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0024] The term "and / or" in this article is a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The symbol " / " in this article indicates that the associated objects are in an or relationship, for example, A / B means A or B.
[0025] The terms "first" and "second" in the specification and claims herein are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first response message and a second response message are used to distinguish different response messages rather than to describe a specific order of the response messages.
[0026] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0027] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two. For example, multiple processing units refer to two or more processing units, etc.; multiple elements refer to two or more elements, etc.
[0028] First, the technical terms involved in the embodiments of the present application are introduced.
[0029] (1) Association table: There is an association relationship between two or more data tables. There are three main types of relationships: one-to-one, one-to-many, and many-to-many. In this invention, we focus on one-to-one and one-to-many. Many-to-many relationships are achieved by adding an intermediate association table. For example, the association between table A and table B is many-to-many. In terms of storage, an intermediate table C is added, and AC and CB are implemented as one-to-many and many-to-one.
[0030] (2) Independent table: An independent table stores the data of an entity and does not rely on other tables to provide complete information, that is, it has no association with other tables.
[0031] (3) Master table and slave table: If table B depends on the data in table A, then table A is called the master table and table B is called the slave table.
[0032] (4) Association relationship and association field: The logical association between the primary table and the secondary table. The field used to establish the association relationship is called the association field.
[0033] (5) Pre-generated set: A set that temporarily stores generated data. The table name and fields correspond to a unique set.
[0034] (6) Range: The set of all valid values that a field (column) may contain.
[0035] Next, the technical solutions provided in the embodiments of the present application are introduced.
[0036] Reference Figure 1 The present application provides a method for generating test data of a database association table, which is characterized by comprising: S101. Obtaining the associated fields, generation rules and generation quantity of the associated table master table; the associated table is composed of at least two data tables; S102. Pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in the pre-generated set; S103. Determine that the main table associated field has been configured with a distribution model, use the initial test data in the pre-generated set as the value range, regenerate new test data based on the distribution model, store the new test data and overwrite the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
[0037] Specifically, first, through S101, extract the fields involved in the association for the main table and the associated table. This may include foreign key fields or other necessary identifiers. Clarify the rules for generating data, such as: field type (integer, string, date, etc.); value range or specific format (such as email format, date format); relationship constraints, etc. According to the test requirements, specify the amount of data to be generated. This is usually reasonably estimated based on the scale and complexity of the test, such as generating 1,000 order data.
[0038] Secondly, through S102, a data storage structure is created, such as a SQL database table, a NoSQL collection, or a CSV file, to store the generated initial test data. The process is as follows: according to the extracted generation rules and quantity, the program automatically generates data that conforms to the rules. The generated initial test data is stored in a pre-generated collection for subsequent use.
[0039] Finally, in S103, according to the generation rules and requirements, the required distribution model (eg, uniform distribution, normal distribution) is configured to determine the distribution mode that each field should follow.
[0040] Generate new data using the distribution model, using the initial test data in the pre-generated set as the value range. For example, if the data in a field is normally distributed, regenerate more realistic test data by setting the mean and standard deviation. Store the generated new test data and overwrite the original pre-generated set to form the final new data set.
[0041] The embodiment of the present application accurately generates test data that meets business logic and requirements through multiple steps, and through the process of obtaining data, generating data, and storing data, to ensure efficient data generation in a complex database environment. By reasonably configuring the distribution model, the generated data can better simulate real scenarios during the test process, improve the validity of the data and the reliability of the test results, and at the same time improve the efficiency and effectiveness of the test.
[0042] The embodiment of the present application can automatically generate data according to the relational model by configuring the associated fields and generation rules of the main table, reducing the possibility of manual intervention and human errors; and can simultaneously generate data of multiple associated tables and independent tables to ensure consistency and authenticity. The present application generates high-quality test data through precise rule settings and diverse distribution models, thereby improving the validity of test data and the reliability of test results, improving the data quality and generation efficiency of test data in complex scenarios, and can provide effective data support for subsequent test cases.
[0043] Optionally, when the distribution model is uniform distribution, the method for generating new test data includes: Determine the number of pre-generated sets and the current number of generations; Calculate the length of the pre-generated set, and calculate the first mapping index of the current generation number mapped to the pre-generated set; The corresponding new test data is obtained from the pre-generated set according to the first mapping index and the length of the pre-generated set.
[0044] Specifically, before starting to generate new test data, we first need to determine the total number of pre-generated data sets, which are the pre-generated sets, denoted as , denoted as n, and the current number of generation, denoted as index. The number of generation is usually the number set before, such as 1000 records. The current number of generation is a cumulative counter used to record the current number of generation cycles so that subsequent data generation can be correctly mapped to the data in the pre-generation set.
[0045] Secondly, obtain the total length of the current pre-generated set, recorded as length, to help with subsequent index calculations to ensure that the generated data does not exceed the boundaries of existing records. By mapping the current number of generation times to the length of the pre-generated set, the index that the new test data needs to select from the pre-generated set is determined, and the current number of generation times index is mapped to the pre-generated set. , the first mapping is marked as ; Finally, use the calculated first mapping index to obtain the corresponding new test data from the pre-generated set and store it in the final new test data set. The elements in can be mapped one by one, as shown in the following formula:
[0046] Here, % means taking the remainder, which ensures that the index index′ is always in the valid range (i.e., from 0 to length−1).
[0047] For example, if R′ has 3 elements (say A, B, C), then: When index=1, R1=R′[1%3]=R′[1]=B; When index=2, R2=R′[2%3]=R′[2]=C; When index=3, R3=R′[3%3]=R′[0]=A.
[0048] The embodiment of the present application can effectively obtain new test data from the pre-generated set based on the concept of uniform distribution, ensuring the diversity and uniformity of the generated data, while avoiding errors caused by index out of bounds. When the current number of generation increases, the data in the pre-generated set can be intelligently recycled, thereby ensuring the validity of the data while meeting the growing test needs.
[0049] Optionally, when the distribution model is a normal distribution, the method for generating new test data includes: Determine the mean and standard deviation, and generate normally distributed random numbers; The normally distributed random number is used to obtain a random number, and a boundary adjustment is performed based on the generated random number to ensure that the index value is within the range of the generated number.
[0050] Further, the method of obtaining a random number using the normally distributed random number and performing boundary adjustment according to the generated random number to ensure that the index value is within the range of the generated number includes: generating a second mapping subscript based on the mean, the standard deviation, and the normal distribution number; Ensure that the second mapping subscript is between 0 and the generated number. If the second mapping subscript is less than 0, the second mapping subscript is 0. If the second mapping subscript is greater than n, the second mapping subscript is n-1. The corresponding element is obtained from the pre-generated set according to the value of the second mapping index to generate the new test data.
[0051] In this embodiment, the mean and standard deviation are first determined, and a normally distributed random number is generated; the mean and standard deviation are two basic parameters of a normal distribution. The mean determines the center position of the data, and the standard deviation determines the degree of dispersion of the data. These parameters are used to generate a random number that conforms to a normal distribution.
[0052] It should be noted that the implementation of normal distribution random numbers is not discussed here, and the specific implementation is provided during programming. For example, in the Java language, java.util.Random provides the nextGaussian method to directly obtain normal distribution random numbers.
[0053] A second mapping subscript is generated based on the mean, standard deviation, and normal distribution number, as shown in the following formula:
[0054] By generating a normal distribution random number, the mean, standard deviation and normal distribution number are converted into an index subscript and mapped to the range of the pre-generated set. After obtaining the second mapping subscript, data can be extracted from the pre-generated set according to this index.
[0055] Furthermore, the validity of the second mapping index needs to be ensured.
[0056] First, we need to specify the number of generated n, which represents the number of elements in the pre-generated set. After generating the second mapping subscript using a normal distribution random number, we need to adjust its value by a certain margin.
[0057] The boundary adjustment logic is as follows: If the second mapping subscript <0, adjust it to 0; If the second mapping subscript >n, then = n, it is adjusted to n-1 (i.e. the last index).
[0058] That is, if an array or list has n elements, The index range is from 0 to (n-1). For example, if there are 5 elements, the index will be 0, 1, 2, 3, 4.
[0059] Optionally, the method further comprises: It is determined that the associated fields of the main table are not configured with a distribution model, and test data for each field in the data table is generated one by one.
[0060] Furthermore, after generating test data for each field in the data table one by one, the method further includes: Determining that the field is a relational field; If the field is a main table associated field, the corresponding test data is sequentially obtained from the pre-generated set according to the currently generated quantity; If the field is a slave table associated field and the distribution model is not set, the corresponding test data is sequentially obtained from the pre-generated set according to the current generated quantity; If the field is a slave table associated field and a distribution model has been set, the initial test data in the pre-generated set is used as a value range, and new test data is regenerated based on the distribution model.
[0061] Specifically, in this embodiment, first, the type of each field in the data table is identified, including whether it is an associated field of the primary table or an associated field of the secondary table.
[0062] For the main table associated fields: If the current field is an associated field of the main table, the corresponding test data should be obtained from the pre-generated set in sequence according to the amount of data that has been generated.
[0063] For fields associated with the secondary table: The distribution model is not set: If the current field is an associated field from a table and no distribution model is set, the corresponding test data is obtained from the pre-generated set in sequence according to the generated quantity.
[0064] The distribution model has been set: If the field is a secondary table-associated field and a distribution model has been set, you should use the initial test data in the pre-generated set as the possible value range and regenerate new test data based on the defined distribution model.
[0065] The specific steps are as follows: Identify the category to which the field belongs (primary table association or secondary table association); adopt corresponding acquisition and generation strategies according to the type and configuration of the field; the primary table field directly obtains data from the pre-generated set; for secondary table fields, select different data generation strategies according to the settings of the distribution model. If the model is not set, directly obtain data; if the model is set, regenerate the data. Through this process, test data can be effectively generated according to the actual needs of the field.
[0066] Optionally, it also includes: Determine that the field is a common field; It is determined that the field is not an association table field and does not exist in the pre-generated set, and the test data is generated according to a generation rule and a distribution model.
[0067] In this embodiment, it is confirmed that the field currently being processed is a common field. Specifically, it is ensured that the field is not a field of an associated table and does not exist in the pre-generated set. This means that the field is not any associated field defined in the primary table or the secondary table.
[0068] For the common fields thus determined, test data is then generated according to the preset generation rules and distribution model. The specific steps are as follows: Generate data using the specified rules according to the defined business logic or data requirements, which may include format, range, data type and other requirements. If the common field has a defined distribution model, the data needs to be generated in combination with the model. For example, normal distribution, uniform distribution, etc. can be used to generate numerical data, or categorical data can be generated through a specified probability distribution.
[0069] The embodiments of the present application provide clear steps for generating test data for common fields, ensuring that the generated data complies with the required specifications and types.
[0070] Reference Figure 2 , Figure 2 It is a complete flow chart of the embodiment of the present application, which includes the following steps: Get the associated fields, generation rules and quantities of all main tables; Pre-generate the main table associated field data according to the number of generation rules and store it in the pre-generation set; Determine whether the associated field has a distribution model set; If so, use the pre-generated set as the value range, regenerate data according to the distribution model, and re-store and overwrite the pre-generated set; generate data for each field of the data table one by one; If not, directly generate the data of each field in the data table one by one; Determine whether the field is an associated field; If not, generate according to the generation rules and distribution model; If so, determine whether the field is a primary table associated field or the model distribution is not configured; If so, get them from the associated field set in sequence; If not, regenerate with the main table associated field value set as the value range, return to the pre-generated set as the value range, regenerate data according to the distribution model, and re-store to overwrite the pre-generated set.
[0071] The present application is described in detail below in conjunction with specific embodiments.
[0072] In an e-commerce project, new data is created for the user table, product table, and user purchase record table. The user table creates 100,000 data items, the product table creates 20,000 data items, and the purchase record table creates 150,000 data items. The user purchase information records depend on the user table and the product table, that is, the user table and the product table are the main tables of the purchase record table, and the associated fields are user_id and product_id respectively.
[0073] The user table user is shown in Table 1 below: Table 1
[0074] The product table product is shown in Table 2 below: Table 2:
[0075] The user purchase record table record is shown in Table 3 below:
[0076] The data generation process is as follows: 1. Get the associated fields of all main tables, which are user.user_id and product.product_id in this case. 2. Generate corresponding data according to generation rules and quantity and store them in the pre-generated set. The structure is as follows: user.user_id ->xxxa1 xxxa2 xxxa3…xxxa10w, a total of 10w ids; product. product_id ->xxxb1 xxxb2 xxxb3…xxxb2w, a total of 2w ids; 3. Get all fields that have a distribution model configured. In this case, they are product. made_in and record.product_id. Pre-generate made_in: Assume that the made_in enumeration is China, the United States, Germany, Japan, and South Korea, a total of 5; Then product. made_in -> China, the United States, Germany, Japan, South Korea, China, the United States… 20,000 in total Pre-generate record. product_id, 150,000 records; Set the value range to the number of product_id in the pre-generated set. , set the standard deviation σ=200; Generate a random number between 0 and 2w each time. This random number is the subscript of the product. product_id set in the pre-generated set and is stored in the pre-generated set. For example, if the random number is 1001, the 1001th data xxxb1001 in the product.product_id set is taken. The structure is as follows: record. product_id ->xxxb1001 xxxb10 xxxb1001 …xxxb10009, a total of 150,000 records; A total of 150,000 times were generated. Arrange all products in the order of the pre-generated set product. product_id as the horizontal axis and the number of purchases as the vertical axis, and you can get a distribution chart of product-purchase frequency, which is generally a normal distribution.
[0077] 4. Start generating data table by table and row by row.
[0078] (a) Generate user table data row by row, where user_id is obtained from the pre-generated set user.user_id in sequence, and other rows are generated according to the generation rules, totaling 100,000 rows.
[0079] (b) Generate product table data row by row, where product_id and made_in are obtained from the pre-generated sets product.product_id and product.made_in respectively, and other rows are generated according to the generation rules, totaling 20,000 rows.
[0080] (c) Generate user purchase record table data row by row, where product_id is obtained from record.product_id and user_id is obtained from user.user_id. , other rows are generated according to the generation rules.
[0081] Reference Figure 3 The present application also provides a device for generating test data of a database association table, comprising: The acquisition module 310 is used to acquire the associated fields, generation rules and generation quantity of the associated table master table; the associated table is composed of at least two data tables; A pre-generation module 320, configured to pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in a pre-generation set; A regeneration module 330 is used to determine that the associated field of the main table has been configured with a distribution model, use the initial test data in the pre-generated set as a value range, regenerate new test data based on the distribution model, store the new test data and overwrite the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
[0082] Optionally, when the distribution model is uniform distribution, the method for generating new test data includes: Determine the number of pre-generated sets and the current number of generations; Calculate the length of the pre-generated set, and calculate the first mapping index of the current generation number mapped to the pre-generated set; The corresponding new test data is obtained from the pre-generated set according to the first mapping index and the length of the pre-generated set.
[0083] Optionally, when the distribution model is a normal distribution, the method for generating new test data includes: Determine the mean and standard deviation, and generate normally distributed random numbers; The normally distributed random number is used to obtain a random number, and a boundary adjustment is performed based on the generated random number to ensure that the index value is within the range of the generated number.
[0084] Optionally, the obtaining of random numbers using the normally distributed random numbers and performing boundary adjustment according to the generated random numbers to ensure that the index value is within the range of the generated number include: generating a second mapping subscript based on the mean, the standard deviation, and the normal distribution number; Ensure that the second mapping subscript is between 0 and the generated number. If the second mapping subscript is less than 0, the second mapping subscript is 0; if the second mapping subscript is greater than n, the second mapping subscript is n. The corresponding element is obtained from the pre-generated set according to the value of the second mapping index to generate the new test data.
[0085] Optionally, the device further comprises a generation module of an unconfigured model, configured to: It is determined that the associated fields of the main table are not configured with a distribution model, and test data for each field in the data table is generated one by one.
[0086] Optionally, a field judgment module is also included, which is used to: Determining that the field is a relational field; If the field is a main table associated field, the corresponding test data is sequentially obtained from the pre-generated set according to the currently generated quantity; If the field is a slave table associated field and the distribution model is not set, the corresponding test data is sequentially obtained from the pre-generated set according to the current generated quantity; If the field is a slave table associated field and a distribution model has been set, the initial test data in the pre-generated set is used as a value range, and new test data is regenerated based on the distribution model.
[0087] Optionally, the field judgment module further: Determine that the field is a common field; It is determined that the field is not an association table field and does not exist in the pre-generated set, and the test data is generated according to a generation rule and a distribution model.
[0088] Further, refer to Figure 4 , Figure 4 This is a user operation sequence diagram of an embodiment of the present application, comprising the following steps: The user inputs database configuration information to the device; the device connects to the database and obtains database table information; This device obtains schema, table, and field information from the database and displays the schema, table, and field information to the user; The user selects a data table, configures the generated data, the generation method of the associated fields between tables, the distribution model, and starts the generation; The device generates teaching data according to the rules and stores them in the warehouse. After the storage is completed, it indicates to the user that the storage is successful.
[0089] It can be understood that the detailed functional implementation of each of the above-mentioned units / modules can be found in the introduction of the aforementioned method embodiment, and will not be repeated here.
[0090] It should be understood that the above-mentioned device is used to execute the method in the above-mentioned embodiment. The implementation principle and technical effect of the corresponding program module in the device are similar to those described in the above-mentioned method. The working process of the device can refer to the corresponding process in the above-mentioned method, which will not be repeated here.
[0091] Reference Figure 5 Based on the method in the above embodiment, the embodiment of the present application provides an electronic device, which may include: a processor (processor) 510, a communication interface (Communications Interface) 520, a memory (memory) 530 and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can call the logic instructions in the memory 530 to execute the method in the above embodiment.
[0092] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application.
[0093] Based on the method in the above embodiment, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method in the above embodiment.
[0094] Based on the method in the above embodiment, an embodiment of the present application provides a computer program product. When the computer program product runs on a processor, the processor executes the method in the above embodiment.
[0095] It is understandable that the processor in the embodiment of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor may be a microprocessor or any conventional processor.
[0096] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0097] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc.
[0098] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used to limit the scope of the embodiments of the present application.
[0099] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A method for generating test data of a database association table, characterized in that: include: Get the associated fields, generation rules and generation quantity of the associated table master table; The association table is composed of at least two data tables; Pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in the pre-generation set; Determine that the associated field of the main table has been configured with a distribution model, use the initial test data in the pre-generated set as a value range, regenerate new test data based on the distribution model, store the new test data and overwrite the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
2. The method for generating database association table test data according to claim 1, characterized in that: When the distribution model is uniform distribution, the method for generating new test data includes: Determine the number of pre-generated sets and the current number of generations; Calculate the length of the pre-generated set, and calculate the first mapping index of the current generation number mapped to the pre-generated set; The corresponding new test data is obtained from the pre-generated set according to the first mapping index and the length of the pre-generated set.
3. The method for generating database association table test data according to claim 1, characterized in that: When the distribution model is a normal distribution, the method for generating new test data includes: Determine the mean and standard deviation, and generate normally distributed random numbers; The normally distributed random number is used to obtain a random number, and a boundary adjustment is performed based on the generated random number to ensure that the index value is within the range of the generated number.
4. The method for generating database association table test data according to claim 3, characterized in that: The method of obtaining a random number using the normally distributed random number and adjusting the boundary according to the generated random number to ensure that the index value is within the range of the generated number includes: generating a second mapping subscript based on the mean, the standard deviation, and the normal distribution number; Ensure that the second mapping subscript is between 0 and the generated number. If the second mapping subscript is less than 0, the second mapping subscript is 0. If the second mapping subscript is greater than n, the second mapping subscript is n-1. The corresponding element is obtained from the pre-generated set according to the value of the second mapping index to generate the new test data.
5. The method for generating database association table test data according to claim 1, characterized in that: Also includes: It is determined that the associated fields of the main table are not configured with a distribution model, and test data for each field in the data table is generated one by one.
6. The method for generating database association table test data according to claim 5, characterized in that: After generating the test data of each field in the data table one by one, it also includes: Determining that the field is a relational field; If the field is a main table associated field, the corresponding test data is sequentially obtained from the pre-generated set according to the currently generated quantity; If the field is a slave table associated field and the distribution model is not set, the corresponding test data is sequentially obtained from the pre-generated set according to the current generated quantity; If the field is a slave table associated field and a distribution model has been set, the initial test data in the pre-generated set is used as a value range, and new test data is regenerated based on the distribution model.
7. The method for generating database association table test data according to claim 5, characterized in that: Also includes: Determine that the field is a common field; It is determined that the field is not an association table field and does not exist in the pre-generated set, and the test data is generated according to a generation rule and a distribution model.
8. A device for generating test data of a database association table, characterized in that: include: The acquisition module is used to obtain the associated fields, generation rules and generation quantity of the associated table master table; The association table is composed of at least two data tables; A pre-generation module, used to pre-generate initial test data of the associated fields of the main table according to the generation rule and the generation quantity, and store the initial test data in a pre-generation set; A regeneration module, used for determining that the associated fields of the main table have been configured with a distribution model, using the initial test data in the pre-generated set as a value range, regenerating new test data based on the distribution model, storing the new test data and overwriting the pre-generated set to form a new data set; Wherein, the distribution model includes a uniform distribution model or a normal distribution model.
9. An electronic device, characterized in that: include: at least one memory for storing a computer program; At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program runs on a processor, the processor is caused to execute the method according to any one of claims 1 to 7.