Patent Description:
Time series data refers to data sequences recorded by the same indicator in chronological order, while a time series database is a specialized database used to store and manage time series data. A time series database in an Internet of things (IoT) system is usually used to store data generated in a large number of scenarios of real-time monitoring, alarming, and analysis and needs to provide larger storage space and the ability to quickly query and process data.

In related arts, upon acquiring data to be stored, a database server stores the data to be stored in a relevant file based on a timestamp, and compresses the file. When data is queried, the relevant file is decompressed in response to a query instruction and the data to be queried is returned.

However, the time series database in related technologies stores all data indiscriminately, and cannot provide targeted compression and storage methods for different types of data, and the compression rate is low. <CIT> discloses a system, method and apparatus for data collection in an industrial production environment. The system may include, a data acquisition circuit structured to interpret a plurality of detection values, each of the plurality of detection values corresponding to input received from at least one of a plurality of input sensors which includes a detection package, each of the plurality of input sensors operatively coupled to at least one of a plurality of components of an industrial production process, a data analysis circuit structured to analyze a subset of the plurality of detection values to determine a sensor performance value of at least one of the plurality of input sensors, and an analysis response circuit structured to adjust at least one of a sensor scaling value or a sensor sampling frequency value, in response to the sensor performance value. Further prior art is known from the Wikipedia article for "Huffman coding".

The underlying problem of the present invention is solved by the subject matter of the independent claims. According to embodiments of the present disclosure, a method and apparatus for storing and querying time series data, and a server and a storage medium thereof are provided.

In one aspect, embodiments of the present disclosure provide a method for storing and querying time series data. The method includes:.

In another aspect, embodiments of the present disclosure provide an apparatus for storing and querying time series data. The apparatus includes:.

In another aspect, embodiments of the present disclosure provide a server. The server includes a processor and a memory. The memory stores at least one instruction, at least one program, a code set, or an instruction set. The at least one instruction, the at least one program, the code set, or the instruction set, when loaded and executed by the processor, causes the processor to perform the method for storing and querying time series data as described in the above aspect.

In another aspect, embodiments of the present disclosure provide a computer-readable storage medium. The computer-readable storage medium stores at least one instruction, at least one program, a code set, or an instruction set. The at least one instruction, the at least one program, the code set, or the instruction set, when loaded and executed by a processor, causes the processor to perform the method for storing and querying time series data as described in the above aspect.

The technical solutions according to the embodiments of the present disclosure achieve at least the following beneficial effects.

A data type of data to be stored is determined. Different types of data are compressed and stored to corresponding data storage tables by different compression methods based on the characteristics thereof, thereby improving the compression efficiency of time series data and saving storage resources. Moreover, during data query, time series data that meets a query time condition is searched from a data storage table corresponding to a query data type, which improves the query efficiency of different types of time series data.

In order to make the objects, technical solutions, and advantages of the present disclosure clearer, the following will further describe the embodiments of the present disclosure in detail with reference to the accompanying drawings.

The term "a plurality of" mentioned herein means two or more, and the term "and/or" describes an association relationship of associated objects, indicating that there may be three types of relationships. For example, A and/or B may indicate three situations: A exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the associated objects are in an "or" relationship.

In related arts, time series database software is usually used for the storage of time series data. For data to be stored with different indicators sent by different IoT devices, a database server stores it in a corresponding data storage table, but all data is compressed by a default compression method of the time series database software defaults, which results in low compression rate. Moreover, the query computing power of the database is limited, which requires a lot of other service logic support.

In order to solve the foregoing problems, the embodiments of the present disclosure provide a method for storing and querying time series data for time series data of different data types. <FIG> shows a schematic diagram of an implementation environment according to an exemplary embodiment of the present disclosure. The implementation environment includes an Internet of things (IoT) device <NUM>, a database server <NUM>, and a query terminal <NUM>.

