Data statistical analysis method based on time sequence database
Generate and execute multiple SQL statements through configuration files, and use time series database functions to perform data statistics, which solves the problems of complexity and low efficiency of time series data statistical analysis in the existing technology, and achieves efficient and easy-to-use data statistics and analysis.
Patent Information
- Application Number
- CN202410885736.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-08-30
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology lacks effective methods to map time series database functions, which results in the need to write a large number of SQL statements in statistical analysis of time series data. Operators need to frequently query the data platform, and it is difficult to efficiently process complex statistical analysis of multiple tables.
By defining the configuration file, the operator can specify the connection information, storage strategy, table name and column information, generate and execute multiple SQL statements, and use the unique functions and aggregate functions of the time series database to automatically count data and record the execution results, reducing the user's time of writing SQL. burden.
It achieves efficient and easy-to-use data statistical analysis, reduces the complexity of users writing SQL, improves the speed and efficiency of data analysis, and ensures data integrity.
Smart Images

Figure CN118568124A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of time series data statistics, and in particular to a data statistical analysis method based on a time series database. Background Art
[0002] As the Internet of Things (IoT) is booming, IoT devices are generating massive amounts of data at an unprecedented rate with their wide range of application scenarios and growing numbers. These data are not only huge in quantity, but also complex in structure, because each IoT device may have hundreds or thousands of sensors and parameters, and the data of these sensors and parameters are recorded in data tables, forming a complex data structure with many columns. Faced with such a large and complex data set, it is far from enough to simply collect and store this data. We need to regularly count and analyze the data in each column to reveal the laws and trends. Such statistical analysis work is crucial for IoT applications. It can help us understand the operating status of the equipment, predict the performance changes of the equipment, discover potential problems and risks, and provide strong data support for business decisions.
[0003] Currently, statistics on time series data are performed by writing SQL to query given columns and display them on a big data platform for monitoring data. However, there is a lack of a unique method to map them to the functions of a time series database. Through the extensive use of database functions, the operator can obtain the statistical data information he wants as a whole. Summary of the invention
[0004] Based on the above technical problems, the present invention proposes a data statistical analysis method based on a time series database, which defines the data table to be counted, the corresponding data columns, and the corresponding statistical information. There is no need to write a large number of SQL statements or go to the data platform to check. The pre-configured statistical data can be directly exported to a file through the tool. The operator can do certain data analysis through the statistical data of the exported file. The specific technical solution is as follows.
[0005] A data statistical analysis method based on a time series database comprises the following steps: Step S1: The operator adds configuration information according to the usage scenario configuration file; Step S2: Read the configuration file information and generate SQL statements according to the configuration file information; Step S3: Execute the generated SQL statement and record the execution result to the storage file and log file according to the storage strategy; Step S4: Open the storage file analysis result.
[0006] Specifically, in step S1, the configuration information of the operator configuration file is determined by the operator and is generated manually or by a program. The tables involved in each statistical data collection must be in one library, and multiple libraries must be counted separately.
[0007] Specifically, the configuration file configuration information includes connection information and statistical information, and the statistical information includes storage strategy and table name 1 to table name n; the table name 1 to table name n include an identifier, an actual table name, a column name of the current table, and a function name used for the current column.
[0008] Specifically, the storage strategy is set to 0 by default when all statistical data are placed in one file, and is set to 1 when one table of statistical data corresponds to one file.
[0009] Specifically, the step S2 specifically includes: Connect to the database according to the connection information in the configuration information; Determine the statistical data storage strategy, read the identifier information until the next identifier, and the columns between the two identifiers all belong to the first identifier; Combine the table name, function and column information to generate an SQL statement, perform generation operations on each identifier in turn, and finally generate multiple SQL statement information.
[0010] Specifically, the step S3 further includes: before executing the SQL statement, judging the SQL statement, and dividing the SQL statement into multiple threads for execution according to the number of SQL statements.
[0011] Specifically, the log file content includes: whether the SQL statement execution result is successful, if the execution fails, the failure reason needs to be recorded, and the failure time, error message returned by the server, table name information and failed SQL statement information are recorded in the log file.
[0012] Beneficial effects of the invention: The invention proposes a data statistical analysis method based on a time series database, which can automatically obtain the desired results through user configuration, greatly reducing the burden of data statistics. By combining the time series database-specific functions and some commonly used aggregate functions, users only need to understand the desired data without worrying about how to assemble SQL, and can query multiple tables at the same time and export the statistical results of multiple tables, which has the following advantages: Efficiency: Multiple tables can be configured at the same time, and users do not need to manually design multiple SQL statements to query multiple data, which greatly increases the speed of data analysis and improves the efficiency of subsequent data statistics and analysis.
[0013] Ease of use: Users do not need to write SQL statements. They only need to specify connection information, storage strategy, table name, column, and function information to automatically match the data in the database and store the data in a file at one time, which lowers the usage threshold and improves the user experience.
[0014] Data integrity: The time, reason, SQL, tbname and other information of failed execution will be recorded one by one to prevent execution failure and loss of statistical results, thus better ensuring data integrity.
[0015] Applicability: This method is extremely applicable when multiple tables of time series data are used for statistics. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a flow chart of a data statistical analysis method based on a time series database of the present invention. DETAILED DESCRIPTION
[0017] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described with reference to the accompanying drawings.
[0018] The present invention proposes a data statistical analysis method based on a time series database. When performing data statistical analysis on a time series database, the data table to be statistically analyzed, the corresponding data column, and the corresponding statistical information can be defined in advance, so that there is no need to write a large number of SQL statements or to check on the data platform. The pre-configured statistical data can be directly exported to a file through the tool, and the operator can perform certain data analysis based on the statistical data of the exported file. The process is as follows: Figure 1 As shown, the following steps are included: Step S1: The operator adds configuration information according to the usage scenario configuration file; Step S2: Read the configuration file information and generate SQL statements according to the configuration file information; Step S3: Execute the generated SQL statement and record the execution result to the storage file and log file according to the storage strategy; Step S4: Open the storage file analysis result.
[0019] In this embodiment, the configuration information of the operator configuration file in step S1 is determined by the operator, and is generated manually or by a program. The tables involved in each statistical data collection must be in one library, and multiple libraries must be counted separately.
[0020] In this embodiment, the configuration file configuration information includes connection information and statistical information, and the statistical information includes storage strategy and table name 1~table name n; the table name 1~table name n include an identifier, an actual table name, a column name of the current table, and a function name used for the current column.
[0021] In this embodiment, the storage policy defaults to 0 when all statistical data are placed in one file, and is set to 1 when one table of statistical data corresponds to one file.
[0022] In this embodiment, step S2 specifically includes: Connect to the database according to the connection information in the configuration information; Determine the statistical data storage strategy, read the identifier information until the next identifier, and the columns between the two identifiers all belong to the first identifier; Combine the table name, function and column information to generate an SQL statement, perform generation operations on each identifier in turn, and finally generate multiple SQL statement information.
[0023] In this embodiment, step S3 further includes: before executing the SQL statement, judging the SQL statement, and dividing the SQL statement into multiple threads for execution according to the number of SQL statements.
[0024] In this embodiment, the log file content includes: whether the SQL statement execution result is successful. If the execution fails, the reason for the failure needs to be recorded, and the failure time, error message returned by the server, table name information and failed SQL statement information are recorded in the log file.
[0025] In one embodiment, the purpose of the present invention is to provide an efficient data statistical analysis method for a time series database. The method can automatically obtain the desired results through user configuration, greatly reducing the burden of data statistics. By combining the time series database-specific functions and some commonly used aggregate functions, the user only needs to understand the desired data, without having to worry about how to assemble the SQL, and can query multiple tables at the same time and export the statistical results of multiple tables. This is extremely applicable when there are many tables. For example, in some special scenarios, it is necessary to count whether the coal leaving the coal yard is the same as the coal transported to the destination, but it involves a large number of vehicles (corresponding to multiple sub-tables) and one by one SQL query is too complicated, not to mention that there are many types of data. At this time, it can be configured through the configuration file. The configuration file can write a demo program to generate the configuration file. The specific steps are as follows: Step 1: Configuration file: The user adds configuration information (the configuration information is determined by the operator and can be generated manually or by writing a program. The tables involved in each statistical data must be in one library, and multiple libraries must be counted separately).
[0026] In this embodiment, since the program obtains corresponding data information for the user according to the user's needs, and each user has different needs, the user must first fill in the configuration item information according to the configuration rules here according to his own scenario and the information he needs to obtain (the filling method can be manually added, or the configuration information generation tool can be written by the user according to the particularity of the configuration item information to generate the configuration file). The configuration information in the configuration file includes connection information (IP, Port, User, Password, DBname), statistical information (storage strategy, table name 1 (tbnme:name column 1: function column 2: function), table name 2 (...), table name n (...)). The storage strategy in the configuration file defaults to 0 (all statistical data are placed in one file), which can be set to 1 (one table and one file for statistical data). It is recommended to be 0, because there is only one row of statistical data for each column, and there will not be many, so one file is completely sufficient. In Tbname:d1001, Tbname represents an identifier, and the following d1001 is the actual table name; col1-n is the column name of the current table, and the function name used for the current column is after the equal sign of the column name. N tables can be defined at the same time for statistics. The function type is a statistical function for a certain column, such as MAX(col1) / MODE(col6), etc. The use of the function has requirements on the data type, and the user needs to configure it carefully. If the function is incompatible with the current column data type, an error message will be generated in the log file in step 4.
[0027] In one embodiment, the configuration file structure is as follows: [conn_cfg] host=127.0.0.1 port=6030 user=root pwd=xugutsdb dbname = test [statisticsTbname_cfg] StorageMethod = 0 Tbname: d1001 * = count col1 = max col2 = min col3 = avg col4 = sum Tbname: d1002 col1 = SPREAD col2 = MODE col3 = CSUM Tbname:dN Coln = max Step 2: Read the configuration file: First, connect to the database according to the connection information in the configuration information, then determine the statistical data storage strategy, read the tbname information until the next tbname, and the columns between the two tbnames belong to the first tbname. Combine the table name, function, and column information to generate an SQL statement; perform the generation operation on each tbname in turn, and finally generate multiple SQL statement information. The example is as follows: / / For the above configuration file: For example, tbname:d1001 generates: SELECT COUNT(*),MAX(col1),MIN(col2),AVG(col3),SUM(col4) FROM d1001; Tbname:d1002 generates: SELECT SPREAD(col1), MODE(col2), CSUM(col3) FROMd1002; / / SPREAD is the difference between the maximum and minimum values of a column in the statistical table. MODE is to return the value with the highest frequency. If there are multiple highest values with the same frequency, one of them is randomly output. CSUM is the cumulative sum; / / Can be adapted to various single-column functions (multiple functions can be used).
[0028] Step 3: Execute the SQL statements generated above: After step 2, the SQL statements have been generated. These SQL statements are judged. If the number of SQL statements is less than 100, they are divided into 3 threads to execute these SQLs. If the range is [100-1000], they are divided into 10 threads to execute these SQLs. If it exceeds 1000, they are divided into 20 threads to execute these SQLs.
[0029] Step 4: Store the execution results: Store the query results according to the storage strategy defined by the implementation, and store the SQL statement for obtaining the result (the SQL statement can be used for secondary verification or data analysis later). At the same time, there must be a separate log file to record whether the execution result of the SQL statement is successful. If it fails, the reason for the failure must be recorded, and the time of failure, error message returned by the server, table name information, failed SQL and other information must be recorded in the log file.
[0030] Step 5: Analyze the results: At this point, the user can open the file storing the results to view the SQL statements and query results. At the same time, pay attention to the log information. If there is an error message in the log, analyze the cause of the failure and then retrieve it again.
[0031] The present invention has shown and described the basic principles and main features of the present invention and the advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A data statistical analysis method based on a time series database, characterized in that: The following steps are involved: Step S1: The operator adds configuration information according to the usage scenario configuration file; Step S2: Read the configuration file information and generate SQL statements according to the configuration file information; Step S3: Execute the generated SQL statement and record the execution result to the storage file and log file according to the storage strategy; Step S4: Open the storage file analysis result.
2. According to the data statistical analysis method based on time series database in claim 1, it is characterized in that: The configuration information of the operator configuration file in step S1 is determined by the operator and is generated manually or by a program. The tables involved in each statistical data collection must be in one library, and multiple libraries must be counted separately.
3. According to the data statistical analysis method based on time series database in claim 2, it is characterized in that: The configuration information of the configuration file includes connection information and statistical information. The statistical information includes storage strategy and table name 1 to table name n. The table name 1 to table name n include an identifier, an actual table name, a column name of the current table, and a function name used for the current column.
4. The data statistical analysis method based on a time series database according to claim 3 is characterized in that: The storage policy defaults to 0 when all statistical data are placed in one file, and is set to 1 when one table of statistical data corresponds to one file.
5. The data statistical analysis method based on a time series database according to claim 1 is characterized in that: The step S2 specifically includes: Connect to the database according to the connection information in the configuration information; Determine the statistical data storage strategy, read the identifier information until the next identifier, and the columns between the two identifiers all belong to the first identifier; Combine the table name, function and column information to generate an SQL statement, perform generation operations on each identifier in turn, and finally generate multiple SQL statement information.
6. The data statistical analysis method based on a time series database according to claim 1 is characterized in that: The step S3 also includes: before executing the SQL statement, judging the SQL statement, and dividing the SQL statement into multiple threads for execution according to the number of SQL statements.
7. The data statistical analysis method based on a time series database according to claim 6 is characterized in that: The log file content includes: whether the SQL statement execution result is successful. If the execution fails, the reason for the failure needs to be recorded, and the failure time, error message returned by the server, table name information and failed SQL statement information are recorded in the log file.
Citation Information
Patent Citations
Method and system for data synchronization of relational heterogeneous databases
CN103761318A
Database synchronization method and device, storage medium and terminal
CN111597257A
Visual analysis method and device for database SQL (Structured Query Language) operation
CN115718781A
Visual Chinese SQL (Structured Query Language) system and query construction method
CN116010439A
