Data query method and device and readable storage medium
By determining the target brief table from the brief table of the data table and querying, the problem of large amount of data in the data table is solved, resulting in low query efficiency, and more efficient data query is achieved.
Patent Information
- Application Number
- CN202311433020.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-31
- Publication Date
- 2025-05-02
AI Technical Summary
During the data query process, due to the large amount of data stored in the data table, the query efficiency is low.
By determining the target brief table from at least one brief table of the data table and querying the target data from the target brief table according to the query conditions in the query request, the query of the data table is converted into a query of the brief table, which significantly reduces the amount of data that needs to be processed during the query process.
Shorten the query time and improve query efficiency. By simplifying the query process and reducing the data processing volume, the performance of data query is significantly improved.
Smart Images

Figure CN119917529A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data query, and in particular to a data query method, device and readable storage medium. Background Art
[0002] At present, in order to uniformly store and manage data, a large amount of data is usually stored in a data table. Taking the battery-related business as an example, the data of a large number of batteries produced by the enterprise (including voltage, current, temperature, etc.) can be centrally stored in a data table, so that the battery data can be added, deleted, and modified through the data table, realizing the unified storage and management of battery data.
[0003] When data is stored in a data table, you can query the data table and obtain the data from the data table when you need to use the data. In the data query process, you may need to group, filter, and calculate the data in the data table. The amount of data stored in the data table is usually large, so a large amount of data may need to be processed during the query process, resulting in low query efficiency. Summary of the invention
[0004] The embodiments of the present application provide a data query method, device and readable storage medium, which can reduce the amount of data in the data query process and improve the query efficiency.
[0005] In a first aspect, a data query method is provided, comprising:
[0006] Receiving a query request including a first query condition, wherein the query request is used to request to query target data from a data table;
[0007] determining a target profile from at least one profile of the data table;
[0008] The target data is queried from the target profile according to the first query condition.
[0009] In the data query method provided in the embodiment of the present application, after receiving the query request, a target simple table is determined from at least one simple table of the data table, and the target data is obtained by querying from the target simple table according to the query condition in the query request. In this way, the query of the data table can be converted into the query of the simple table of the data table. Since the amount of data stored in the simple table is less than that of the data table, when querying the target data from the simple table, the amount of data to be processed during the query process can be significantly reduced, thereby shortening the query time and improving the query efficiency.
[0010] In some embodiments, determining a target profile from at least one profile in the data table comprises:
[0011] Determine, from the at least one simple table, at least one first simple table whose corresponding time granularity is less than or equal to a first time granularity, wherein the simple table stores time series data obtained by aggregating time series data in the data table by a preset time granularity, and the first time granularity is the time granularity of the target data;
[0012] The target profile is determined from the at least one first profile.
[0013] In an embodiment of the present application, when time series data is stored in a data table, and an aggregated result obtained by aggregating the time series data in the data table at a corresponding time granularity is stored in a simplified table, during a data query process, a simplified table with a time granularity less than or equal to the first time granularity can be determined from at least one simplified table as a target simplified table, and then the target data is obtained by querying from the target simplified table. Since the amount of time series data stored in the simplified table is much less than the amount of time series data stored in the data table, when querying the target data from the target simplified table, the amount of data that needs to be processed during the query process can be significantly reduced, thereby improving the efficiency of data query.
[0014] In some embodiments, determining the target profile from the at least one first profile comprises:
[0015] Determine a time difference between a time granularity corresponding to each of the first profiles and the first time granularity;
[0016] The target profile corresponding to the smallest time difference is determined from the at least one first profile.
[0017] In the embodiment of the present application, in the process of determining the target profile from at least one profile, the first profile with the smallest time difference with the first time granularity is determined from the at least one profile as the target profile. Since the closer the time granularity, the smaller the amount of data that needs to be processed when querying and obtaining target data from the target profile, when the first profile with the smallest corresponding time difference is selected as the target profile, the amount of data that needs to be processed during the data query process can be reduced to the greatest extent, thereby maximizing the data query efficiency.
[0018] In some embodiments, the first query condition includes a query method for the target data, and determining at least one first profile whose corresponding time granularity is less than or equal to the first time granularity from the at least one profile includes:
[0019] At least one first profile whose corresponding time granularity is less than or equal to the first time granularity and whose corresponding aggregation mode matches the query mode is determined from the at least one profile.
[0020] In the embodiment of the present application, during the data query process, the target profile can be determined according to the time granularity of the target data and the query method specified by the first query condition, so that a more accurate target profile can be determined, thereby improving the query efficiency.
[0021] In some embodiments, querying the target data from the target profile according to the first query condition includes:
[0022] Changing the identifier of the data table included in the query request to the identifier of the target profile;
[0023] Based on the identifier of the target profile, the target data is queried from the target profile.
[0024] In the embodiment of the present application, by rewriting the identifier of the data table included in the query request, the query on the data table is rewritten as a query on the target profile, which can facilitate accurate positioning of the target profile and obtain target data from the target profile. In this way, after determining the target profile, the target profile can be directly accessed to obtain the target data, thereby simplifying the query process and improving query efficiency.
[0025] In some embodiments, the method further includes: when the target profile is not included in the at least one profile, querying the target data from the data table according to the first query condition.
[0026] In the embodiment of the present application, when there is no target summary table in at least one summary table of the data table, the data table is continued to be accessed to obtain target data from the data table. The target data can be queried and obtained without the target summary table, thereby improving the reliability of data query.
[0027] In some embodiments, the method further includes: when multiple first time series data within a second time granularity are added to the data table, aggregating the multiple first time series data to obtain second time series data, and the second time granularity is the time granularity corresponding to the simple table; and storing the second time series data in the simple table corresponding to the second time granularity.
[0028] In an embodiment of the present application, after storing new time series data in the data table, the time series data in the simplified table is updated synchronously, so that the time series data in the simplified table can be synchronized with the time series data in the data table, thereby increasing the probability of obtaining target data from the simplified table and further improving data query efficiency.
[0029] In some embodiments, there are multiple simple tables, each of which corresponds to different time granularities. The aggregating the multiple first time series data to obtain the second time series data includes: aggregating the multiple third time series data in the second simple table to obtain the second time series data, the second simple table is a simple table in which the corresponding time granularity of the multiple simple tables is smaller than the second time granularity, and the multiple third time series data are obtained by aggregating the multiple first time series data.
[0030] In an embodiment of the present application, in the process of updating the time series data in the simple table, the newly added time series data in the simple table corresponding to the smaller time granularity is aggregated according to the size of the time granularity, and the aggregation result is stored in the simple table corresponding to the larger time granularity. This can reduce the amount of data that needs to be processed during the aggregation process, thereby improving the updating efficiency of the simple table.
[0031] In some embodiments, the method further includes: determining the target profile from at least one profile of the data table, including: determining the target profile whose marked time granularity matches the first time granularity from the at least one profile.
[0032] In an embodiment of the present application, a profile is marked by a time granularity corresponding to the profile. In the process of determining a target profile, the target profile is determined from at least one profile according to the time granularity marked by the profile. The target profile can be quickly determined from at least one profile, thereby improving the efficiency of determining the target profile, and further improving the efficiency of data query.
[0033] In some embodiments, the simplified table comprises a materialized view.
[0034] In the embodiment of the present application, when the simplified table of the data table is a materialized view, it is convenient to update the data in the simplified table when the data in the data table changes, so that the simplified table can be maintained and managed in a timely manner.
[0035] In some embodiments, the method further includes: upon receiving the original time series data sent by the data source, converting the data structure of the original time series data into a first data structure, wherein the first data structure is the data structure of the time series data stored in the data table; and storing the converted time series data in the data table.
[0036] In the embodiment of the present application, after receiving the original time series data sent by the data source, the data structure of the original time series data is converted, and the converted time series data is stored in the data table, so that the data structure of the time series data can be unified. In this way, it is convenient to manage the time series data in the data table and improve the data management and query efficiency.
[0037] In some embodiments, converting the data structure of the original time series data into a first data structure includes: converting the data structure of the original time series data into the first data structure according to a preset conversion rule corresponding to the data source.
[0038] In an embodiment of the present application, corresponding conversion rules are set for the data source. When time series data sent by the data source is received, the time series data is converted according to the conversion rules corresponding to the data source, which can improve the conversion efficiency of the data structure and thus improve the data storage efficiency.
[0039] In a second aspect, a data query device is provided, comprising:
[0040] A receiving module, configured to receive a query request including a first query condition, wherein the query request is used to request to query target data from a data table;
[0041] A determination module, configured to determine a target profile from at least one profile in the data table;
[0042] A query module is used to query the target data from the target profile according to the first query condition.
[0043] In some embodiments, the determination module is specifically used to determine at least one first simple table whose corresponding time granularity is less than or equal to a first time granularity from the at least one simple table, wherein the simple table stores time series data obtained by aggregating time series data in the data table through a preset time granularity, and the first time granularity is the time granularity of the target data; and determine the target simple table from the at least one first simple table.
[0044] In some embodiments, the determination module is specifically configured to determine the time difference between the time granularity corresponding to each of the first profiles and the first time granularity; and determine the target profile having the smallest corresponding time difference from the at least one first profile.
[0045] In some embodiments, the first query condition includes a query method for the target data, and the determination module is specifically used to determine from the at least one simple table the at least one first simple table whose corresponding time granularity is less than or equal to the first time granularity and whose corresponding aggregation method matches the query method.
[0046] In some embodiments, the query module is specifically used to change the identifier of the data table included in the query request to the identifier of the target profile; and query the target data from the target profile based on the identifier of the target profile.
[0047] In some embodiments, the query module is further configured to query the target data from the data table according to the first query condition when the target profile is not included in the at least one profile.
[0048] In some embodiments, the device also includes: an aggregation module, which is used to aggregate the multiple first time series data within the second time granularity to obtain second time series data when multiple first time series data within the second time granularity are newly added to the data table, and the second time granularity is the time granularity corresponding to the simple table; a storage module, which is used to store the second time series data in the simple table corresponding to the second time granularity.
[0049] In some embodiments, there are multiple simple tables, each of which corresponds to different time granularities. The aggregation module is specifically used to aggregate multiple third time series data in the second simple table to obtain the second time series data. The second simple table is a simple table in which the corresponding time granularity of the multiple simple tables is smaller than the second time granularity. The multiple third time series data are obtained by aggregating the multiple first time series data.
[0050] In some embodiments, the determining module is specifically configured to determine, from the at least one profile, the target profile whose marked time granularity matches the first time granularity.
[0051] In some embodiments, the simplified table comprises a materialized view.
[0052] In some embodiments, the device also includes: a conversion module, which is used to convert the data structure of the original time series data into a first data structure when receiving the original time series data sent by the data source, and the first data structure is the data structure of the time series data stored in the data table; and store the converted time series data in the data table.
[0053] In some embodiments, the conversion module is specifically used to convert the data structure of the original time series data into the first data structure according to a preset conversion rule corresponding to the data source.
[0054] According to a third aspect, a readable storage medium is provided, on which a computer program is stored. When the computer program is executed on a data query device, the data query device executes the data query method provided in the first aspect.
[0055] In a fourth aspect, a data query device is provided, comprising: a processor; a memory; and a computer program, wherein the computer program is stored in the memory, and when the computer program is executed by the processor, the data query device executes the data query method provided in the first aspect.
[0056] In a fifth aspect, a computer program product is provided, comprising: a computer program code, when the computer program code is run on a data query device, the data query device executes the data query method provided in the first aspect.
[0057] In a sixth aspect, a chip is provided, comprising: a processor for calling and running a computer program from a memory, so that a data query device equipped with the chip executes the data query method provided in the aforementioned first aspect.
[0058] It can be understood that the data query devices provided in the second and fourth aspects, the readable storage medium provided in the third aspect, the computer program product provided in the fifth aspect, and the chip provided in the sixth aspect are all used to execute the data query method provided in the first aspect. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 A schematic diagram showing an application scenario of a data query method provided in an embodiment of the present application.
[0060] Figure 2 A schematic flow chart of a data storage method provided in an embodiment of the present application is shown.
[0061] Figure 3 A flow chart of a data query method provided in an embodiment of the present application is shown.
[0062] Figure 4 A flow chart of another data query method provided in an embodiment of the present application is shown.
[0063] Figure 5 A structural schematic diagram of a data query device provided in an embodiment of the present application is shown.
[0064] Figure 6 A structural block diagram of a data query device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0065] The technical solution in the present application will be described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0066] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0067] The term "comprising" herein indicates the presence of the described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections. The terms "comprising", "including", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized. Below, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise stated, the meaning of "multiple" is two or more.
[0068] The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0069] At present, there are more and more scenarios for unified storage and management of large amounts of data. Taking battery-related businesses as an example, enterprises not only need to monitor the status of each battery after leaving the factory to provide early warning when the battery may fail, but also need to analyze the performance of the battery to improve the relevant battery technologies. Therefore, it is necessary to establish a database to store data such as voltage, current, and temperature of each battery during operation through the data table in the database, so as to monitor the status of the battery through the stored data and analyze the performance of the battery.
[0070] Battery data is usually time series data recorded in chronological order, and the time granularity of the time series data is usually milliseconds. For example, the power-consuming device (data source) can obtain and upload a time series data of the battery to the database every 1 millisecond. The time series data includes the device identification, voltage, current, temperature and other data of the battery, as well as a timestamp. The timestamp is the time when the data is generated or sent. After continuously storing the battery data for a period of time, a large amount of time series data can be obtained. It should be understood that the battery may include but is not limited to a battery pack, a battery module and a cell, and the power-consuming device may include but is not limited to electric vehicles, energy storage systems, electric ships, robots, power tools and electric aircraft.
[0071] For another example, in the Internet of Things (IOT) system, the database needs to store the operating parameters of multiple IOT devices (data sources). Similarly, the operating parameters of IOT devices are also time series data. IOT devices can upload a time series data to the database every 1 second (time granularity). Each time series data includes the device identification, operating parameters and timestamp of the IOT device. The database stores the time series data uploaded by the IOT device in the data table. After continuously storing the time series data uploaded by the IOT device for a period of time, a large amount of time series data can be obtained. It should be understood that the time granularity of the time series data can include but is not limited to 1 millisecond, 1 second, 1 minute or 1 hour.
[0072] When data is stored in a data table, the required data (usually referred to as target data) can be queried from the data table for use. During the query process, the data in the data table may need to be processed. Since the amount of data stored in the data table is usually large, a large amount of data may need to be processed during the query process. For example, if you need to query the maximum voltage value of the battery in a day, you need to determine the maximum voltage value from all the voltage values stored in the data table in a day. The voltage value of the battery is stored once every millisecond, so the battery has a large number of voltage values in a day, resulting in a large number of voltage values needing to be compared during the query process to determine the maximum voltage value, which takes a long time, resulting in low query efficiency.
[0073] In order to solve the above technical problems, the embodiment of the present application provides a data query method that can improve query efficiency. In the data query process, if the data table has at least one simplified table, a target simplified table is determined from at least one simplified table of the data table, and target data is obtained by querying from the target simplified table according to the query conditions in the query request. The data in the data table can be simplified in advance, and the simplified result is stored in the simplified table, so that a small amount of data obtained from the data table can be stored in the simplified table.
[0074] The data query method provided in the embodiment of the present application can convert a query on a data table into a query on a simplified table of the data table. Since the amount of data stored in the simplified table is less than that of the data table, when querying target data from the simplified table, the amount of data that needs to be processed during the query process can be significantly reduced, thereby shortening the query time and improving query efficiency.
[0075] The simplified table may include but is not limited to a materialized view or a data table, and other carriers that can store simplified results of a data table.
[0076] See also Figure 1 , Figure 1 FIG. 1 is a schematic diagram showing an application scenario 10 of a data query method provided in an embodiment of the present application. Figure 1 As shown, the application scenario 10 may include a query device 11 and a request device 12. The query device 11 and the request device 12 are communicatively connected with each other. The query device 11 is provided with a database for storing data. The request device 12 may send a query request to the query device to query and obtain target data from the query device 11.
[0077] like Figure 1 As shown, the query device 11 may be a server, and the request device 12 may be a computer. It should be understood that the query device 11 may also be a server cluster, a cloud platform, or other device that can store data and provide data to the outside. The request device 12 may also be a server, a mobile phone, an embedded system, a wearable device, or other device that can obtain and use data from the query device 11.
[0078] In some cases, the query device 11 and the request device 12 may also be two servers in the same server cluster, or the query device 11 and the request device 12 may also be two virtual machines in the same cloud platform, or the query device 11 and the request device 12 may also be two software modules in one server. The specific implementation of the query device and the request device may include but is not limited to the above examples.
[0079] In the data query method provided in the embodiment of the present application, the query device 11 can establish a data table in the database. During the data storage process, the query device 11 stores the acquired data in the data table and maintains and manages the data table. At the same time, the query device 11 can simplify the data table to obtain one or more simplified results, and create corresponding simplified tables based on each simplified result.
[0080] During the data query process, the requesting device 12 may send a query request to the querying device 11, and the query request may include a query condition. For the sake of distinction, the query condition in the query request is referred to as a first query condition in the embodiment of the present application.
[0081] Accordingly, after receiving the query request, the query device 11 determines the first query condition from the query request, then determines the target profile from at least one profile, and searches for target data from the target profile according to the first query condition. Afterwards, the query device 11 can send the target data obtained by the query to the request device 12 for use by the request device 12.
[0082] To facilitate understanding of the present application, the data storage process involved in the embodiments of the present application is briefly introduced below, taking the storage process of time series data as an example.
[0083] See also Figure 2 , Figure 2 The flowchart of a data storage method 100 provided in an embodiment of the present application is shown. The execution subject of the data storage method may be Figure 1 The query device 11 shown, as Figure 2 As shown, the data storage method 100 includes the following steps:
[0084] Step 110: Receive original time series data sent by a data source.
[0085] In this embodiment, a database is provided in the query device, and a corresponding data table is established in the database for a certain business to store the data generated in the corresponding business. As mentioned above, for battery-related business, the query device can create a data table, and the power-consuming device can send the original time series data (original time series data) to the query device after generating the time series data (original time series data). Correspondingly, the query device can receive the original time series data sent by the power-consuming device and store the original time series data in the data table.
[0086] In some cases, the original time series data can also be actively acquired by the query device and stored in the data table. For example, for website-related services, when the query device is located in the server cluster where the website is located, the query device can obtain information such as the number of user visits, visit time and visit content to obtain the original time series data, and store the original time series data in the data table. The above are only illustrative examples, and the method for acquiring the original time series data may include but is not limited to the above examples.
[0087] Step 120: Determine whether the data structure of the original time series data matches the first data structure.
[0088] The data structure refers to the organizational form of time series data, that is, the form of the field name, data type, data unit, etc. in the time series data. The first data structure is the data structure of the time series data stored in the data table.
[0089] In general, the data structures of time series data generated by different data sources are different. Taking battery data as an example, the field name of the voltage value in a time series data generated by an electric vehicle is "voltage", the data type is integer, and the voltage unit is volt (V), while the field name of the voltage value in a time series data generated by an energy storage system is "VOL", the data type is long integer, and the voltage unit is kilovolt (KV).
[0090] Of course, the data structures of time series data generated by different data sources may also be the same. For example, when electric vehicles and energy storage systems generate time series data according to the same data structure, the data structures of the time series data generated by the two are the same.
[0091] In some embodiments, a data table may store time series data sent by multiple data sources. When the data table stores time series data sent by different data sources, the data structure of the time series data sent by each data source may be different from the first data structure. Therefore, after receiving the original time series data sent by the data source, the query device first determines whether the data structure of the original time series data is the same as the first data structure. If so, step 140 is executed to store the original time series data in the data table. If not, step 130 is executed to convert the data structure of the original time series data into the first data structure, and then the converted time series data is stored in the data table.
[0092] Step 130: Convert the data structure of the original time series data into a first data structure.
[0093] The process of converting the data structure of the original time series data into the first data structure by the query device is also called the data structure unification process or normalization process. That is, when storing time series data with different data structures, the query device unifies the data structure of the time series data into the first data structure.
[0094] Optionally, step 130 may include:
[0095] The data structure of the original time series data is converted into a first data structure according to a preset conversion rule corresponding to the data source.
[0096] In some embodiments, for each data source, the staff can pre-set the corresponding conversion rules (i.e., preset conversion rules) in the query device, and the preset conversion rules can set the conversion target and conversion method, etc. After receiving the original time series data sent by a data source, when the query device determines that the data structure of the original time series data does not match the first data structure, it can obtain the preset conversion rules corresponding to the data source, and then convert the data structure of the original time series data according to the preset conversion rules.
[0097] For example, the unit of the voltage value in the time series data stored in the data table is KV, and the data type of the voltage value is long integer. For electric vehicles, the preset conversion rule can set the conversion object to the unit and data type of the voltage value, and the conversion method is to convert the unit from V to KV, and convert the data type from integer to long integer. After receiving the original time series data sent by the electric vehicle, the query device can obtain the preset conversion rule corresponding to the electric vehicle, and then convert the voltage unit in the original time series data from volts to kilovolts, and convert the data type from integer to long integer according to the preset conversion rule.
[0098] The above are merely illustrative examples, and specific methods for converting data structures may include but are not limited to the above examples.
[0099] In an embodiment of the present application, corresponding conversion rules are set for the data source. When time series data sent by the data source is received, the time series data is converted according to the conversion rules corresponding to the data source, which can improve the conversion efficiency of the data structure and thus improve the data storage efficiency.
[0100] Step 140: Store the converted time series data in a data table.
[0101] In this embodiment, when the data structure of the received original time series data matches the first data structure, the query device directly stores the original time series data in the data table. Similarly, after converting the data structure of the received original time series data into the first data structure, the converted time series data can be stored in the data table.
[0102] It should be noted that, for time series data, the query device can store each acquired time series data in a data table in chronological order according to the timestamps included in the time series data, so as to maintain and manage the time series data according to the timestamps.
[0103] In the embodiment of the present application, after receiving the original time series data sent by the data source, the data structure of the original time series data is converted, and the converted time series data is stored in the data table, so that the data structure of the time series data can be unified. In this way, it is convenient to manage the time series data in the data table and improve the data management and query efficiency.
[0104] Step 150: Aggregate the time series data in the data table using a preset time granularity to obtain an aggregation result.
[0105] Step 160: Create a simple table corresponding to each aggregation result.
[0106] In some embodiments, the time series data in the data table may be simplified by data aggregation to obtain a simplified result. For example, the time series data in the data table may be aggregated by one or more different time granularities to obtain an aggregated result, and the aggregated result is the simplified result. The aggregated result obtained when the time series data is aggregated is new time series data, and the aggregated result corresponding to each time granularity is stored separately, so as to obtain one or more simplified tables of the data table.
[0107] Exemplarily, for battery-related time series data, the first time granularity can be set to 1 minute, the second time granularity can be set to 1 hour, and the third time granularity can be set to 1 day. At the same time, the aggregation method corresponding to the three time granularities can be set to calculate the average value. For the first time granularity, the query device can group all the voltage values of each battery stored in the data table in chronological order according to the timestamp in each time series data, and divide the voltage values within each minute into one group, and all the voltage values can be divided into multiple continuous groups. Afterwards, the query device calculates (i.e., aggregates) the average value of all voltage values in each group to obtain the average voltage value of the battery in each minute. Similarly, for current values and temperature values other than voltage values, the average current value and average temperature value of the battery in each minute can also be calculated and determined.
[0108] In this way, the aggregation result corresponding to the first time granularity includes the average voltage value, average current value, and average temperature value of the battery in each minute. Next, a first materialized view (i.e., a simplified table) corresponding to the first time granularity can be created, and the aggregation result corresponding to the first time granularity can be stored through the first materialized view.
[0109] During data aggregation, you can set the timestamp of each aggregated time series data. Taking the first time granularity as an example, after calculating the average voltage value, average current value, and average temperature value within 13:24 on March 14, you can set a timestamp of 13:24 on March 14. Combining the average voltage value, average current value, average temperature value within 13:24 on March 14 with the timestamp, you can get a time series data with a timestamp of 13:24 on March 14.
[0110] Similarly, the second materialized view corresponding to the second time granularity can be obtained, and the second materialized view stores the average voltage value, average current value, and average temperature value of the battery per hour. Also, the third materialized view corresponding to the third time granularity can be obtained, and the third materialized view stores the average voltage value, average current value, and average temperature value of the battery per day.
[0111] It can be understood that the first time granularity is to aggregate the time series data in the data table at a time granularity of 1 minute, so the time granularity of the time series data stored in the first materialized view is 1 minute. Similarly, the second query condition is to aggregate the time series data in the data table at a time granularity of 1 hour, and the time granularity of the time series data stored in the second materialized view is 1 hour; the third query condition is to aggregate the time series data in the data table at a time granularity of 1 day, and the time granularity of the time series data stored in the third materialized view is 1 day.
[0112] The data aggregation process is to calculate the average value, maximum value, minimum value, summation result, variance and standard deviation, etc. The aggregation method may include but is not limited to calculating the average value, maximum value, minimum value, summation result, variance and standard deviation, etc.
[0113] Optionally, in the process of creating the above three materialized views, each materialized view can be created in order from small to large time granularity, and when creating a subsequent materialized view, the time series data in the previously created materialized view can be aggregated to obtain an aggregated result, so as to create a subsequent materialized view based on the aggregated result, which can improve the efficiency of creating the simple table.
[0114] For example, after creating the first materialized view with a time granularity of 1 minute, you can aggregate the time series data in the first materialized view according to the second time granularity to obtain the aggregated result, that is, calculate the average value of all voltage values in the first materialized view per hour to obtain the average voltage value, calculate the average value of all current values per hour to obtain the average current value, and calculate the average value of all temperature values per hour to obtain the average temperature value, so as to obtain the aggregated result corresponding to the second time granularity, and then create the second materialized view corresponding to the time granularity of 1 hour based on the obtained aggregated result. Similarly, you can aggregate the time series data in the second materialized view according to the third time granularity to obtain the aggregated result, and then create the third materialized view based on the aggregated result.
[0115] As an optional implementation, when creating a simple table, the query device can mark the simple table according to the time granularity to distinguish the simple tables corresponding to different time granularities, and then determine the time granularity corresponding to the simple table according to the mark of the simple table. For example, for the first time granularity mentioned above, the identifier of the first materialized view can be set to consist of the identifier of the data table (which can be the table name of the data table) and the time granularity, specifically: sheet1_1min, where sheet1 is the table name of the data table, and lmin indicates that the time granularity corresponding to the first materialized view is 1 minute.
[0116] Similarly, the identifier of the second materialized view can be set to sheet1_1h, where 1h means the time granularity of the second materialized view is 1 hour; and the identifier of the third materialized view can be set to sheet1_1d, where 1d means the time granularity of the third materialized view is 1 day. In this way, for the data table sheet1, the materialized view sheet1_1min, the materialized view sheet1_1h, and the materialized view sheet1_1d can be obtained according to the three time granularities mentioned above.
[0117] In another optional implementation, during the process of creating a profile, the query device may set attribute information for each profile, and record the time granularity corresponding to the profile in the attribute information, so as to mark the profile by the time granularity in the attribute information. It should be understood that when marking the profile, the profile may be marked by information such as the time granularity and / or aggregation method, and the identifier of the data table according to requirements, and the marking method of the profile may include but is not limited to the above examples.
[0118] It should be understood that the data aggregation process is also a data query process. Taking the first time granularity as an example, in the aggregation process, multiple time series data within each minute stored in the data table can be queried, and then the average value of the voltage values included in the multiple time series data within each minute is calculated to obtain the average voltage value, the average value of the current values included in the multiple time series data within each minute is calculated to obtain the average current value, and the average value of the temperature values included in the multiple time series data within each minute is calculated to obtain the average temperature value.
[0119] Optionally, the query device can maintain and manage the data table through structured query language (SQL). In the aggregation process of the data table, the query device can construct the query scope (aggregation scope) and query method (aggregation method) in the query condition (i.e., aggregation condition) through SQL statements, and execute the SQL statements to query the data table. For example, in the process of creating the materialized view sheet1_1min, the query device can construct a set of SQL statements including a SELECT clause, a FROM clause, and a GROUP BY clause.
[0120] Among them, the parameters in the SELECT clause include fields in the time series data (such as voltage values) and AVG aggregation functions. The fields are used to specify the query time range, and the AVG aggregation function is used to specify that the query method is to calculate the average value; the parameters in the FROM clause include the table name of the data table, which is used to specify the data table to be queried; the parameters in the GROUP BY clause include the time granularity (1 minute), which is used to specify that the query time range is every minute. The query device can execute the above SQL statement to query the data table to obtain the query result (i.e., the aggregate result) corresponding to the first time granularity. It should be understood that the method of querying from the data table to obtain the query result may include but is not limited to the above examples.
[0121] In the embodiment of the present application, in the process of creating a simplified table, the time series data in the data table can be aggregated according to the preset time granularity, and the simplified table can be created according to the aggregation result. In this way, the time series data stored in the data table can be compressed, so that a small amount of time series data corresponding to the data table can be stored in the simplified table. In this way, when the target data is obtained from the simplified table during the data query process, the amount of data that needs to be processed during the query process can be reduced, thereby improving the query efficiency.
[0122] When the time series data in the data table is updated, the query device can update the data in each simple table accordingly.
[0123] Optionally, in the process of storing time series data, when multiple first time series data within the second time granularity are added to the data table, the multiple first time series data are aggregated to obtain second time series data, and the second time granularity is the time granularity corresponding to the simple table; the second time series data is stored in the simple table corresponding to the second time granularity. The first time series data is the time series data newly added to the data table, and the second time series data is the time series data obtained by aggregating multiple first time series data.
[0124] For example, after the query device receives multiple time series data (first time series data) within a new 1 minute (second time granularity) sent by the electrical equipment, the voltage values in the multiple time series data within the new 1 minute can be aggregated to obtain the average voltage value, the current values in the multiple time series data within the new 1 minute can be aggregated to obtain the average current value, and the temperature values in the multiple time series data within the new 1 minute can be aggregated to obtain the average temperature value. The average voltage value, average current value and average temperature value obtained by combining them, as well as the corresponding timestamp, can be used to obtain a new time series data (i.e., the second time series data), and then the second time series data is added to the materialized view sheet1_1min, and the second time series data includes the new average voltage value, average current value and average temperature value within 1 minute.
[0125] Similarly, when the query device receives the new time series data within 1 hour (second time granularity) sent by the electrical equipment, the average voltage value, average current value and average temperature value within the new 1 hour can be obtained, and the average voltage value, average current value, average temperature value, and the corresponding timestamp are combined to obtain the second time series data, and then the second time series data is added to the materialized view sheet1_1h, which includes the new average voltage value, average current value and average temperature value within the 1 hour.
[0126] Similarly, when the query device receives the new time series data within 1 day (second time granularity) sent by the electrical equipment, the average voltage value, average current value and average temperature value within the new day can be obtained, and the average voltage value, average current value, average temperature value, and the corresponding timestamp are combined to obtain the second time series data, and then the second time series data is added to the materialized view sheet1_1d, which includes the new average voltage value, average current value and average temperature value within the new day.
[0127] In an embodiment of the present application, after storing new time series data in the data table, the time series data in the simplified table is synchronously updated, so that the time series data in each simplified table can be synchronized with the time series data in the data table, thereby increasing the probability of obtaining the target data from the simplified table and further improving the data query efficiency.
[0128] Optionally, the step of aggregating a plurality of first time series data to obtain second time series data may include:
[0129] The second time series data are obtained by aggregating multiple third time series data in the second simple table, the second simple table is a simple table in which the corresponding time granularity is smaller than the second time granularity among the multiple simple tables, and the multiple third time series data are obtained by aggregating multiple first time series data.
[0130] For example, if the second time granularity is 1 minute, the second simple table with a corresponding time granularity smaller than the second time granularity in the multiple simple tables is the materialized view sheet1_1min. After adding multiple first time series data within 1 hour (the second time granularity is equal to 60 minutes) to the data table, firstly, according to the time granularity of 1 minute, the multiple first time series data within each minute are respectively aggregated to obtain 60 third time series data, and the 60 third time series data are stored in the materialized view sheet1_1min.
[0131] In this way, 60 time series data (i.e., multiple third time series data) are added to the materialized view sheet1_1min. At this time, the 60 time series data added to the materialized view sheet1_1min can be aggregated at a time granularity of 1 hour to obtain one time series data, which is the second time series data corresponding to the materialized view sheet1_1h. Then, the aggregated second time series data is stored in the materialized view sheet1_1h.
[0132] Similarly, for the materialized view sheet1_1d, if multiple first time series data within one day are added to the data table, the multiple third time series data within one day added to the materialized view sheet1_1min can be aggregated to obtain the second time series data. Alternatively, the multiple third time series data within one day added to the materialized view sheet1_1h can be aggregated to obtain the second time series data.
[0133] In an embodiment of the present application, in the process of updating the time series data in the simple table, the newly added time series data in the simple table corresponding to the smaller time granularity is aggregated according to the size of the time granularity, and the aggregation result is stored in the simple table corresponding to the larger time granularity. This can reduce the amount of data that needs to be processed during the aggregation process, thereby improving the updating efficiency of the simple table.
[0134] It should be understood that one or more data tables can be created in the query device, and each data table can store data in different businesses respectively. Of course, data tables can also be used to store non-time series data. For example, for the sales business of a product, a data table can be established in the database, and the customer data of each customer can be stored in the data table. The customer data may include information such as the customer's identity, gender, age, address, telephone number, and income. In this case, the customer data can be generated by a computer at the sales end and uploaded to the query device, or the customer data can be manually imported into the query device by the staff.
[0135] The above are merely illustrative examples, and specific methods for simplifying the data in a data table may include but are not limited to the above examples.
[0136] See also Figure 3 , Figure 3 FIG. 2 is a flow chart of a data query method 200 provided in an embodiment of the present application. The execution subject of the data query method 200 may be Figure 1 The query device 11 shown. Figure 3 As shown, the method may include the following steps:
[0137] Step 210: Receive a query request including a first query condition, where the query request is used to request to obtain target data from a data table.
[0138] Step 220: Determine a target profile from at least one profile in the data table.
[0139] The query request can be made by Figure 1 The request device shown sends the query request to the query device, and the query request is used to request to obtain the target data from the data table.
[0140] Optionally, when determining the target profile from at least one profile in the data table, a profile may be randomly selected from the at least one profile as the target profile. Alternatively, the target profile may be determined from the at least one profile according to the simplification mode corresponding to the profile and the first query condition.
[0141] Exemplarily, step 220 may include:
[0142] Determine at least one first simplified table from at least one simplified table, the corresponding time granularity being less than or equal to the first time granularity, wherein the simplified table stores time series data obtained by aggregating time series data in the data table by a preset time granularity, and the first time granularity is the time granularity of the target data;
[0143] A target profile is determined from the at least one first profile.
[0144] In combination with the above example, when the simplified table stores time series data obtained by aggregating time series data in the data table through a preset time granularity, at least one first simplified table whose corresponding time granularity is less than or equal to the first time granularity can be determined from at least one simplified table according to the first time granularity of the target data to be queried by the first query request, and then one of the first simplified tables is determined as the target simplified table.
[0145] Exemplarily, after receiving the query request, the query device may parse the query request and determine the time granularity of the target data according to the first query condition in the query request. For example, when the first query condition specifies that the maximum voltage value (target data) stored in the data table at 13:00 on April 14 needs to be queried, the first time granularity can be determined to be 1 hour according to the query time 13:00 on April 14. For another example, when the first query condition specifies that multiple time series data (target data) stored in the data table at 13:12 on April 14 to 13:15 on April 14 needs to be queried, the first time granularity can be determined to be 1 minute.
[0146] For another example, the time information included in the first query condition includes the first time point 13:24 and the second time point 13:26. The first time point 13:24 and the second time point 13:26 are used to specify the query of the time series data from 13:24 to 13:26. The first time point 13:24 and the second time point 13:26 use minutes as the minimum time unit, so the time granularity of the first time point and the second time point is 1 minute, and the time granularity of the target data can be determined to be 1 minute. It should be understood that the method for determining the first time granularity may include but is not limited to the above examples.
[0147] After determining the first time granularity, at least one first simple table whose corresponding time granularity is less than or equal to the first time granularity may be determined from at least one data table. For example, when the first time granularity is 2 hours, materialized view sheet1_1min and materialized view sheet1_1h may be determined as the first simple table from materialized view sheet1_1min, materialized view sheet1_1h, and materialized view sheet1_1d; when the first time granularity is 10 minutes, materialized view sheet1_1min may be determined as the first simple table from materialized view sheet1_1min, materialized view sheet1_1h, and materialized view sheet1_1d. Subsequently, a first simple table may be randomly selected from at least one materialized view as a target simple table.
[0148] In an embodiment of the present application, when time series data is stored in a data table, and an aggregation result obtained by aggregating the time series data in the data table at a preset time granularity is stored in a simplified table, during a data query process, a simplified table with a time granularity less than or equal to the first time granularity can be determined from at least one simplified table as a target simplified table, and then the target data is obtained by querying from the target simplified table. Since the amount of time series data stored in the simplified table is much less than the amount of time series data stored in the data table, when querying the target data from the target simplified table, the amount of data that needs to be processed during the query process can be significantly reduced, thereby improving the efficiency of data query.
[0149] Optionally, the step of determining a target profile from at least one first profile may include:
[0150] Determine a time difference between a time granularity corresponding to each first profile and the first time granularity;
[0151] A target profile with the smallest corresponding time difference is determined from the at least one first profile.
[0152] Exemplarily, when the first time granularity is 2 hours, it can be determined that the first simple table includes materialized view sheet1_1min and materialized view sheet1_1h. In the process of determining the target simple table, first determine the time difference between the first time granularity and the time granularity of 1 minute corresponding to materialized view sheet1_1min, and determine the time difference between the first time granularity and the time granularity of 1 hour corresponding to materialized view sheet1_1h. Then, materialized view sheet1_1h with the smallest corresponding time difference can be determined from materialized view sheet1_1min and materialized view sheet1_1h as the target simple table. It should be understood that when at least one simple table includes only one first simple table, the first simple table is directly used as the target simple table.
[0153] In the embodiment of the present application, in the process of determining the target profile from at least one profile, the first profile with the smallest time difference with the first time granularity is determined from the at least one profile as the target profile. Since the closer the time granularity, the smaller the amount of data that needs to be processed when querying and obtaining target data from the target profile, when the first profile with the smallest corresponding time difference is selected as the target profile, the amount of data that needs to be processed during the data query process can be reduced to the greatest extent, thereby maximizing the data query efficiency.
[0154] For example, when the first simple table includes materialized view sheet1_1min and materialized view sheet1_1h, if the target data to be queried is the average voltage value within the last day, when querying the target data from materialized view sheet1_1min, the average voltage value included in 1440 (i.e., 1440 minutes) time series data needs to be calculated. When querying the average voltage value within the last day from materialized view sheet1_1h, the average voltage value included in 24 (i.e., 24 hours) time series data only needs to be calculated.
[0155] It should be understood that when non-time series data is stored in a data table, and the simplified table of the data table is obtained by simplifying in other ways, the target simplified table can be adaptively determined from at least one simplified table of the data table according to the simplified method of the data table and the first query condition. The above is only an illustrative example, and the method of determining the target simplified table from at least one simplified table of the data table may include but is not limited to the above example.
[0156] Step 230: Query target data from the target profile according to the first query condition.
[0157] In this embodiment, after determining the target profile, the query device can obtain the target data from the target profile according to the first query condition. For example, when the first query condition specifies that the target data to be queried is the average voltage value within the last 3 hours, and the target profile is the materialized view sheet1_1min, the time series data of each minute within the last 3 hours can be obtained from the materialized view sheet1_1min, and then the voltage value is extracted from the time series data of each minute, and the average value of all the extracted voltage values is calculated, so that the target data can be obtained.
[0158] Similarly, if the first query condition specifies that the target data to be queried is the average voltage value within the last three days, and the target simple table is the materialized view sheet1_1d, the time series data within the last three days can be obtained from the materialized view sheet1_1d, and then the voltage value is extracted from the time series data of each day, and the average value of all the extracted voltage values is calculated, so as to obtain the target data.
[0159] In the embodiment of the present application, during the data query process, a query request including a first query condition is received, a target summary table is determined from at least one summary table of the data table, and then target data is queried from the target summary table according to the first query condition. During the data query process, the query on the data table can be converted into a query on the summary table of the data table. Since the amount of data stored in the summary table is less than that of the data table, when querying the target data from the summary table, the amount of data that needs to be processed during the query process can be significantly reduced, thereby shortening the query time and improving the query efficiency.
[0160] Optionally, step 220 may include:
[0161] A target profile having a marked time granularity matching the first time granularity is determined from the at least one profile.
[0162] The marked time granularity matches the first time granularity, which means that the marked time granularity is less than or equal to the first time granularity.
[0163] For example, the data table sheet1 has three simple tables, namely, materialized view sheet1_1min, materialized view sheet1_1h, and materialized view sheet1_1d. According to the identifier of each materialized view, it can be determined that the time granularity marked by materialized view sheet1_1min is 1 minute, the time granularity marked by materialized view sheet1_1h is 1 hour, and the time granularity marked by materialized view sheet1_1d is 1 day. Alternatively, after setting the corresponding time granularity in the attribute information of each materialized view, the time granularity corresponding to each materialized view can be obtained from the attribute information of materialized view sheet1_1min, materialized view sheet1_1h, and materialized view sheet1_1d.
[0164] After determining the time granularity marked by each materialized view, a simplified table whose marked time granularity is less than or equal to the first time granularity may be determined from at least one materialized view as a target simplified table.
[0165] In an embodiment of the present application, a profile is marked by a time granularity corresponding to the profile. In the process of determining a target profile, the target profile is determined from at least one profile according to the time granularity marked by the profile. The target profile can be quickly determined from at least one profile, thereby improving the efficiency of determining the target profile, and further improving the efficiency of data query.
[0166] Optionally, the simplified table of the data table may include a materialized view. Of course, the simplified table of the data table may also be a data table or other carriers that can be used to store query results.
[0167] In the embodiment of the present application, when the simplified table of the data table is a materialized view, it is convenient to update the data in the simplified table when the data in the data table changes, so that the simplified table can be maintained and managed in a timely manner.
[0168] Optionally, the first query condition includes a query mode of the target data, and the step of determining at least one first profile whose corresponding time granularity is less than or equal to the first time granularity from at least one profile may include:
[0169] At least one first profile whose corresponding time granularity is less than or equal to the first time granularity and whose corresponding aggregation mode matches the query mode is determined from at least one profile.
[0170] In some embodiments, when the first query condition includes a query method for target data, the target profile may be a profile whose corresponding aggregation method in at least one first profile matches the query method for target data and whose corresponding time granularity matches the first time granularity. For example, if the first time granularity is 1 hour, and the first query condition includes an aggregation function that specifies that the query method for target data is to calculate an average value. After determining at least one first profile whose corresponding time granularity is less than or equal to the first time granularity, the query device may determine from the at least one first profile that the corresponding aggregation method is to calculate an average value as the target profile.
[0171] Optionally, the aggregation mode corresponding to each profile may be marked, for example, the aggregation mode corresponding to the profile may be marked in the attribute information of each profile. When determining the target profile from at least one first profile, a first profile whose marked aggregation mode matches the query mode in the first query condition and whose marked time granularity matches the first time granularity may be determined as the target profile from the at least one first profile.
[0172] In the embodiment of the present application, during the data query process, the target profile can be determined according to the time granularity of the target data and the query method specified by the first query condition, so that a more accurate target profile can be determined, thereby improving the query efficiency.
[0173] See also Figure 4 , Figure 4 FIG. 3 is a flow chart of another data query method 300 provided in an embodiment of the present application. The execution subject of the data query method 300 may be Figure 1 The query device 11 shown. Figure 4 As shown, the method may include the following steps:
[0174] Step 310: Receive a query request.
[0175] Step 320: parse the query request.
[0176] Step 330: Generate a query statement.
[0177] In this embodiment, the requesting device can send a query request to the querying device through an interface call. After receiving the query request, the querying device can first parse the query request to obtain a parsing result, and then generate a query statement based on the parsing result to determine the data table requested to be queried and the first query condition based on the query statement.
[0178] Exemplarily, the requesting device can call a representational state transfer (REST) interface to send a query request to the querying device, wherein the query request includes a parameterized SQL statement, and the parameterized SQL statement includes parameters such as the table name of the data table, time information for specifying the query time range, and aggregation functions for specifying the query method, but is not limited to this.
[0179] Accordingly, after receiving the query request, the query device may parse the query request to obtain a parameterized SQL statement (i.e., a parsing result) included in the query request. The parameterized SQL statement is usually included in the query request in the form of a string. The query device may deserialize the string obtained by parsing to convert the parameterized SQL statement into an entity object with multiple attributes. Afterwards, the query device may generate a standard SQL statement (i.e., a query statement) based on the multiple attributes of the entity object. The SQL statement includes, but is not limited to, a GROUP BY clause, a FROM clause, and a SELECT clause.
[0180] Step 340: Generate an abstract syntax tree according to the query statement.
[0181] Step 350: Determine whether the data table has at least one summary table.
[0182] In this embodiment, after obtaining the standard SQL statement, the query device can perform lexical analysis and grammatical analysis on the SQL statement in sequence through a parsing tool to convert the SQL statement into an abstract syntax tree (AST), which includes information such as table name, field, and time information. After that, the query device can obtain the table name of the data table from the AST. After obtaining the table name of the data table, the query device can determine whether the data table corresponding to the table name in the database has at least one simplified table.
[0183] Exemplarily, after obtaining the table name of the data table, the query device can query whether there is a simplified table in the database whose identifier includes the table name. If there is, it is determined that the data table has a simplified table, otherwise it is determined that the data table has no simplified table. As mentioned above, in the data storage process, three simplified tables of the data table sheet1 can be generated respectively, namely, materialized view sheet1_1min, materialized view sheet1_1h and materialized view sheet1_1d, and the identifier of each materialized view consists of the table name sheet1 and the corresponding time granularity. In the data query process, after obtaining the table name sheet1, the query device can determine that a data table with the table name sheet1 is stored in the database. At the same time, since the identifiers of the materialized view sheet1_1min, the materialized view sheet1_1h and the materialized view sheet1_1d all include the table name sheet1, it can be determined that there are three simplified tables of the data table sheet1 in the database. On the contrary, if the database does not include a materialized view with sheet1 in the identifier, it is determined that the data table sheet1 has no simplified table.
[0184] The query device executes step 360 after determining that the data table has at least one summary table, and executes step 380 after determining that the data table has no summary table.
[0185] Step 360: Determine whether at least one profile of the data table includes the target profile.
[0186] In this embodiment, after determining that the data table has at least one profile, the query device first determines whether the at least one profile of the data table includes the target profile, and if it is determined that the at least one profile includes the target profile, it executes step 370, and if it is determined that the at least one profile does not include the target profile, it executes step 380. The method of determining whether the at least one profile includes the target profile can refer to the above example, and this embodiment will not be described in detail here.
[0187] Step 370: Get target data from the target profile.
[0188] In some embodiments, when acquiring target data from a data table, the query device may change the identifier of the data table included in the query request to the identifier of the target profile; and then query the target data from the target profile based on the identifier of the target profile.
[0189] For example, the query device may rewrite the table name of the data table included in the generated AST into the identifier of the target profile. Then, a standard SQL statement may be obtained based on the rewritten AST conversion. Afterwards, the query device may submit the converted SQL statement to the execution engine of the database so that the execution engine executes the SQL statement (i.e., responds to the modified query request) and obtains the target data from the target profile.
[0190] For another example, after generating the standard SQL statement in step 330, the query device may back up the SQL statement. After determining the target profile from at least one profile, the table name of the data table included in the pre-backed SQL statement may be rewritten as the identifier of the target profile. Afterwards, the query device may submit the rewritten SQL statement to the execution engine of the database, so that the execution engine executes the SQL statement and obtains the target data from the target profile.
[0191] Alternatively, after receiving the query request, the query device may back up the query request. After determining the target profile from at least one profile, the query device may parse the pre-backed query request and generate a standard SQL statement, and then rewrite the table name of the data table included in the SQL statement into the identifier of the target profile. Afterwards, the query device may submit the rewritten SQL statement to the execution engine of the database, so that the execution engine executes the SQL statement and obtains the target data from the target profile.
[0192] The above are merely illustrative examples, and specific methods for obtaining target data from a data table may include but are not limited to the above examples.
[0193] In the embodiment of the present application, by rewriting the identifier of the data table included in the query request, the query on the data table is rewritten as a query on the target profile, which can facilitate accurate positioning of the target profile and obtain target data from the target profile. In this way, after determining the target profile, the target profile can be directly accessed to obtain the target data, thereby simplifying the query process and improving the query efficiency. At the same time, the requesting device does not need to know the profile information of the data table, and can directly access the data table. If the data table has a profile, the profile is automatically accessed, which can simplify the data query process of the requesting device.
[0194] Step 380: Get target data from the data table.
[0195] In the embodiment of the present application, when it is determined that the data table has no simplified table or at least one simplified table in the data table does not include the target simplified table, the query device can obtain the target data from the data table. For example, in the process of obtaining the target data from the data table, the query device can convert the AST into a standard SQL statement, and then submit the SQL to the execution engine, so that the execution engine executes the SQL statement to query and obtain the target data from the data table.
[0196] For another example, after generating the standard SQL statement in step 330, the query device may back up the SQL statement. After determining that the data table has no profile or at least one profile does not include the target profile, the query device may submit the pre-backed-up SQL statement to the execution engine of the database, so that the execution engine executes the SQL statement and queries and obtains the target data from the data table.
[0197] Alternatively, after receiving the query request, the query device may back up the query request. After determining that the data table has no summary table or at least one summary table does not include the target summary table, the query device may parse the pre-backed query request and generate a standard SQL statement, and then submit the SQL statement to the execution engine of the database so that the execution engine executes the SQL statement to query and obtain the target data from the data table.
[0198] In an embodiment of the present application, when a data table has no simplified table or at least one simplified table in the data table has no target simplified table, the data table continues to be accessed to obtain target data from the data table. The target data can be queried and obtained when there is no simplified table or no target simplified table, thereby improving the reliability of data query.
[0199] Step 390: Return the target data to the requesting device.
[0200] In the embodiment of the present application, after the query device obtains the target data from the target profile or data table, it can send the target data to the request device to complete the response to the query request.
[0201] Combination of the above Figures 1 to 4 The data query method provided by the embodiment of the present application is described in detail. Figure 5 , Figure 6 Describe the data query device provided by the embodiment of the present application. It should be understood that Figure 5 , Figure 6 The control device shown can achieve Figure 3 or Figure 4 One or more steps in the method flow shown are not described in detail here to avoid repetition.
[0202] See also Figure 5 , Figure 5FIG. 1 shows a schematic diagram of the structure of a data query device provided in an embodiment of the present application. Figure 5 As shown, the data query device 50 includes a receiving module 51 , a determining module 52 and a query module 53 .
[0203] A receiving module 51 is used to receive a query request including a first query condition, wherein the query request is used to request to query target data from a data table;
[0204] A determination module 52, configured to determine a target profile from at least one profile in the data table;
[0205] The query module 53 is used to query the target data from the target profile according to the first query condition.
[0206] In some embodiments, the determination module 52 is specifically used to determine at least one first simple table whose corresponding time granularity is less than or equal to a first time granularity from the at least one simple table, wherein the simple table stores time series data obtained by aggregating time series data in the data table through a preset time granularity, and the first time granularity is the time granularity of the target data; and determine the target simple table from the at least one first simple table.
[0207] In some embodiments, the determination module 52 is specifically configured to determine the time difference between the time granularity corresponding to each of the first profiles and the first time granularity; and determine the target profile having the smallest corresponding time difference from the at least one first profile.
[0208] In some embodiments, the first query condition includes a query method for the target data, and the determination module 52 is specifically used to determine from the at least one simple table the at least one first simple table whose corresponding time granularity is less than or equal to the first time granularity and whose corresponding aggregation method matches the query method.
[0209] In some embodiments, the query module 53 is specifically used to change the identifier of the data table included in the query request to the identifier of the target profile; and query the target data from the target profile based on the identifier of the target profile.
[0210] In some embodiments, the query module 53 is further configured to query the target data from the data table according to the first query condition when the target profile is not included in the at least one profile.
[0211] In some embodiments, the device also includes: an aggregation module, which is used to aggregate the multiple first time series data within the second time granularity to obtain second time series data when multiple first time series data within the second time granularity are newly added to the data table, and the second time granularity is the time granularity corresponding to the simple table; a storage module, which is used to store the second time series data in the simple table corresponding to the second time granularity.
[0212] In some embodiments, there are multiple simple tables, each of which corresponds to different time granularities. The aggregation module is specifically used to aggregate multiple third time series data in the second simple table to obtain the second time series data. The second simple table is a simple table in which the corresponding time granularity of the multiple simple tables is smaller than the second time granularity. The multiple third time series data are obtained by aggregating the multiple first time series data.
[0213] In some embodiments, the determining module 52 is specifically configured to determine, from the at least one profile, the target profile whose marked time granularity matches the first time granularity.
[0214] In some embodiments, the simplified table comprises a materialized view.
[0215] In some embodiments, the device also includes: a conversion module, which is used to convert the data structure of the original time series data into a first data structure when receiving the original time series data sent by the data source, and the first data structure is the data structure of the time series data stored in the data table; and store the converted time series data in the data table.
[0216] In some embodiments, the conversion module is specifically used to convert the data structure of the original time series data into the first data structure according to a preset conversion rule corresponding to the data source.
[0217] Figure 6 FIG. 1 shows a structural block diagram of a data query device provided by an embodiment of the present application. Figure 6 As shown, the data query device 60 includes a processor 61 and a memory 62 , and the above-mentioned components can be connected via one or more buses 64 .
[0218] The data query device 60 further includes a computer program 63, which is stored in the memory 62. When the computer program 63 is executed by the processor 61, the data query device 60 executes the above Figures 2 to 4 All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding physical device, and will not be repeated here.
[0219] An embodiment of the present application also provides a readable storage medium, which includes a computer program. When the computer program is executed on a computer, the computer executes the method provided by the above method embodiment.
[0220] An embodiment of the present application also provides a computer program product comprising instructions, and when the computer program product is run on a computer, the computer is enabled to execute the method provided by the above method embodiment.
[0221] An embodiment of the present application also provides a chip system, including a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that a data query device equipped with the chip system executes the method provided in the above method embodiment.
[0222] Among them, the chip system may include an input circuit or interface for sending information or data, and an output circuit or interface for receiving information or data.
[0223] It should be understood that in the embodiments of the present application, the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0224] It should also be understood that the memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0225] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0226] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0227] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0228] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0229] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0230] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0231] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data query method, characterized in that: include: Receiving a query request including a first query condition, wherein the query request is used to request to query target data from a data table; determining a target profile from at least one profile of the data table; The target data is queried from the target profile according to the first query condition.
2. The method according to claim 1, characterized in that The determining of the target profile from at least one profile of the data table comprises: Determine, from the at least one simple table, at least one first simple table whose corresponding time granularity is less than or equal to a first time granularity, wherein the simple table stores time series data obtained by aggregating time series data in the data table by a preset time granularity, and the first time granularity is the time granularity of the target data; The target profile is determined from the at least one first profile.
3. The method according to claim 2, characterized in that The determining the target profile from the at least one first profile comprises: Determine a time difference between a time granularity corresponding to each of the first profiles and the first time granularity; The target profile corresponding to the smallest time difference is determined from the at least one first profile.
4. The method according to claim 2 or 3, characterized in that The first query condition includes a query method for the target data, and the determining, from the at least one simple table, at least one first simple table whose corresponding time granularity is less than or equal to the first time granularity includes: At least one first profile whose corresponding time granularity is less than or equal to the first time granularity and whose corresponding aggregation mode matches the query mode is determined from the at least one profile.
5. The method according to any one of claims 1 to 4, characterized in that The querying the target data from the target profile according to the first query condition comprises: Changing the identifier of the data table included in the query request to the identifier of the target profile; Based on the identifier of the target profile, the target data is queried from the target profile.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: In the case that the target profile is not included in the at least one profile, the target data is obtained by querying from the data table according to the first query condition.
7. The method according to any one of claims 2 to 6, characterized in that The method further comprises: When a plurality of first time series data in a second time granularity are newly added to the data table, the plurality of first time series data are aggregated to obtain second time series data, where the second time granularity is the time granularity corresponding to the brief table; The second time series data is stored in the simple table corresponding to the second time granularity.
8. The method according to claim 7, characterized in that There are multiple brief tables, each of which corresponds to a different number of time granularities. The aggregating the multiple first time series data to obtain the second time series data includes: The second time series data is obtained by aggregating multiple third time series data in the second simple table, the second simple table is a simple table in which the corresponding time granularity of the multiple simple tables is smaller than the second time granularity, and the multiple third time series data are obtained by aggregating the multiple first time series data.
9. The method according to any one of claims 2 to 8, characterized in that The method further includes: determining a target profile from at least one profile of the data table, comprising: The target profile having a marked time granularity matching the first time granularity is determined from the at least one profile.
10. The method according to any one of claims 1 to 9, characterized in that The simplified table includes a materialized view.
11. The method according to any one of claims 1 to 10, characterized in that The method further comprises: When receiving the original time series data sent by the data source, converting the data structure of the original time series data into a first data structure, where the first data structure is the data structure of the time series data stored in the data table; The converted time series data is stored in the data table.
12. The method according to claim 11, characterized in that The converting the data structure of the original time series data into a first data structure comprises: The data structure of the original time series data is converted into the first data structure according to a preset conversion rule corresponding to the data source.
13. A data query device, characterized in that: include: A receiving module, used for receiving a query request including a first query condition, wherein the query request is used for requesting to query target data from a data table; A determination module, configured to determine a target profile from at least one profile in the data table; A query module is used to query the target data from the target profile according to the first query condition.
14. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program runs on the data query device, the data query device executes the method according to any one of claims 1 to 12.