The IoT device <NUM> is a device with a data acquisition function for acquiring time series data, which may be a new energy device equipped with sensors such as a wind speed detector, a temperature and humidity detector, and a photovoltaic sensor, such as a wind generator and a photovoltaic panel. As shown in <FIG>, a plurality of IoT devices <NUM> acquire time series data of different data types, and send the acquired time series data to the database server <NUM>. In a possible application scenario, the IoT device <NUM> sends the data to the database server <NUM> by a gateway device.

The IoT device <NUM> and the database server <NUM> are connected over a wired or wireless network.

The database server <NUM> is a storage device that stores the data acquired by the IoT device <NUM>, which may be a server, a server cluster composed of several servers, or a cloud server. Optionally, the database server <NUM> acquires data to be stored sent by the IoT device <NUM>, determines a corresponding data compression method based on a data type of the data to be stored, and stores compressed data in a corresponding data storage table.

The database server <NUM> and the query terminal <NUM> are connected over a wired or wireless network.

The query terminal <NUM> is a device with a data query function. In a possible application scenario, the query terminal <NUM> sends a query request containing a query data type and a query time condition to the database server <NUM>. The database server <NUM> determines a corresponding data storage table based on the query data type, decompresses the data storage table, determines target data in the data storage table based on the query time condition, and feeds back a query result to the query terminal <NUM>. The query terminal <NUM> displays the received time series data in the form of a chart. The query terminal <NUM> may be a personal computer, a smart phone, a tablet computer, or the like. As shown in <FIG>, the query terminal <NUM> is a personal computer.

<FIG> shows a flowchart of a method for storing and querying time series data according to an exemplary embodiment of the present disclosure. In this embodiment, the method being applied to a database server is taken as an example for description.

In step <NUM>, after data to be stored is received from an IoT device, a data type of the data to be stored is determined. The data to be stored is time series data. The data type is intended to indicate a change in the time series data over time.

Time series data refers to data sequences recorded by the same indicator in chronological order. In an IoT system, time series data acquired by different IoT devices vary over time. Therefore, in some embodiments, data acquired by an IoT device may be categorized into different types of data based on changes thereof over time in advance. When receiving data to be stored from the IoT device, the database server may first determine its data type.

Optionally, upon receiving data to be stored sent by an IoT device, the database server may determine its data type based on a device identifier or a keyword indicating a data indicator carried in the data to be stored.

In step <NUM>, compressed data is obtained by compressing the data to be stored by a data compression method corresponding to the data type. Different data types correspond to different data compression methods.

The database server categorizes the data into different types, and compresses each type of data in a corresponding manner, thereby maximizing a compression rate of the database.

In some embodiments, the database server is preset with multiple data compression methods, and matches a corresponding compression method for each type of data. After a data type of the data to be stored is determined, the data is compressed by a corresponding data compression method.

In step <NUM>, the compressed data is stored to a data storage table corresponding to the data type. Different data types correspond to different data storage tables.

Compared with relational databases, time series databases (such as Open TSDB) in related technologies have characteristics of high throughput and high compression rate. However, the data storage table is sole and cannot perform classified storage based on data types of time series data. Therefore, the data processing capacity of the time series database is limited.

In some embodiments, the database server is provided with a plurality of types of data storage tables. Data of different data types is allocated to different data storage tables for isolated storage. On this basis, different data query capabilities are provided to improve the data query efficiency of the database. The database server compresses the data to be stored by a corresponding data compression method based on the data type thereof, and then stores compressed data in a corresponding data storage table.

Optionally, the database server marks different types of data storage tables which correspond to marks indicating data types in the data to be stored, compresses the data to be stored, and then stores the same in a corresponding data storage table. Since the data acquired by the IoT device is time series data, the database server stores the data to be stored to a data storage table in the order of time stamp.

In step <NUM>, a query request is received. The query request includes a query data type and a query time condition.

In addition to storing the data sent by the IoT device, the database server also has a query function. Users may send query requests as needed, and perform data analysis based on query results returned by the database server to obtain a change trend of a certain indicator, an increase or decrease in revenue or data details within a specific time and other information.

