Random SQL (Structured Query Language) testing method and device for time series data

Through the construction and formatting of output of abstract syntax tree, combined with transaction execution and fallback operations, the adaptation problem of random tests in the timing database is solved, and the random SQL generation and testing coverage of timing data is realized, which improves the stability of the system and Iterative reliability.

CN119127697APending Publication Date: 2024-12-13INSPUR QILU SOFTWARE IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411224810.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

The existing random testing technology has not been effectively adapted in the timing database system, and cannot meet the characteristics and query requirements of timing data, especially the association of timestamps and measured values, as well as insufficient support for aggregation operations and time range queries, and The timing database does not support transaction operations, limiting the controllability of the test.

Method used

Adopt abstract syntax tree (AST) construction method, including syntax, semantics and syntax modules, define the syntax and semantics of time series data, combine formatted output and log modules, generate random SQL queries suitable for time series data, and execute and fallback through transactions Operations ensure test independence and adjust the weight of SQL statements to accommodate differences in different query categories and database systems.

Benefits of technology

Implement random SQL generation for time series data, covering time range and aggregation queries, improving the scalability and coverage of tests, and being able to output SQL statements under complex and boundary conditions in real scenarios, supplementing the shortcomings of manual testing, and improving The stability of the system and the reliability of iterative releases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127697A_ABST
    Figure CN119127697A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of database testing, and particularly provides a random SQL testing method and device oriented to time series data, and the method comprises the following steps: S1, realizing an AST (abstract syntax tree) generation function; s2, formatting and outputting; and S3, collecting and connecting database information. Compared with the prior art, the method has the advantages that random SQL generation of time series data can be realized, good expansibility is provided, and weight-based output and specific SQL type output of different query types can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database testing, and specifically provides a method and device for random SQL testing of time series data. Background Art

[0002] In the development and maintenance process of database systems, testing can not only verify the correctness of functions, but also ensure the stability of the system and reveal potential risks and problems in the system. Usually, SQL logic testing (SQL Logic Test) is required for specified functions in database functional testing, that is, SQL test cases are used to verify the correctness of SQL syntax and logic, especially in query scenarios, it is necessary to cover whether the query execution in different situations can run normally. This type of test can ensure the correctness and stability of the system's functions during rapid development and iteration. In the current general database testing process framework, database testing usually requires manual analysis of functional points, writing corresponding query SQL cases, covering all test scenarios as much as possible, and repeatedly executing in iterations through different automated methods to ensure the stability of the system. However, this method has the inevitable limitations of manual testing, that is, it is difficult to output complex SQL that appears in real scenarios, and to cover various boundary conditions and abnormal situations.

[0003] Therefore, random testing is a necessary supplement to manual testing in the database system testing process. Random testing mainly constructs the SQL syntax body through a specific syntax generation tree and converts it into SQL statements through syntax tree parsing. Random testing has been adapted to the current mainstream relational database systems and helps the database system improve the stability of iterative releases.

[0004] However, random testing is currently only widely used in relational database systems and has not been well adapted to time series database systems. The specific reasons are:

[0005] 1. The characteristics of time series data. Unlike relational data, time series data consists of timestamps and measurement value pairs, so the timestamp characteristics must be taken into account when acquiring data;

[0006] 2. Time series data focuses more on query methods such as time range query and aggregation operation. The statements output by random tests may not be applicable to time series data. Therefore, it is necessary to restrict and adapt the generation of syntax trees.

[0007] 3. Time series data currently does not support transactions, so during the test execution process, transaction operations cannot be used to control the database system for testing. Summary of the invention

[0008] The present invention aims to address the deficiencies of the above-mentioned prior art and provides a highly practical method for random SQL testing of time series data.

[0009] A further technical task of the present invention is to provide a device for random SQL testing of time series data that is reasonably designed, safe and applicable.

[0010] The technical solution adopted by the present invention to solve its technical problem is:

[0011] A method for random SQL testing of time series data has the following steps:

[0012] S1. Abstract syntax tree AST generation function implementation;

[0013] S2, formatted output;

[0014] S3. Database information collection and connection.

[0015] Further, in step S1, the abstract syntax tree AST includes a syntax module, a semantic module and a grammar module, wherein the syntax module defines the syntax of the value expression and specifies the expression for constructing the value;

[0016] The semantic module is used to define tuple relations and process inclusion relations and constraint relations between categories of tables, columns and functions;

