Disclosure of Invention
In order to solve the above technical problems, an embodiment of the present application provides a method and a system for accessing industrial time series data, so as to achieve the purpose of improving the performance of a query function, and the technical scheme is as follows:
an access method for industrial time series data, comprising:
when an industrial time sequence data query request is received, analyzing a data identifier and a query time range from the industrial time sequence data query request;
selecting one time sequence database from a plurality of different time sequence databases as a time sequence database to be accessed according to the inquiry time range; the plurality of different timing databases includes: the system comprises a real-time sequence database and a historical time sequence database, wherein the real-time sequence database stores industrial time sequence data with reporting time in a first set time length before the current time, the historical time sequence database stores industrial time sequence data with reporting time in a second set time length before the current time, and the second set time length is longer than the first set time length;
if the time sequence database to be accessed is a real-time sequence database, inquiring industrial time sequence data matched with the data identification and the inquiring time range from the real-time sequence database;
and if the time sequence database to be accessed is a historical time sequence database, inquiring industrial time sequence data matched with the data identification and the inquiring time range from the historical time sequence database.
Preferably, the real-time sequence database includes: the first real-time database sub-database and the second real-time database sub-database;
the first real-time database stores industrial time sequence data with reporting time being in a first set duration before the current time, and the second real-time database stores industrial time sequence data with reporting time being in a time before the current time.
Preferably, the process of storing industrial time series data in the plurality of different time series databases respectively includes:
when a storage request aiming at target industrial time sequence data is received, analyzing a data type from the storage request;
judging whether the data type is the data type supported by the time sequence database;
if not, discarding the target industrial time sequence data;
if yes, storing the target industrial time sequence data into the time sequence database.
Preferably, the method further comprises:
and modifying the data types supported by the time sequence database according to modification instructions aiming at the data types supported by the time sequence database.
Preferably, in the case that the time series database is a historical time series database, the storing the target industrial time series data to the time series database includes:
compressing the target industrial time sequence data to obtain compressed data;
and storing the compressed data in the historical time sequence database according to a storage mode that each field of the industrial time sequence data of the same kind is respectively stored in different rows.
Preferably, in the case that the time series database is a history time series database based on HBase, the storing the target industrial time series data to the time series database includes:
compressing the target industrial time sequence data to obtain compressed data;
storing the compressed data in a first column cluster in the HBase-based historical time sequence database according to a storage mode that data of each field of the same kind of industrial time sequence data are respectively stored in different columns;
and performing aggregation calculation on the target industrial time sequence data in a third set time length to obtain an aggregation result, and storing the aggregation result in a second column cluster in the HBase-based historical time sequence database.
An access system for industrial time series data, comprising: a plurality of different timing databases, the plurality of different timing databases comprising: the system comprises a real-time sequence database and a historical time sequence database, wherein the real-time sequence database stores industrial time sequence data with reporting time in a first set time length before the current time, the historical time sequence database stores industrial time sequence data with reporting time in a second set time length before the current time, and the second set time length is longer than the first set time length; an analysis module; a selection module; the system comprises a first query module and a second query module;
the analysis module is used for analyzing the data identification and the query time range from the industrial time sequence data query request when the industrial time sequence data query request is received;
the selection module is used for selecting one time sequence database to be accessed from the plurality of different time sequence databases according to the inquiry time range;
the first query module is configured to query industrial time sequence data matched with the data identifier and the query time range from the real-time sequence database if the time sequence database to be accessed is a real-time sequence database;
and the second query module is used for querying industrial time sequence data matched with the data identification and the query time range from the historical time sequence database if the time sequence database to be accessed is the historical time sequence database.
Preferably, the real-time sequence database includes: the first real-time database sub-database and the second real-time database sub-database;
the first real-time database stores industrial time sequence data with reporting time being in a first set duration before the current time, and the second real-time database stores industrial time sequence data with reporting time being in a time before the current time.
Preferably, the method further comprises:
a storage module for:
when a storage request aiming at target industrial time sequence data is received, analyzing a data type from the storage request;
judging whether the data type is the data type supported by the time sequence database;
if not, discarding the target industrial time sequence data;
if yes, storing the target industrial time sequence data into the time sequence database.
Preferably, the method further comprises:
and the modification module is used for modifying the data types supported by the time sequence database according to modification instructions aiming at the data types supported by the time sequence database.
Preferably, in the case that the time sequence database is a historical time sequence database, the storage module is specifically configured to:
compressing the target industrial time sequence data to obtain compressed data;
and storing the compressed data in the historical time sequence database according to a storage mode that each field of the industrial time sequence data of the same kind is respectively stored in different rows.
Preferably, in the case that the timing database is an HBase-based historical timing database, the storage module is specifically configured to:
compressing the target industrial time sequence data to obtain compressed data;
storing the compressed data in a first column cluster in the HBase-based historical time sequence database according to a storage mode that data of each field of the same kind of industrial time sequence data are respectively stored in different columns;
and performing aggregation calculation on the target industrial time sequence data in a third set time length to obtain an aggregation result, and storing the aggregation result in a second column cluster in the HBase-based historical time sequence database.
Compared with the prior art, the application has the beneficial effects that:
in the application, the time sequence database is divided into a real-time sequence database and a historical time sequence database, the real-time sequence database is less and newer than the historical time sequence database in comparison with the data stored in the historical time sequence database, in the case that the time sequence database to be accessed is the real-time sequence database and the historical time sequence database, the query is preferentially performed from the real-time sequence database, and the data stored in the real-time sequence database is smaller, so that the workload of the query can be reduced, the query efficiency is improved, and the performance of the query function of the time sequence database is improved.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The embodiment of the application discloses an access method of industrial time sequence data, which comprises the following steps: when an industrial time sequence data query request is received, analyzing a data identifier and a query time range from the industrial time sequence data query request; determining a time sequence database to be accessed according to the inquiry time range, wherein the time sequence database to be accessed comprises: the system comprises a real-time sequence database or a historical time sequence database, wherein the real-time sequence database stores industrial time sequence data with reporting time in a first set time length before the current time, the historical time sequence database stores industrial time sequence data with reporting time in a second set time length before the current time, and the second set time length is longer than the first set time length; if the time sequence database to be accessed is a real-time sequence database and a historical time sequence database, inquiring industrial time sequence data matched with the data identification and the inquiring time range from the real-time sequence database; and if the time sequence database to be accessed is a historical time sequence database, inquiring industrial time sequence data matched with the data identification and the inquiring time range from the historical time sequence database. In the application, the performance of the query function can be improved.
Next, an industrial time series data access method disclosed in the embodiment of the present application is described, where the industrial time series data access method is applied to a time series database, as shown in fig. 1, and a flowchart of an industrial time series data access method embodiment 1 provided in the present application may include the following steps:
and S11, when an industrial time sequence data query request is received, analyzing a data identifier and a query time range from the industrial time sequence data query request.
The data identification can be understood as: unique identification of a class of industrial time series data. Each type of industrial time sequence data has unique identification, and is convenient to store and search. For example, industrial timing data of the motor includes: the power consumption and the power consumption, the identification of the power consumption is 1, and the identification of the power consumption is 2. The power consumption and the power consumption are distinguished by different identifiers, and are convenient to search.
Industrial time series data of corresponding time periods can be queried from the time series database according to the query time range. If the inquiry time range is from the start time to the end time, the industrial time sequence data with the time period from the start time to the end time can be inquired from the time sequence database.
Step S12, selecting one time sequence database from a plurality of different time sequence databases as a time sequence database to be accessed according to the inquiry time range.
In this embodiment, a plurality of different time series databases may be provided. The different time sequence databases are respectively provided with query interfaces for query. The plurality of different timing databases may include: a real-time timing database and a historical timing database. The real-time sequence database and the historical time sequence database comprise industrial time sequence data in different time ranges. For example, the real-time sequence database stores industrial time sequence data with reporting time within a first set time length before the current time, the history time sequence database stores industrial time sequence data with reporting time within a second set time length before the current time, and the second set time length is longer than the first set time length.
The reporting time can be understood as: time of industrial time series data reporting to time series database.
Because each time sequence database comprises industrial time sequence data in different time ranges, each time sequence database corresponds to different time ranges, one time sequence database can be selected from a plurality of different time sequence databases to be accessed according to the inquiry time range.
The first set duration can be flexibly set according to actual needs, for example, the first set duration can be set to be 1 hour.
Of course, the second set duration may also be flexibly set according to actual needs, for example, the second set duration may be set as a difference between the current time and the starting time.
And step S13, if the time sequence database to be accessed is a real-time sequence database and a historical time sequence database, inquiring industrial time sequence data matched with the data identification and the inquiring time range from the real-time sequence database.
If the time sequence database to be accessed is a real-time sequence database and a historical time sequence database, industrial time sequence data matched with the data identification and the query time range are queried from the real-time sequence database, and compared with the industrial time sequence data matched with the data identification and the query time range are queried from the historical time sequence database, the workload of query is small, and the query efficiency is high.
In this embodiment, the real-time timing database may include, but is not limited to: a first real-time database sub-database and a second real-time database sub-database.
The first real-time database stores industrial time sequence data with reporting time being in a first set duration before the current time, and the second real-time database stores industrial time sequence data with reporting time being in a time before the current time.
It can be understood that the second real-time database stores the industrial time sequence data with reporting time being the time before the current time, i.e. the second real-time database stores the latest reported industrial time sequence data.
In the case that the time sequence database to be accessed is the second real-time database sub-database, the first real-time database sub-database and the history time sequence database, the time sequence database to be accessed is preferentially selected from the second real-time database sub-database
Step S14, if the time sequence database to be accessed is a historical time sequence database, industrial time sequence data matched with the data identification and the query time range is queried from the historical time sequence database.
Because the industrial time sequence data in the real-time sequence database is less than the data in the historical time sequence database, the industrial time sequence data matched with the data identification and the query time range needs to be queried from the historical time sequence database under the condition that the time sequence database to be accessed is determined to be the historical time sequence database, and the reliability of query is ensured.
In embodiment 2 of the present application, a process of storing industrial time series data in a plurality of different time series databases in embodiment 1 is described, and as shown in fig. 2, the method may include the following steps:
step S21, when a storage request for target industrial time series data is received, analyzing the data type from the storage request.
Data types may include, but are not limited to: string, boolean, long or Float type.
And S22, judging whether the data type is the data type supported by the time sequence database.
It will be appreciated that the types of data supported by the timing database may be preset, e.g., the timing database support String and Boolean may be preset.
If not, executing step S23; if yes, go to step S24.
In this embodiment, the timing database provides a modification interface for receiving modification instructions for the data types supported by the timing database.
The modification procedure of the data type supported by the time sequence database can comprise the following steps: and modifying the data types supported by the time sequence database according to modification instructions aiming at the data types supported by the time sequence database.
Step S23, discarding the target industrial time sequence data.
In the case where the parsed data type is not a data type supported by the time series database, the time series database cannot parse the data normally and store it, and thus it is necessary to discard the target industrial time series data.
Step S24, storing the target industrial time sequence data into the time sequence database.
The process of storing the target industrial time series data to the time series database may include:
s241, the target industrial time sequence data is sent to a message middleware, and the message middleware stores the target industrial time sequence data within a set storage duration.
The message middleware stores the target industrial time sequence data in a set storage duration, so that external access can be facilitated.
S242, the time sequence database reads the target industrial time sequence data from the message middleware and stores the target industrial time sequence data.
As embodiment 3 of the present application, mainly, a refinement of the process of storing industrial time series data in a plurality of different time series databases described in embodiment 2 above is provided, and as shown in fig. 3, the method may include, but is not limited to, the following steps:
step S31, when a storage request for target industrial time series data is received, the data type is analyzed from the storage request.
And step S32, judging whether the data type is the data type supported by the time sequence database.
If not, executing step S33; if not, step S34 is performed.
And step S33, discarding the target industrial time sequence data.
The detailed procedure of steps S31-S33 can be referred to in the related description of steps S21-S23 in embodiment 2, and will not be described herein.
And step S34, compressing the target industrial time sequence data to obtain compressed data under the condition that the time sequence database is a historical time sequence database.
Step S35, storing the compressed data in the history time sequence database according to the storage mode that each field of the same kind of industrial time sequence data is respectively stored in different rows.
According to the storage mode that each field of the industrial time sequence data of the same kind is respectively stored in different rows, the compressed data is stored in the historical time sequence database, so that each field of the industrial time sequence data can be respectively stored, and the query efficiency is improved when a certain field of the industrial time sequence data is queried.
And, store the said compressed data in the said historical time sequence database, can save the memory space of the historical time sequence database.
Steps S34-S35 are a specific embodiment of step S24 in example 2.
As embodiment 4 of the present application, mainly, a refinement of the process of storing industrial time series data in a plurality of different time series databases described in embodiment 2 above is provided, and as shown in fig. 4, the method may include, but is not limited to, the following steps:
step S41, when a storage request for target industrial time series data is received, analyzing the data type from the storage request.
Step S42, judging whether the data type is the data type supported by the time sequence database.
If not, executing step S43; if yes, go to step S44.
Step S43, discarding the target industrial time sequence data.
And S44, compressing the target industrial time sequence data to obtain compressed data when the time sequence database is a historical time sequence database based on HBase.
In this embodiment, the history time sequence database based on HBase may be set to be automatically created monthly for the data table, the data of the month is stored in the same data table, and the data table may be composed of a row key internal ID, a field name, a field type, and a time stamp (hour). The keys of the time series data of the same kind and the same hour may be set to be the same.
Step S45, storing the compressed data in a first column cluster in the history time sequence database based on HBase according to a storage mode that data of each field of the industrial time sequence data of the same kind are respectively stored in different columns.
And step S46, performing aggregation calculation on the target industrial time sequence data in a third set time length to obtain an aggregation result, and storing the aggregation result in a second column cluster in the HBase-based historical time sequence database.
Aggregate calculations for the target industrial time series data within a third set period of time may include, but are not limited to: and calculating the maximum value, the minimum value, the average value, the total point number, the first value or the last value of the target industrial time sequence data in the third set time length, and respectively returning a calculation result.
The third set period of time may be, but is not limited to: and 1 hour.
In this embodiment, the method of individually storing the aggregate calculation result may improve query efficiency of the aggregate result.
Next, the system for accessing industrial time series data provided by the present application will be described, and the system for accessing industrial time series data described below and the method for accessing industrial time series data described above can be referred to correspondingly.
Referring to fig. 5, the access system for industrial time series data includes: a plurality of different time series databases DB, a parsing module 11, a selection module 12, a first query module 13 and a second query module 14.
The plurality of different time series databases DB are denoted DB1, DB2, …, DBn, respectively. n is an integer greater than 1.
The plurality of different timing database DBs includes: the system comprises a real-time sequence database and a historical time sequence database, wherein the real-time sequence database stores industrial time sequence data with reporting time in a first set time length before the current time, the historical time sequence database stores industrial time sequence data with reporting time in a second set time length before the current time, and the second set time length is longer than the first set time length; an analysis module; a selection module; the system comprises a first query module and a second query module;
the parsing module 11 is configured to parse a data identifier and a query time range from the industrial time-series data query request when the industrial time-series data query request is received;
the selecting module 12 is configured to select one of the plurality of different time sequence databases as a time sequence database to be accessed according to the query time range;
the first query module 13 is configured to query industrial time sequence data matching the data identifier and the query time range from the real-time sequence database if the time sequence database to be accessed is a real-time sequence database;
the second query module 14 is configured to query the historical time sequence database for industrial time sequence data matching the data identifier and the query time range if the time sequence database to be accessed is the historical time sequence database.
In this embodiment, the real-time sequence database may include: the first real-time database sub-database and the second real-time database sub-database;
the first real-time database stores industrial time sequence data with reporting time being in a first set duration before the current time, and the second real-time database stores industrial time sequence data with reporting time being in a time before the current time.
In this embodiment, the access system for industrial time series data may further include:
a storage module for:
when a storage request aiming at target industrial time sequence data is received, analyzing a data type from the storage request;
judging whether the data type is the data type supported by the time sequence database;
if not, discarding the target industrial time sequence data;
if yes, the target industrial time sequence data is stored in the time sequence database DB.
In this embodiment, the access system for industrial time series data may further include:
and the modification module is used for modifying the data types supported by the time sequence database DB according to modification instructions aiming at the data types supported by the time sequence database DB.
In this embodiment, in the case where the time-series database DB is a history time-series database, the storage module may be specifically configured to:
compressing the target industrial time sequence data to obtain compressed data;
and storing the compressed data in the historical time sequence database according to a storage mode that each field of the industrial time sequence data of the same kind is respectively stored in different rows.
In this embodiment, in the case where the timing database DB is an HBase-based history timing database, the storage module may be specifically configured to:
compressing the target industrial time sequence data to obtain compressed data;
storing the compressed data in a first column cluster in the HBase-based historical time sequence database according to a storage mode that data of each field of the same kind of industrial time sequence data are respectively stored in different columns;
and performing aggregation calculation on the target industrial time sequence data in a third set time length to obtain an aggregation result, and storing the aggregation result in a second column cluster in the HBase-based historical time sequence database.
It should be noted that, in each embodiment, the differences from the other embodiments are emphasized, and the same similar parts between the embodiments are referred to each other. For the apparatus class embodiments, the description is relatively simple as it is substantially similar to the method embodiments, and reference is made to the description of the method embodiments for relevant points.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
For convenience of description, the above devices are described as being functionally divided into various units, respectively. Of course, the functions of each element may be implemented in the same piece or pieces of software and/or hardware when implementing the present application.
From the above description of embodiments, it will be apparent to those skilled in the art that the present application may be implemented in software plus a necessary general hardware platform. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method described in the embodiments or some parts of the embodiments of the present application.
The above describes in detail an industrial time series data access method and system provided by the present application, and specific examples are applied to illustrate the principles and embodiments of the present application, and the above examples are only used to help understand the method and core ideas of the present application; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.