In some embodiments, a user inputs a query request on a client. The database server receives the query request and obtains a query data type and a query time condition in the query request. The query data type is intended to determine a data storage table. The query time condition is intended to determine data in the data storage table.

In step <NUM>, target data that meets the query time condition is queried from a data storage table corresponding to the query data type.

In some embodiments, the database server acquires the query data type in the query request, determines a data storage table corresponding to the type, decompresses the data storage table, determines and extracts target data in the data storage table based on the query time condition, and returns a query result.

If the query request also contains other query conditions, the database server performs statistical analysis and calculation processing on the target data based on a specific query condition.

In summary, in the embodiments of the present disclosure, a data type of data to be stored is determined, and different types of data are compressed and stored in corresponding data storage tables by different compression methods based on the characteristics thereof, which can greatly improve compression efficiency and save system resources. On the basis of different types of data storage tables, target data is determined based on a query condition, which provides rich query capabilities, and improves data query efficiency.

In an IoT system, time series data acquired by an IoT device mainly includes three types, namely an analog quantity, a state quantity, and a cumulative quantity. Changes in different types of time series data change over time are different. The state quantity is a physical quantity that is discontinuous over time and has a value belonging to a preset enumerated data set, such as a position signal of a circuit breaker or an isolating switch, an action signal of a protection device, or an operation state signal of a communication device. The analog quantity is a physical quantity that is continuous over time and has a value within a preset value range but cannot be enumerated, such as temperature, wind speed, or voltage value. The cumulative quantity is a physical quantity whose value increases progressively over time and is a cumulative value of a certain indicator over a time period, such as electric meter reading, or car mileage. <FIG> shows a schematic diagram of a data storage process according to an exemplary embodiment of the present disclosure. The data sent by the IoT device <NUM> to the database server is categorized into an analog quantity, a state quantity, a cumulative quantity, and other types of data. The database server compresses the data to be stored by a corresponding compression algorithm based on the data type of the data to be stored, and stores compressed data in a corresponding data storage table. The present disclosure illustrates the method for storing and querying time series data by taking an analog quantity, a state quantity, and a cumulative quantity as examples.

<FIG> shows a flowchart of a method for storing and querying time series data according to another exemplary embodiment of the present disclosure. In this embodiment, the method being applied to a database server is taken as an example for description.

For details of this step, reference may be made to step <NUM>, which are not repeated in this embodiment.

In step <NUM>, when the data to be stored is a state quantity, values of n pieces of data to be stored that are continuously received are read, wherein n is an integer greater than or equal to <NUM>.

Regarding the state quantity, only the time point and data of change are concerned during query and calculation, and data within the time period when no change occurs is not concerned. Therefore, it is unnecessary to store every piece of data sent by the IoT device, and only data at the moment when the state quantity changes is stored.

In some embodiments, in order to only retain data when a change occurs, the database server needs to compare the values of the data to be stored. When n pieces of data to be stored are continuously received, the database server first reads values of the n pieces of data to be stored, wherein n may be set according to the actual data acquisition situation of the IoT device.

In some embodiments, a switch of the IoT device has two positions: on and off. It uploads data containing a switch position signal to the database server every one minute. An on state is represented by a number <NUM>. An off state is represented by a number <NUM>. Before <NUM>:<NUM>:<NUM>, the switch position signal of the loT device is <NUM>. The switch position signal becomes <NUM> at <NUM>:<NUM>:<NUM> and continues until <NUM>:<NUM>:<NUM>. At <NUM>:<NUM>:<NUM>, the value of the state quantity uploaded by the IoT device is <NUM>. That is, between <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM>, the switch position signal data of the IoT device is <NUM>, <NUM>, <NUM>, <NUM>, <NUM>, <NUM>, <NUM>. If the database server is set to acquires values of <NUM> pieces of data to be stored at one time and the previous acquisition is until <NUM>:<NUM>:<NUM>, the database server acquires values of the data to be stored from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> at this time, namely <NUM>, <NUM>, <NUM>, <NUM>, <NUM>.