[0017] The grammar module defines the overall grammar of the query statement.

[0018] Furthermore, the semantic module needs to additionally define the relationship between tables and columns. The timestamp column in the time series data needs to be associated with the corresponding measurement value column as a whole key-value pair.

[0019] But at the same time, they are also column values ​​of the table. Therefore, in the semantic module, the time series are recorded through timestamp key-value pairs and correspond to the column names of the time series table.

[0020] Furthermore, in step S2, a formatting module and a log module are included, and the formatting module performs formatted output and converts the abstract syntax tree into a recognizable SQL character set;

[0021] The log module is used to collect and report necessary statistical information during the SQL QUERY generation and execution process.

[0022] Furthermore, the log module interacts with the outside world, obtains AST syntax tree information through the statistical information collection function and calls the formatting module to convert it into a recognizable SQL character set, and finally calls the log interface to output the SQL character set;

[0023] In addition, the return results of SQL QUERY executed after the database is connected are also processed and analyzed through the log module, different errors are classified and summarized for phased output, and the necessary assertion interface is provided to terminate the test operation;

[0024] It also serves as an association mechanism between the database collection information and the connected execution module and the AST generation function module. By obtaining the error code returned by the execution as a feedback parameter, the weight value of the SQL STATEMENT generated by the AST is further adjusted.

[0025] Furthermore, the assertion terminates the operation by relying on the error code returned by the QUERY execution, and the error codes corresponding to different database systems are inconsistent.

[0026] Further, in step S3, the database information collection and connection function is responsible for connecting to and reading the target database and executing the QUERY on the database, including a connection module, a reading module, and an execution module;

[0027] The connection module calls the driver API of the corresponding database to establish a connection with the time series database system to be tested;

[0028] The reading module collects all necessary elements for AST generation;

[0029] The execution module executes the SQL STATEMENT string generated by the AST through transactions, and uses a rollback operation to cancel the result of each execution.

[0030] Furthermore, it is necessary to collect all necessary elements of AST generation, including data type metadata;

[0031] The data type metadata includes all table names in the database, the schema corresponding to the table, the table type, column name, constraints, and all functions in the database and corresponding input and output parameters.

[0032] A device for random SQL testing of time series data, comprising: at least one memory and at least one processor;

[0033] The at least one memory is used to store a machine-readable program;

[0034] The at least one processor is used to call the machine-readable program to execute a method for random SQL testing of time series data.

[0035] Compared with the prior art, the method and device for random SQL testing for time series data of the present invention have the following outstanding beneficial effects:

[0036] The present invention realizes the generation of random SQL QUERY based on a specific table structure through abstract syntax tree construction and formatted output. In combination with the characteristics of time series data, a specific time series of timestamp-measurement value is added and a weight ratio is introduced to improve the output of SQL QUERY of aggregation query and time range query that are more concerned in time series data query, thereby realizing random SQL generation for time series data.

[0037] At the same time, it provides good scalability and can achieve weight-based output of different query categories and output of specific SQL types. Finally, it realizes the application of fuzzy testing of random SQL testing in time series databases, supplements the test surfaces that are difficult to cover in manual testing in actual testing, outputs complex SQL that may appear in real scenarios, and covers test points under various boundary conditions and abnormal conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] Attached Figure 1 It is a method flow chart for random SQL testing of time series data;

[0040] Attached Figure 2 The diagram is an application example of a random SQL test method for time series data. DETAILED DESCRIPTION

[0041] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than 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 are within the scope of protection of the present invention.

[0042] A best embodiment is given below:

[0043] like Figure 1-2 As shown, a method for random SQL testing of time series data in this embodiment has the following steps:

[0044] S1. Abstract syntax tree AST generation function implementation;

[0045] AST generation relies on three parts: syntax module, semantic module, and grammar module. The syntax module is responsible for defining the syntax of "value" expressions, including constant expressions, Boolean expressions, etc. This module can specify expressions that construct values. For example, a Boolean value expression can be composed of multiple Boolean expressions or a constant.

[0046] The semantic module is used to define tuple relationships, and is mainly responsible for handling the inclusion and constraint relationships between major categories such as tables, columns, and functions. In this type of module, additional definitions of table and column relationships are required. The timestamp column in the time series data needs to be associated with the corresponding measurement value column as a whole key-value pair. But at the same time, they are also column values ​​of the table. Therefore, in the semantic module, the time series is recorded through the timestamp key-value pair and corresponds to the column name of the time series table.