In step <NUM>, compressed data is obtained by compressing the data to be stored based on changes in the values of the n pieces of data to be stored.

Regarding the state quantity, a user usually only cares about data at the moment of change when querying, so the data server performs compression and storage based on a change in the value of the data to be stored.

In some embodiments, this step may include the following sub-steps:.

In some embodiments, when the data to be stored is a state quantity, the database server reads the values of the n pieces of data to be stored, and then compares values of data other than a first piece of data among the n pieces of data to be stored with a value of a previous piece of data. If a value of a certain piece of data is different from that of a previous piece of data, the data is retained. The first piece of data among the n pieces of data to be stored needs to be compared with a value of the last state quantity stored in the corresponding data storage table. If they are different, the first piece of data is retained.

In some embodiments, the switch position signal data of the IoT device acquired by the database server from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> is <NUM>, <NUM>, <NUM>, <NUM>, <NUM>. Starting from a second piece of data to be stored, a value of each piece of data to be stored is compared with that of a previous piece of data to be stored. If the values are different, the piece of data to be stored is retained. That is, the data at <NUM>:<NUM>:<NUM> is retained. A value of the first piece of data to be stored needs to be compared with that of the last piece of data in the corresponding data storage table with a purpose to determine whether the first piece of data to be stored is a piece of data that has changed. If the value of the last piece of data in the data storage table is <NUM>, then the data at <NUM>:<NUM>:<NUM> is retained.

If the value of the (i+<NUM>)th piece of data to be stored is the same as that of the ith piece of data to be stored, the (i+<NUM>)th piece of data to be stored is deleted.

Starting from a second piece of data among the n pieces of data, if a value of a current piece of data to be stored is the same as that of a previous piece of data to be stored, the current piece of data is deleted. A value of a first piece of data to be stored needs to be compared with that of the last piece of data in the corresponding data storage table. If they are the same, the first piece of data to be stored is deleted.

In some embodiments, the switch position signal data of the IoT device acquired by the database server from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> is <NUM>, <NUM>, <NUM>, <NUM>, <NUM>. Starting from a second piece of data to be stored, a value of each piece of data to be stored is compared with that of a previous piece of data to be stored. If the values are the same, a current piece of data to be stored is deleted. That is, three pieces of data from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> need to be deleted. The data at <NUM>:<NUM>:<NUM> needs to be compared with a value of the last piece of data in the corresponding data storage table. If the values are the same, the first piece of data to be stored is deleted. If they are different, the first piece of data to be stored is retained. Because the value of the data to be stored at <NUM>:<NUM>:<NUM> is difference from that of the last piece of data in the data storage table, it indicates that the switch state changes at <NUM>:<NUM>:<NUM>, and the data is retained.

In step <NUM>, when the data to be stored is an analog quantity, the compressed data is obtained by compressively sampling the data to be stored based on an acquisition frequency of the data to be stored and a target sampling frequency. The acquisition frequency is higher than the target sampling frequency.

In some embodiments, data acquired by an IoT device is an analog quantity, and an acquisition frequency is relatively high. However, if a user needs a change trend of the analog quantity within a long time period when querying and analyzing or statistical results of the data and do not need specific details, the database server may compress the data to be stored of the analog quantity by sampling and compression. That is, the database server retains one piece of data to be stored at predetermined time intervals based on a preset target sampling frequency and delete the remaining data, thereby reducing the space occupied by the data. The target sampling frequency is smaller than the acquisition frequency of the IoT device.

In some embodiments, the IoT device is a wind speed detector, which acquires the wind speed every <NUM> seconds and uploads it to the database server. Since the wind speed generally does not change abruptly and a user usually only needs to query the wind speed changes in a few hours or a day, a specific wind speed every <NUM> seconds does not need to be specified. A target sampling frequency of the database server for the analog data sent by the IoT device may be set to once every minute. For example, from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM>, the IoT device acquires <NUM> sets of wind speeds and uploads them to the database server. The database server only retains data at <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM> based on the target sampling frequency once per minute and compresses the data, and delete the remaining <NUM> groups of data.

Optionally, the data to be stored whose data type is an analog quantity may be compressed by a lossless compression method of a time series database, such as Huffman compression algorithm.

In step <NUM>, when the data to be stored is a cumulative quantity, the data to be stored is compressed by a preset lossless compression algorithm of a time series database.

Since a value of the cumulative quantity increases progressively over time which is a cumulative value of a certain indicator and usually its data acquisition frequency is relatively low, it is necessary to retain complete data when performing compression and storage. In some embodiments, the database server compresses the cumulative quantity by a lossless compression method of a time series database.

It should be noted that no strict order is defined between steps <NUM> to <NUM> and step <NUM> and step <NUM>. That is, steps <NUM> to <NUM> and step <NUM> and step <NUM> may be performed synchronously, which is not limited in this embodiment.

In some embodiments, the database server is provided with a plurality of types of data storage tables. Each type of data storage table corresponds to one data type, and only stores data of that type. When a user needs to query data, he/she only needs to decompress the corresponding data storage table. Based on different types of data storage tables, corresponding query algorithms are set to enable the database server to have rich query capabilities.

In addition to storing the data acquired by the IoT device, the database server also has data query and analysis capabilities, and provides different query capabilities for different types of data.

In some embodiments, a user initiates a query request on a client, which includes a query data type and a query time conditions. After the database server receives the query request from the client, it determines and decompresses a corresponding data storage table based on the query data type, and then determines relevant data in the data storage table based on the query time condition.

In some embodiments, a query data type, a query object, a query time condition, and a query service need to be entered in a query interface. For example, a user may enter the minimum temperature of each day in November <NUM> in a certain area in the query analog quantity.

As shown in <FIG>, different types of data have different query requirements. Since the database server stores each type of data separately in a corresponding data storage table, it can meet the query requirements of each type of data. For example, a user may perform basic aggregation queries (such as summation, average, and solving minimum and maximum values) and interpolation queries for analog data, and may also set other query methods according to the actual data. For a state quantity, displacement reading, adjacent state query, state statistics, and the like may be performed. For a cumulative quantity, it is usually necessary to perform data decomposition and perform related queries on this basis, for example, querying related fees such as related costs and benefits.

In step <NUM>, when the query data type is the state quantity, if the query time condition is a first moment and a data storage table corresponding to the state quantity does not store data corresponding to the first moment, then data corresponding to a second moment in the data storage table is determined to be target data. The second moment is before the first moment and is closest to the first moment.

In some embodiments, because the compression method of the state quantity is to only retain data when a change occurs and delete data when no change occurs, the data is not complete, and there may be no corresponding data stored in the data storage table at the first moment of user input. However, since the stored data is unchanged data, its value is equal to that of data in the data storage table that is closest to its moment and before that moment. That is, the data corresponding to the second moment is the target data, and the database server returns the data at the second moment.

In some embodiment, if a user needs to query the switch state of the IoT device at <NUM>:<NUM>:<NUM>, after a corresponding data storage table is determined based on the data type and it is detected that no data is present at that moment, data closest to that moment and before that moment is returned, i.e., data at <NUM>:<NUM>:<NUM> with a value of <NUM>, which indicates that the switch state of the IoT device is off at <NUM>:<NUM>:<NUM>.

In some embodiments, the query data type is the state quantity. If the query time condition is a target time period, data within the target time period in the data storage table is determined as target data. When a user needs to query a state quantity or a statistical result of the state quantity within a time period, the query time condition is one time period, and the database server returns the state quantity or the statistical result thereof within this time period.