[0047] The grammar module is responsible for defining the overall grammar of the query statement. This module needs to be distinguished from the syntax module. The syntax module is only responsible for defining the "value" expression, while the grammar module is used to define the syntax of the overall query at a higher level. For example, a query is defined as SELECT CLAUSE+FROM+WHERE, where SELECT CLAUSE can be defined as SELECT keyword + multiple value expressions, etc. The grammar module is based on the syntax module and the semantic module, and is the most important module in the abstract syntax tree generation function.

[0048] Since in time series data applications, query categories focus more on time range queries and aggregate queries, this method introduces the concept of weights in the grammar module, assigns different weights to query categories such as time range queries, function queries, subqueries, association queries, fuzzy queries, and increases the weight ratio of range queries and aggregate function queries. Among them, range queries include timestamp ranges and range queries of other measurement value categories. For such subclass concepts, the output of random SQL QUERY is also controlled by weight ratio. Of course, considering that there may be many more specific query methods and weight ratios in different database systems, the grammar module of this method is more of an interface call through abstract functions, which can provide more extensibility operations of query methods and change the weight configuration of query categories.

[0049] S2, formatted output;

[0050] It consists of a formatting module and a logging module. The formatting module is responsible for formatting the output and converting the abstract syntax tree into a recognizable SQL character set; the logging module is used to collect and report the necessary statistical information during the SQL QUERY generation and execution process.

[0051] Among them, the log module is the main module for external interaction. It obtains AST syntax tree information through the statistical information collection function and calls the formatting module to convert it into a recognizable SQL character set, and finally calls the log interface to output the SQL character set. In addition, the return result of SQL QUERY executed after the database is connected can also be processed and analyzed by the log module, and different ERRORs are classified and summarized for staged output, and the necessary assertion interface is provided to terminate the test operation.

[0052] The assertion mainly terminates the operation by relying on the error code returned by the QUERY execution. Different database systems have different corresponding error codes, so additional operations are performed to process them.

[0053] In addition, the log module can also be used as a mechanism to associate database collection information with the connected execution module and AST generation function module, and further adjust the weight value of the SQL STATEMENT generated by AST by obtaining the error code returned by the execution as a feedback parameter, thereby reducing the probability of the same error type appearing multiple times and increasing the coverage of other syntax tests.

[0054] S3. Database information collection and connection.

[0055] The database information collection and connection function is mainly responsible for connecting, reading the target database and executing QUERY on the database, that is, it includes a connection module, a reading module, and an execution module. This part is the main part of the time series data adaptation. In the present invention, this function is the entrance to the overall test, and the driver API of the corresponding database is called by the connection module to establish a connection with the time series database system that needs to be tested. It should be noted that in a database system with a safe mode, the connection module needs to be operated by a user with ROOT permissions in order to collect necessary information for the database system. In addition, since the drivers of different databases are inconsistent, the connection module is also an abstract interface calling function. You only need to specify the driver address of the database and the necessary IP, port, user name and password to connect to the database normally for operation.

[0056] The reading module needs to collect all necessary elements generated by AST, including data type metadata; all table names in the database, the schemas corresponding to the tables, and the types of the tables; column names, constraints, and all functions in the database and the corresponding input and output parameters.

[0057] The collection of metadata of the tables and columns of the database is relatively special. Generally, the types of tables under the time series database are divided into basic tables, system tables and time series tables, and some time series databases support the creation of relational tables. Therefore, it is necessary to distinguish and process the types of tables in the acquisition of table metadata. At the same time, the function types and column types of time series tables are also different from the support levels of other types of columns. For example, the columns under the time series table need to be combined with the corresponding timestamp columns to form a set of timestamp key-value pairs. In addition, the functions of time series data need to focus more on aggregate queries under time ranges. Therefore, additional internal structures are required to record the special structure of time series data in the acquisition of function metadata and column metadata.

[0058] In the above execution module, transactions are usually required to execute the SQL STATEMENT string generated by AST. Rollback operations are used to cancel the results of each execution. This operation is to prevent the execution of some SQL statements from affecting subsequent QUERY and ensure that multiple tests are independent of each other and have no correlation. However, the operations of time series data in the current popular time series database system do not support transactions, because in common scenarios of time series data, it needs to provide continuous high-throughput writing, and the introduction of transactions will affect the read and write performance of the time series database system.