In some embodiments, if a user needs to query statistical results of state quantities of the IoT device from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM>, the database server determines a corresponding data storage table and determines target data based on the time period of the query time condition to acquire data at <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM>, the values of which are <NUM> and <NUM> respectively. The returned statistical results are once on and once off.

In step <NUM>, when the query data type is the analog quantity, if the query time condition is a third moment and a data storage table corresponding to the analog quantity does not store data corresponding to the third moment, data corresponding to at least one fourth moment and at least one fifth moment in the data storage table is acquired. The fourth moment is before the third moment and closest to the third moment. The fifth moment is after the third moment and closest to the third moment.

In some embodiments, since the compression method of the analog quantity may be sampling and compression, the data thereof is incomplete, and data at a certain moment queried by a user may not be stored in the data storage table. The database server first determines data at two moments or within two time periods that are closest to the third moment of the query time condition before and after.

In some embodiments, if a user needs to query the wind speed acquired by the IoT device at <NUM>:<NUM>:<NUM>, since the IoT device acquires data every one minute for compression and storage, no data at <NUM>:<NUM>:<NUM> is not present in the data storage table. At this moment, the database server acquires data at <NUM>:<NUM>:<NUM> and several moments before and data at <NUM>:<NUM>:<NUM> and several moments after.

In step <NUM>, target data corresponding to the third moment is calculated by an interpolation algorithm based on the data corresponding to the fourth moment and the fifth moment.

According to data corresponding to a moment adjacent to the third moment, the database server fits a function of data within a time period including the third moment by an interpolation algorithm, calculates data corresponding to the third moment, and returns a calculation result.

In some embodiments, if a user needs to query the wind speed acquired by the IoT device at <NUM>:<NUM>:<NUM>, the database server calculates the wind speed at <NUM>:<NUM>:<NUM> based on data at <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM> and data at <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM>. Assuming that the wind speeds corresponding to <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM>, <NUM>:<NUM>:<NUM> and <NUM>:<NUM>:<NUM> are all <NUM>/s, a function is fitted and the wind speed at <NUM>:<NUM>:<NUM> is calculated to be <NUM>/s.

In some embodiments, the query data type is the analog quantity. If the query time condition is a target time period, target data corresponding to the target time period in the data storage table is acquired. If the query request also includes other query conditions, a target function is determined based on a specific query condition, the target data is calculated and processed based on the target function, and a calculation result is obtained and returned to a query device.

In some embodiments, if a user needs to query the maximum wind speed from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> acquired by the IoT device, the database server determines data within this time period in a corresponding data storage table, determines a function to solve the maximum value, calculates the maximum value of wind speed from <NUM>:<NUM>:<NUM> to <NUM>:<NUM>:<NUM> with this function, and returns a result to the client.

In step <NUM>, when the query data type is the cumulative quantity, components corresponding to respective time periods are calculated based on adjacent cumulative quantities in the data storage table.

When querying a cumulative quantity, it is usually necessary to perform data decomposition first, that is, calculate components of time periods, so as to perform data statistics or other joint calculations, such as calculating the electricity bill by combining the electric meter reading with the electricity price. The database server subtracts a cumulative quantity corresponding to a previous moment from a cumulative quantity corresponding to each moment to obtain a component corresponding to each time period.

In some embodiments, the query data type is the cumulative quantity, the query time condition is a sixth moment, and the target data is determined based on the sixth moment. When a user needs to query a cumulative quantity at a certain time, the database server queries and directly returns the cumulative quantity at that moment.

In step <NUM>, target components belonging to a target time period indicated by the query time condition are queried.

In some embodiments, after decomposing the components corresponding to the respective time periods, the database server determines a target component that a user needs to query based on a target time period.

In some embodiments, if a user needs to query an electric meter reading acquired by the IoT device and needs the electricity consumption and electricity bill for each day in September, and the database server stores an electric meter reading for each day from September <NUM> to September <NUM>, namely each day's cumulative electricity consumption, the database server first starts with data of the second day, and subtracts a cumulative quantity of a previous day from a cumulative quantity per day to obtain a daily electricity consumption in September.

In step <NUM>, target data is determined based on the target components.

Upon acquiring components of the cumulative quantity in respective time periods, the database server performs data statistics or calculation on target components to determine target data. In some embodiments, if a user needs to query fees of a certain cumulative quantity in respective time periods within a period of time, it is necessary to calculate in combination with components of the cumulative quantity in the respective time periods and the cost.

In some embodiments, if a user needs to query an electric meter reading acquired by the IoT device and the electricity consumption and electricity bill for each day in September, the database server subtracts a cumulative quantity of a previous day from a cumulative quantity per day starting from data of the second day to obtain a daily electricity consumption in September, and then calculates a daily electricity bill in combination with the electricity price in September.

It should be noted that no strict order is defined between step <NUM> and steps <NUM> to <NUM>, and steps <NUM> to <NUM>. That is, step <NUM>, steps <NUM> to <NUM>, and steps <NUM> to <NUM> may be performed synchronously, which is not limited in this embodiment.

In the embodiments of the present disclosure, data types are categorized into state quantities, analog quantities, and cumulative quantities based on their change characteristics over time, and a different data compression method is adopted for each data type, which maximizes the compression rate and saves system resources. Different types of data are stored in different data storage tables. On this basis, a variety of query functions are provided for the database server. Users can query data and its statistics or calculation results according to actual needs, which improves the query capability of the database server.

<FIG> is a structural block diagram of an apparatus for storing and querying time series data according to an exemplary embodiment of the present disclosure. The apparatus may be disposed in the database server described in the above embodiment. As shown in <FIG>, the apparatus includes:.

Optionally, the data to be stored is a state quantity; the state quantity is a physical quantity that is discontinuous over time and has a value belonging to a preset enumerated data set; and the processing module <NUM> includes:.

Optionally, the compressing unit is further configured to:.

Optionally, the query data type is the state quantity; and the querying module <NUM> includes:
a first determining unit, configured to determine data corresponding to a second moment in the data storage table to be the target data if the query time condition is a first moment and the data storage table corresponding to the state quantity does not store data corresponding to the first moment, wherein the second moment is before the first moment and is closest to the first moment.

Optionally, the data to be stored is an analog quantity; the analog quantity is a physical quantity that is continuous over time and has a value within a preset value range; and the processing module <NUM> further includes:
a second compressing unit, configured to obtain the compressed data by sampling and compressing the data to be stored based on an acquisition frequency of the data to be stored and a target sampling frequency, wherein the acquisition frequency is higher than the target sampling frequency.

Optionally, the query data type is the analog quantity; and the querying module <NUM> further includes:.

Optionally, the data to be stored is a cumulative quantity; the cumulative quantity is a physical quantity whose value increases progressively over time; and the data to be stored is compressed by a preset lossless compression algorithm of a time series database.

The query data type is the cumulative quantity; and the querying module <NUM> further includes:.

<FIG> shows a schematic structural diagram of a server according to an exemplary embodiment of the present disclosure. Specifically, the server <NUM> includes a central processing unit (CPU) <NUM>, a system memory <NUM> including a random access memory (RAM) <NUM> and a read-only memory (ROM) <NUM>, and a system bus <NUM> connecting the system memory <NUM> and the central processing unit <NUM>. The server <NUM> also includes a basic input/output (I/O) system <NUM> that helps transfer information between various devices in the server, and a mass storage device <NUM> for storing an operating system <NUM>, application programs <NUM>, and other program modules <NUM>.

The basic input/output system <NUM> includes a display <NUM> for displaying information and an input device <NUM> such as a mouse and a keyboard for a user to input information. The display <NUM> and the input device <NUM> are both connected to the central processing unit <NUM> by an input and output controller <NUM> connected to the system bus <NUM>. The basic input/output system <NUM> may further include the input and output controller <NUM> for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input and output controller <NUM> also provides outputs to a display screen, a printer, or other types of output devices.