[0059] Therefore, transaction operations need to be avoided in the execution module. By adding a delay between each QUERY execution to determine the database status, the failure problem of database lag that may be caused by each query can be avoided. It should be noted that the execution module delay mechanism relies on the fact that even if the time series database no longer supports transaction queries, it can still ensure the consistency of the database under concurrent queries.

[0060] It should be clear that the relationship between the above modules of this method is not implemented in a logical order, but is a mutually dependent relationship. In the logical relationship, the functional module for collecting and connecting database information is the basic calling module, and other functional modules rely on this module to pass parameters, call and run. For example, the running module needs to call the AST generation module through the obtained metadata parameters, and the syntax tree generated by the AST will be called by the execution module through the formatting function module to output the SQL STATEMENT string. In addition, the log module can also call the output of the SQL STATEMENT of the AST through the formatting function module and interrupt the operation of the execution module, so that only the random statements required by this method can be output without returning the results through the database operation.

[0061] Based on the above method, a device for random SQL testing of time series data in this embodiment includes: at least one memory and at least one processor;

[0062] The at least one memory is used to store a machine-readable program;

[0063] The at least one processor is used to call the machine-readable program to execute a method for random SQL testing of time series data.

[0064] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that conform to the above-mentioned specific implementations of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.

[0065] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for random SQL testing of time series data, characterized in that: The steps are as follows: S1. Abstract syntax tree AST generation function implementation; S2, formatted output; S3. Database information collection and connection.

2. The method for random SQL testing of time series data according to claim 1, characterized in that: In step S1, the abstract syntax tree AST includes a syntax module, a semantic module and a grammar module, wherein the syntax module defines the syntax of the value expression and specifies the expression for constructing the value; The semantic module is used to define tuple relations and process inclusion relations and constraint relations between categories of tables, columns and functions; The grammar module defines the overall grammar of the query statement.

3. The method for random SQL testing of time series data according to claim 2, characterized in that: The semantic module needs to additionally define the relationship between tables and columns. The timestamp column in the time series data needs to be associated with the corresponding measurement value column as a whole key-value pair. But at the same time, they are also column values ​​of the table. Therefore, in the semantic module, the time series are recorded through timestamp key-value pairs and correspond to the column names of the time series table.

4. The method for random SQL testing of time series data according to claim 3, characterized in that: In step S2, a formatting module and a log module are included, and the formatting module performs formatted output and converts the abstract syntax tree into a recognizable SQL character set; The log module is used to collect and report necessary statistical information during the SQL QUERY generation and execution process.

5. The method for random SQL testing of time series data according to claim 4, characterized in that: The log module interacts with the outside world, obtains AST syntax tree information through the statistical information collection function and calls the formatting module to convert it into a recognizable SQL character set, and finally calls the log interface to output the SQL character set; In addition, the return results of SQL QUERY executed after the database is connected are also processed and analyzed through the log module, different errors are classified and summarized for phased output, and the necessary assertion interface is provided to terminate the test operation; It also serves as an association mechanism between the database collection information and the connected execution module and the AST generation function module. By obtaining the error code returned by the execution as a feedback parameter, the weight value of the SQL STATEMENT generated by the AST is further adjusted.

6. The method for random SQL testing of time series data according to claim 5, characterized in that: The assertion terminates the operation by relying on the error code returned by the QUERY execution, and the error codes corresponding to different database systems are inconsistent.

7. The method for random SQL testing of time series data according to claim 6, characterized in that: In step S3, the database information collection and connection function is responsible for connecting to and reading the target database and executing QUERY on the database, including a connection module, a reading module, and an execution module; The connection module calls the driver API of the corresponding database to establish a connection with the time series database system to be tested; The reading module collects all necessary elements for AST generation; The execution module executes the SQL STATEMENT string generated by the AST through transactions, and uses a rollback operation to cancel the result of each execution.

8. The method for random SQL testing of time series data according to claim 7, characterized in that: All necessary elements for AST generation need to be collected, including data type metadata; The data type metadata includes all table names in the database, the schema corresponding to the table, the table type, column name, constraints, and all functions in the database and corresponding input and output parameters.

9. A device for random SQL testing of time series data, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 8.