The mass storage device <NUM> is connected to the central processing unit <NUM> by a mass storage controller (not shown) connected to the system bus <NUM>. The mass storage device <NUM> and its associated server-readable storage medium provide nonvolatile storage for the server <NUM>. That is, the mass storage device <NUM> may include a server-readable storage medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.

Without loss of generality, the server-readable storage medium may include a server storage medium and a communication medium. The server storage medium includes volatile and nonvolatile, removable and non-removable medium implemented in any method or technology for storing information such as server-readable storage instructions, data structures, program modules, or other data. The server storage medium includes a RAM, a ROM, an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, or other solid state storage devices, a CD-ROM, a digital versatile disk (DVD) or other optical storage devices, a tape cassette, a magnetic tape, a disk storage or other magnetic storage devices. Those skilled in the art may know that the server storage medium is not limited to the foregoing. The aforementioned system memory <NUM> and mass storage device <NUM> may be collectively referred to as memory.

The memory stores one or more programs configured to be run by one or more central processing units <NUM> and including instructions for performing the above-mentioned method for storing and querying time series data. The central processing unit <NUM> run the one or more programs to perform the method for storing and querying time series data according to the above method embodiments.

According to various embodiments of the present disclosure, the server <NUM> may also be connected to a remote server over a network such as the Internet to run. That is, the server <NUM> may be connected to a network <NUM> by a network interface unit <NUM> connected to the system bus <NUM>. In other words, the network interface unit <NUM> may also be used to connect to other types of networks or remote server systems (not shown).

The memory further includes one or more programs. The one or more programs include instructions to perform the steps performed by the database server in the method provided in the embodiments of the present disclosure.

An embodiment of the present disclosure further provides a computer-readable storage medium storing at least one computer program including at least one instruction. The at least one instruction, when loaded and executed by a processor, causes the processor to perform the method for storing and querying time series data described in the above embodiments.

An embodiment of the present disclosure further provides a computer program product storing at least one instruction therein. The at least one instruction, when loaded and executed by a processor, causes the processor to perform the method for storing and querying time series data described in the above embodiments.

Those skilled in the art may be aware that, in one or more of the foregoing examples, the functions described in the embodiments of the present disclosure may be implemented by hardware, software, firmware, or any combination thereof. When implemented by software, these functions may be stored in a computer-readable storage medium or transmitted as one or more instructions or codes on the computer-readable storage medium. The computer-readable storage medium includes a computer storage medium and a communication medium. The communication medium includes any medium that facilitates the transfer of a computer program from one place to another. The storage medium may be any available medium that may be accessed by a general-purpose or special-purpose computer.

Claim 1:
A computer-implemented method (<NUM>) for storing and querying time series data, comprising:
upon receiving data to be stored from an Internet of things, IoT, device, determining (<NUM>) a data type of the data to be stored, wherein the data to be stored is time series data, and the data type is intended to indicate a change in the time series data over time;
obtaining (<NUM>) compressed data by compressing the data to be stored by a data compression method corresponding to the data type, wherein different data types correspond to different data compression methods;
storing (<NUM>) the compressed data to a data storage table corresponding to the data type, wherein different data types correspond to different data storage tables;
receiving (<NUM>) a query request, wherein the query request comprises a query data type and a query time condition; and
querying (<NUM>) target data that meets the query time condition from a data storage table corresponding to the query data type;
wherein the data to be stored comprises a state quantity, wherein the state quantity is a physical quantity that is discontinuous over time and has a value belonging to a preset enumerated data set, and obtaining the compressed data by compressing the data to be stored by the data compression method corresponding to the data type comprises:
reading values of n pieces of state quantity that are continuously received, wherein n is an integer greater than or equal to <NUM>; and
obtaining the compressed data by compressing the n pieces of state quantity based on changes in the values of the n pieces of state quantity.