Data aggregation query method and device, electronic equipment and computer readable storage medium
By generating and executing multi-dimensional data aggregation query statements on the query server, the problem of high backend database load in multi-dimensional data queries is solved, achieving efficient and flexible data aggregation queries, reducing response latency and improving query efficiency.
Patent Information
- Application Number
- CN202410977145.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2026-01-20
AI Technical Summary
Existing technologies in multi-dimensional data aggregation queries result in high backend database load, long query response times, and a lack of scalability.
The query server generates aggregate query statements corresponding to all combinations of values for multiple data aggregation dimensions, including a first aggregate query statement corresponding to the first value combination and a second aggregate query statement corresponding to the second value combination. The query statement for the first value combination is used to obtain the full data, and the query statement for the second value combination is executed in the full data query results, reducing direct access to the backend database.
It reduces the load on the backend database, improves query efficiency, reduces query response latency, and can be flexibly scaled to any number of dimensions.
Smart Images

Figure CN121365076A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data query, and in particular to a data aggregation query method and device, an electronic device, and a computer readable storage medium. BACKGROUND
[0002] Aggregation queries of a database are implemented through specific SQL (Structured Query Language) functions that allow users to summarize or calculate a set of data. Aggregation queries are very useful in data analysis, report generation, and processing large amounts of data.
[0003] Currently, report business and other scenarios often involve complex requirements for multi-dimensional data aggregation queries, and the number of query combinations increases exponentially with the increase in data dimensions. If a SQL statement is constructed for each query combination to directly query the backend database, the load pressure on the backend database and the query response delay will be greatly increased. SUMMARY
[0004] Embodiments of the present application provide a data aggregation query method and device and a clearing server to reduce the load pressure on the backend database and improve query efficiency.
[0005] Embodiments of the present application use the following technical solutions:
[0006] In a first aspect, embodiments of the present application provide a data aggregation query method executed by a query server, wherein the data aggregation query method comprises:
[0007] receiving a data aggregation query request, wherein the data aggregation query request contains a plurality of data aggregation dimensions and the values of each data aggregation dimension;
[0008] generating aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request, wherein the aggregation query statements include a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination;
[0009] querying the backend database using the first aggregation query statement to obtain full data query results returned by the backend database under the first value combination;
[0010] querying the full data query results using the second aggregation query statement to obtain data aggregation query results under the second value combination.
[0011] Optionally, generating aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request comprises:
[0012] generating, according to the data aggregation query request and the binary, a binary representation corresponding to all value combinations of the plurality of data aggregation dimensions;
[0013] generating, according to the binary representation corresponding to all value combinations, an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions.
[0014] Optionally, the generating, according to the data aggregation query request and the binary, a binary representation corresponding to all value combinations of the plurality of data aggregation dimensions comprises:
[0015] dividing, according to values of the plurality of data aggregation dimensions, value types of the data aggregation dimensions, the value types comprising all values and specific values;
[0016] based on a dimension number of the plurality of data aggregation dimensions, generating a plurality of binary representations by using binary, each of the binary representations being composed of a plurality of characters;
[0017] determining, according to the plurality of data aggregation dimensions and the value types of the data aggregation dimensions, data aggregation dimensions and value types corresponding to values of each character in each binary representation.
[0018] Optionally, the generating, according to the binary representation corresponding to all value combinations, an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions comprises:
[0019] traversing values of each character in the binary representation corresponding to each value combination;
[0020] generating, according to data aggregation dimensions and value types corresponding to the traversed values of each character, an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions.
[0021] Optionally, the generating, according to data aggregation dimensions and value types corresponding to the traversed values of each character, an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions comprises:
[0022] if value types corresponding to values of each character in a binary representation are all all values, generating, according to data aggregation dimensions corresponding to values of each character, a first aggregation query statement corresponding to a first value combination, the first aggregation query statement not containing a where statement;
[0023] otherwise, generating, according to data aggregation dimensions and value types corresponding to the traversed values of each character, a second aggregation query statement corresponding to a second value combination, the second aggregation query statement containing a where statement.
[0024] Optionally, the querying in the full-data query result by using the second aggregate query statement to obtain the data aggregate query result under the second value combination comprises:
[0025] In the memory of the query server, the full-data query result under the first value combination is mapped into a data table form by using a preset mapping mechanism;
[0026] The second aggregate query statement is executed in the full-data query result in the data table form to obtain the data aggregate query result under the second value combination.
[0027] Optionally, after the querying in the full-data query result by using the second aggregate query statement to obtain the data aggregate query result under the second value combination, the data aggregate query method further comprises:
[0028] The full-data query result under the first value combination and the data aggregate query result under the second value combination are summarized and returned to the user.
[0029] In a second aspect, the embodiments of the present application further provide a data aggregate query device applied to a query server, wherein the data aggregate query device comprises:
[0030] A receiving unit configured to receive a data aggregate query request, wherein the data aggregate query request comprises a plurality of data aggregate dimensions and values of each data aggregate dimension;
[0031] A generating unit configured to generate an aggregate query statement corresponding to all value combinations of the plurality of data aggregate dimensions according to the data aggregate query request, wherein the aggregate query statement comprises a first aggregate query statement corresponding to a first value combination and a second aggregate query statement corresponding to a second value combination;
[0032] A first querying unit configured to query in a backend database by using the first aggregate query statement to obtain a full-data query result under the first value combination returned by the backend database;
[0033] A second querying unit configured to query in the full-data query result by using the second aggregate query statement to obtain a data aggregate query result under the second value combination.
[0034] In a third aspect, the embodiments of the present application further provide an electronic device comprising:
[0035] A processor; and
[0036] A memory arranged to store computer executable instructions that, when executed, cause the processor to perform any of the aforementioned data aggregate query methods.
[0037] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium storing one or more programs, which, when executed by an electronic device comprising a plurality of application programs, cause the electronic device to perform the data aggregation query method according to any one of the preceding embodiments.
[0038] The above at least one technical solution adopted by the embodiments of the present application can achieve the following beneficial effects: The data aggregation query method of the embodiments of the present application is executed by a query server, receives a data aggregation query request first, the data aggregation query request comprising a plurality of data aggregation dimensions and a value of each data aggregation dimension; then generates an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request, the aggregation query statement comprising a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination; thereafter, queries in a backend database by using the first aggregation query statement to obtain full data query results under the first value combination returned by the backend database; finally, queries in the full data query results by using the second aggregation query statement to obtain data aggregation query results under the second value combination. The data aggregation query method of the embodiments of the present application can query full data query results from the backend database by using the first aggregation query statement corresponding to the first value combination, and subsequent queries can be directly executed on the basis of the full data query results, without accessing the backend database for querying each time, which greatly reduces the load pressure of the backend database, reduces the query response delay, and improves the query efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0039] The accompanying drawings, which are included to provide a further understanding of the present application, constitute a part of the present application and illustrate the illustrative embodiments of the present application and their description serve to explain the present application, and do not constitute improper limitations on the present application. In the drawings:
[0040] Figure 1 FIG. 1 is a flowchart of a data aggregation query method according to an embodiment of the present application;
[0041] Figure 2 FIG. 2 is a structural diagram of a data aggregation query device according to an embodiment of the present application;
[0042] Figure 3 FIG. 3 is a structural diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0043] In order to make the purposes, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described below in connection with specific embodiments of the present application and corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0044] The technical solutions provided by the embodiments of the present application will be described in detail below in connection with the drawings.
[0045] The embodiments of the present application provide a data aggregation query method, which is executed by a query server, as shown in the following figure, a flowchart of a data aggregation query method in the embodiments of the present application is provided, and the data aggregation query method comprises at least the following steps S110 to S140: Figure 1
[0046] Step S110, receiving a data aggregation query request, wherein the data aggregation query request contains a plurality of data aggregation dimensions and the value of each data aggregation dimension.
[0047] The data aggregation query method of the embodiments of the present application is executed by a query server, and when data aggregation query is performed, a data aggregation query request initiated by a user needs to be received first, and the data aggregation query request needs to contain the data aggregation query requirement information of the user, which can specifically include a plurality of data aggregation dimensions provided by the user and the value of each data aggregation dimension.
[0048] Taking the scene of multi-dimensional aggregation calculation of related indicators for data with a two-dimensional table as the underlying data model as an example, the two-dimensional table has two dimensions A and B, and the possible values of each dimension are as follows:
[0049] A=[“All”,“A1”,“A2”,“A3”,“A4”]
[0050] B=[“All”,“B1”,“B2”]
[0051] Among them, All represents all possible values of the dimension, and the others represent single values of the dimension. All contains but is not limited to the value list listed below, for example, All of the A dimension can refer to A1, A2...A100. The current business requirement requires that any combination of A and B is calculated for related indicators.
[0052] The A and B dimensions are multiple data aggregation dimensions defined by the embodiments of the present application, wherein [“All”, “A1”, “A2”, “A3”, “A4”] are values of the A data aggregation dimension, and [“All”, “B1”, “B2”] are values of the B data aggregation dimension. Of course, the number of specific dimensions and values can be flexibly expanded according to the scene requirements, and which aggregation dimensions are included in the data aggregation query request initiated by the user and the specific values of each aggregation dimension can be flexibly selected or set by the user according to the actual query requirements, which are not limited here.
[0053] In step S120, an aggregation query statement corresponding to all value combinations of the multiple data aggregation dimensions is generated according to the data aggregation query request, wherein the aggregation query statement includes a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination.
[0054] After receiving the data query request, an aggregation query statement corresponding to all value combinations of the multiple data aggregation dimensions is generated according to the multiple data aggregation dimensions and their values in the request, and all value combinations can be understood as the mutual arbitrary combination of each value contained in the multiple data aggregation dimensions, and all possible combination results are obtained.
[0055] For example, for the above two data aggregation dimensions A and B and their corresponding value sets, there are the following four kinds of all possible value combinations:
[0056] 1) A = “All”, B = “All”
[0057] 2) A = “All”, B = [“B1”, “B2”]
[0058] 3) A = [“A1”, “A2”, “A3”, “A4”], B = “All”
[0059] 4) A = [“A1”, “A2”, “A3”, “A4”], B = [“B1”, “B2”]
[0060] The embodiments of the present application further divide the above all value combinations into two categories of first value combinations and second value combinations, and correspondingly generate a first aggregation query statement corresponding to the first value combination and a second aggregation query statement corresponding to the second value combination. The first aggregation query statement corresponding to the first value combination is mainly used for querying full-amount data, and the second aggregation query statement corresponding to the second value combination is mainly used for querying the aggregation result of part of the full-amount data, so from the data query range, the data range queried by the second aggregation query statement can be regarded as a subset of the full-amount data queried by the first aggregation query statement.
[0061] Step S130, querying in the backend database by using the first aggregate query statement to obtain full-amount data query results returned by the backend database under the first value combination.
[0062] After obtaining the first aggregate query statement corresponding to the first value combination and the second aggregate query statement corresponding to the second value combination, the first aggregate query statement is used to query the backend database first, and the backend database can return full-amount data corresponding to the first value combination according to the query statement. The full-amount data can be understood as all data covered under multiple data aggregation dimensions, without considering the specific value of each data aggregation dimension. This process is equivalent to pulling all data of the target data table that the user wants to query in the backend database to the query server.
[0063] It should be noted that in the report business scenario, the user usually has the demand for querying full-amount data. In this case, the full-amount data can be obtained according to the data aggregation query request. However, considering the difference between different business scenarios and query requirements, the user may not necessarily have the demand for querying full-amount data. Therefore, after all possible combinations of the values of the multiple data aggregation dimensions included in the request are obtained, the full-amount data may not include the first value combination, that is, the full-amount data is not obtained. For this case, the embodiment of the present application can be preset, that is, even if the user does not include the specific value corresponding to the first value combination in the request, the first aggregate query statement corresponding to the first value combination is automatically generated to ensure that the full-amount data can be obtained at all times.
[0064] Step S140, querying in the full-amount data query results by using the second aggregate query statement to obtain data aggregation query results under the second value combination.
[0065] After obtaining the full-amount data, the subsequent other query statement, that is, the second aggregate query statement, is directly executed on the basis of the full-amount data to obtain the data aggregation query results under the second value combination. The second value combination can be multiple, for example, the user can want to query the data aggregation results corresponding to the combination 2) and the combination 3) respectively. Then, the aggregate query statements corresponding to the combination 2) and the combination 3) can be executed on the basis of the full-amount data to obtain the data aggregation query results corresponding to the combination 2) and the combination 3) respectively.
[0066] It should be noted that the steps S120-S140 are defined as follows: first, the first aggregation query statement corresponding to the first value combination and the second aggregation query statement corresponding to the second value combination are generated, and then the query is performed. In actual application, the first aggregation query statement corresponding to the first value combination can be generated first, then the full-amount data is obtained by executing the first aggregation query statement, the second aggregation query statement corresponding to the second value combination is generated, and then the second aggregation query statement is executed on the basis of the full-amount data. How to set it specifically can be selected flexibly by those skilled in the art according to actual needs.
[0067] The data aggregation query method of the embodiment of the application can query the full-amount data query result from the backend database by using the first aggregation query statement corresponding to the first value combination, and subsequent queries can be directly executed on the basis of the full-amount data query result, without accessing the backend database for querying each time, which greatly reduces the load pressure of the backend database, reduces the query response delay, and improves the query efficiency.
[0068] In some embodiments of the application, the generating of the aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request comprises: generating binary representations corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request and the binary; and generating the aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the binary representations corresponding to all value combinations.
[0069] In the prior art, when constructing a query statement, each possible value combination needs to be simply enumerated, for example, for the simplest case of the two dimensions A and B, the combination cases are as follows:
[0070] 1) A = "All", B = "All"
[0071] 2) A = "All", B = ["B1", "B2"]
[0072] 3) A = ["A1", "A2", "A3", "A4"], B = "All"
[0073] 4) A = ["A1", "A2", "A3", "A4"], B = ["B1", "B2"]
[0074] Each combination is queried from the backend database by using an SQL statement, for example, the SQL statement corresponding to the second combination can be expressed in the following form, and other combinations are similar:
[0075] select sum(m), B from t where B in ('B1', 'B2') group by B
[0076] If a dimension C is added on the basis of the existing two dimensions A and B, the number of combinations / query times becomes 8 through analysis, and if a dimension D is further added, the number of combinations / query times becomes 16, and so on. This exponential growth leads to a lack of scalability of the existing solution.
[0077] Based on this, the embodiments of the present application consider the exponential relationship between the number of combinations and the number of dimensions when generating the aggregate query statements corresponding to all value combinations, and the simple and consistent association between each combination and the corresponding SQL statement. Binary is used to express this association, that is, based on the query request and the binary expression method, binary representations are generated that can cover all value combinations, and then the binary representations corresponding to all value combinations are used to generate corresponding aggregate query statements. For any number of aggregate dimensions, the SQL statements corresponding to the related combinations are dynamically generated instead of being simply enumerated, thereby improving the scalability of the overall solution.
[0078] In some embodiments of the present application, the generating, according to the data aggregation query request and the binary, of the binary representations corresponding to all value combinations of the plurality of data aggregation dimensions includes: dividing the value types of the data aggregation dimensions according to the values of the plurality of data aggregation dimensions, the value types including all values and specific values; generating a plurality of binary representations based on the number of dimensions of the plurality of data aggregation dimensions, each of the binary representations being composed of a plurality of characters; determining the data aggregation dimension and the value type corresponding to the value of each character in each binary representation according to the plurality of data aggregation dimensions and the value types of the data aggregation dimensions.
[0079] When generating the binary representations corresponding to all value combinations, the values of the plurality of data aggregation dimensions can be divided into two categories based on the structural characteristics of binary expression, including the types of all values and specific values. All values, i.e., the ALL case, represent all possible values of a certain data aggregation dimension, and specific values represent a single value of a certain data aggregation dimension.
[0080] For example, for the possible values of the above-mentioned dimensions A and B:
[0081] A = ["All", "A1", "A2", "A3", "A4"]
[0082] B = ["All", "B1", "B2"]
[0083] The values of the A dimension can be divided into all values [“ALL”] and specific values [“A1”, “A2”, “A3”, “A4”], and the values of the B dimension can be divided into all values [“ALL”] and specific values [“B1”, “B2”]. The same is true when expanding to more dimensions, so that the values of each data aggregation dimension can be uniformly divided into all values and specific values.
[0084] Further, considering the exponential relationship between the number of combinations and the number of dimensions, the embodiments of the present application can generate a plurality of binary representations capable of covering all value combinations based on this relationship and the number of dimensions of the current data aggregation dimension, each binary representation being composed of a plurality of characters, each character having two values of 0 or 1.
[0085] For example, when there are two data aggregation dimensions, binary representations from 0 to 3 (2^number of dimensions-1) can be generated, i.e., 00, 01, 10, and 11. Similarly, when there are three data aggregation dimensions, eight binary representations of 000, 001, 010, 011, 100, 101, 110, and 111 can be generated, and so on. Binary representations corresponding to any number of dimensions can be generated in this way.
[0086] Based on this, each data aggregation dimension and the two types of values divided by the data aggregation dimension can be corresponded to each character of the binary representation and the values of the character, and this process can be regarded as a process of giving meaning to each character of the binary representation. For example, on the one hand, the plurality of characters in the binary representation can be defined to represent the A, B, and C dimensions in turn, and on the other hand, the character value 0 in the binary representation can be defined to represent all values ALL, and 1 can be defined to represent specific values. Of course, the character value 0 can be defined to represent specific values, and 1 can be defined to represent all values ALL, which is not limited here.
[0087] In this way, for the four combinations of 00, 01, 10, and 11, it can be determined that 00 represents that the values of the A and B dimensions are all values, corresponding to the case of combination 1) above, 01 represents that the value of the A dimension is all values and the value of the B dimension is a specific value, corresponding to the case of combination 2), 10 represents that the value of the A dimension is a specific value and the value of the B dimension is all values, corresponding to the case of combination 3), and 11 represents that the values of the A and B dimensions are both specific values, corresponding to the case of combination 4).
[0088] Therefore, through the above processing, each binary representation will have a specific meaning, and each binary representation corresponds to a value combination, so that all possible value combinations can be covered by the simple binary representation, without enumerating each possibility, and thus easily extended to any number of dimensions.
[0089] In some embodiments of the present application, the generating the aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the binary representations corresponding to the all value combinations comprises: traversing the value of each character in each binary representation; and generating the aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation dimension corresponding to the value of each character and the value type corresponding to the value of each character.
[0090] In the generating of the aggregation query statements according to the binary representations corresponding to all value combinations, each value of each character in each binary representation can be traversed first. Since the data aggregation dimension corresponding to each character and the value type corresponding to the value of each character have been defined in the foregoing embodiments, the data aggregation dimension corresponding to the value of each character and the value type corresponding to the value of each character can be determined by the traversal. For example, if the current binary representation 01 is traversed, it represents that the value combination corresponding to the binary representation is that the value of the data aggregation dimension A is all values ALL and the value of the data aggregation dimension B is a specific value B1 or B2.
[0091] Since there is a simple and consistent association between each value combination and the corresponding SQL statement in the data aggregation query scenario, the limitation on the value combination condition in the SQL statement is determined after the specific value combination is determined. Therefore, the corresponding aggregation query statement can be dynamically generated according to each value combination obtained by the traversal.
[0092] In some embodiments of the present application, the generating the aggregation query statements corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation dimension corresponding to the value of each character and the value type corresponding to the value of each character comprises: if the value type corresponding to the value of each character in a binary representation is all values, generating a first aggregation query statement corresponding to a first value combination according to the data aggregation dimension corresponding to the value of each character, the first aggregation query statement not containing a where statement; otherwise, generating a second aggregation query statement corresponding to a second value combination according to the data aggregation dimension corresponding to the value of each character and the value type corresponding to the value of each character, the second aggregation query statement containing a where statement.
[0093] The foregoing embodiments divide the values of the data aggregation dimensions into two categories, all values and specific values, based on the characteristics of the binary representation. All possible combinations are made based on the two categories of values, and all value combinations obtained are also divided into two categories, a first value combination and a second value combination. The first value combination can be understood as a case where the values of the plurality of data aggregation dimensions are all of the all value type, and the purpose is to obtain full data. The second value combination includes all the remaining combination cases.
[0094] Based on this, when generating the corresponding aggregation query statement according to the data aggregation dimension and the value type corresponding to the value of each character traversed, if the value type corresponding to the value of each character traversed is all value types, it indicates that the binary representation currently traversed is the binary representation of the first value combination. Since the role of distinguishing the first value combination is to enable subsequent query of full data, that is, all data aggregation dimensions, without specific limitations on the values of the dimensions, when generating the first aggregation query statement of the first value combination, only the data aggregation dimensions corresponding to the value of each character currently traversed need to be considered, without considering the specific values of each dimension, that is, the where statement does not need to be set in the finally generated first aggregation query statement. The where statement here refers to a conditional limitation statement for the value of a certain dimension.
[0095] If the value type corresponding to the value of each character traversed is not all value types, it indicates that the binary representation currently traversed is the binary representation of the second value combination, that is, at least one data aggregation dimension has a specific value requirement, and the specific value of the dimension needs to be conditionally limited. Therefore, the where statement needs to be set in the finally generated second aggregation query statement.
[0096] For example, 1 in the binary representation 10 represents that the A dimension uses a specific value, and the corresponding SQL statement can be represented in the following form:
[0097] select sum(m),A from t where A in(‘A1’,‘A2’,‘A3’,‘A4’)group by A
[0098] 1 in the binary representation 01 represents that the B dimension uses a specific value, and the corresponding SQL statement can be represented in the following form:
[0099] select sum(m),B from t where B in(‘B1’,‘B2’)group by B
[0100] In some embodiments of the present application, the querying in the full data query result using the second aggregation query statement to obtain the data aggregation query result under the second value combination includes: in the memory of the query server, using a preset mapping mechanism to map the full data query result under the first value combination into a data table form; and executing the second aggregation query statement in the full data query result in the data table form to obtain the data aggregation query result under the second value combination.
[0101] Since the data form of the full data query result returned by the backend database cannot be directly used for secondary query, the embodiment of the application can first remap the full data query result under the first value combination to the form of a data table in the memory of the query server by adopting a certain mapping mechanism, so that the second aggregation query statement can be directly executed in the full data table in the memory, thereby obtaining the data aggregation query result under the second value combination, and the problem that the backend database needs to be accessed every time is avoided.
[0102] The mapping mechanism can be implemented by, for example, the Reflective Schema mechanism in Apache Calcite. The Reflective Schema mechanism allows Calcite to access Java objects as the schema of a database through reflection, that is, a normal Java object set can be queried as a database table. The Reflective Schema can map the fields of the Java object to the columns of the table and map the set of objects to the rows of the table. Of course, in addition to the Reflective Schema mechanism in Apache Calcite, other frameworks capable of achieving the above function in the prior art, such as Hibernate and MyBatis, can also be adopted, and the application is not limited in this regard.
[0103] In some embodiments of the application, after the second aggregation query statement is used to query in the full data query result, the data aggregation query result under the second value combination is obtained, the data aggregation query method further includes: the full data query result under the first value combination and the data aggregation query result under the second value combination are summarized and returned to the user.
[0104] After the query results of all value combinations are obtained, all the query results can be combined and sent to the user together. Of course, if the query requirement of the user does not include full data, the data aggregation query result under the second value combination can also be returned to the user. The specific query results to be sent can be flexibly set by the person skilled in the art according to the user requirement.
[0105] In summary, the application at least achieves the following technical effects:
[0106] 1) In the data aggregation query scenario, the dimensions of the aggregation query can be simply and flexibly expanded to any number of dimensions;
[0107] 2) The backend database needs to be queried only once, the pressure of the backend database is stable, and the load pressure of the backend database is reduced;
[0108] 3) Most of the query logic is completed in the application layer through in-memory SQL, which is easy to extend and fast in execution, thus greatly reducing the query response delay.
[0109] The embodiment of the application further provides a data aggregation query device 200, which is applied to a query server, and the data aggregation query device 200 comprises a receiving unit 210, a generating unit 220, a first query unit 230 and a second query unit 240. Figure 2 As shown in the figure, a structure diagram of the data aggregation query device in the embodiment of the application is provided, and the data aggregation query device 200 at least comprises a receiving unit 210, a generating unit 220, a first query unit 230 and a second query unit 240, wherein:
[0110] The receiving unit 210 is used for receiving a data aggregation query request, wherein the data aggregation query request comprises multiple data aggregation dimensions and values of each data aggregation dimension.
[0111] The generating unit 220 is used for generating an aggregation query statement corresponding to all value combinations of the multiple data aggregation dimensions according to the data aggregation query request, wherein the aggregation query statement comprises a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination.
[0112] The first query unit 230 is used for querying in a backend database by using the first aggregation query statement to obtain full-amount data query results under the first value combination returned by the backend database.
[0113] The second query unit 240 is used for querying in the full-amount data query results by using the second aggregation query statement to obtain data aggregation query results under the second value combination.
[0114] In some embodiments of the application, the generating unit 220 is specifically used for generating binary representations corresponding to all value combinations of the multiple data aggregation dimensions according to the data aggregation query request and the binary; and generating the aggregation query statement corresponding to all value combinations of the multiple data aggregation dimensions according to the binary representations corresponding to all value combinations.
[0115] In some embodiments of the application, the generating unit 220 is specifically used for dividing value types of the data aggregation dimensions according to the values of the multiple data aggregation dimensions, wherein the value types comprise all values and specific values; generating multiple binary representations by using binary based on the number of dimensions of the multiple data aggregation dimensions, wherein each binary representation is composed of multiple characters; and determining data aggregation dimensions and value types corresponding to values of each character in each binary representation according to the multiple data aggregation dimensions and the value types of the data aggregation dimensions.
[0116] In some embodiments of the present application, the generating unit 220 is specifically configured to: traverse the value of each character in the binary representation corresponding to each value combination; and generate an aggregated query statement corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation dimension and the value type corresponding to the value of each character traversed.
[0117] In some embodiments of the present application, the generating unit 220 is specifically configured to: if the value type corresponding to the value of each character in a binary representation is all values, generate a first aggregated query statement corresponding to a first value combination according to the data aggregation dimension corresponding to the value of each character, wherein the first aggregated query statement does not include a where statement; otherwise, generate a second aggregated query statement corresponding to a second value combination according to the data aggregation dimension and the value type corresponding to the value of each character traversed, wherein the second aggregated query statement includes a where statement.
[0118] In some embodiments of the present application, the second query unit 240 is specifically configured to: map the full-amount data query result under the first value combination into a data table form in the memory of the query server by using a preset mapping mechanism; and execute the second aggregated query statement in the full-amount data query result in the data table form to obtain the data aggregation query result under the second value combination.
[0119] In some embodiments of the present application, the data aggregation query device further includes a summarizing unit configured to, after the data aggregation query result under the second value combination is obtained by querying the full-amount data query result under the first value combination using the second aggregated query statement, return the full-amount data query result under the first value combination and the data aggregation query result under the second value combination to the user after summarizing the full-amount data query result under the first value combination and the data aggregation query result under the second value combination.
[0120] It can be understood that the above-mentioned data aggregation query device can realize each step of the data aggregation query method performed by the clearing server provided in the foregoing embodiments, and the related explanations about the data aggregation query method are all applicable to the data aggregation query device, which will not be described here again.
[0121] Figure 3 is a structural schematic diagram of an electronic device of an embodiment of the present application. Please refer to Figure 3 At the hardware level, the electronic device includes a processor, and optionally further includes an internal bus, a network interface, and a memory. The memory can include a memory such as a random-access memory (RAM), and can also include a non-volatile memory such as at least one disk memory. Of course, the electronic device can also include other hardware required by the business.
[0122] The processor, the network interface and the memory can be connected with each other through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used to represent the bus, but it does not mean that there is only one bus or only one type of bus.
[0123] The memory is used to store programs. Specifically, the program can include program code including computer operation instructions. The memory can include an internal memory and a non-volatile memory, and provide instructions and data for the processor.
[0124] The processor reads the corresponding computer program from the non-volatile memory into the internal memory and then runs, and forms a data aggregation query device at a logical level. The processor executes the program stored in the memory, and is specifically used for executing the following operations:
[0125] Receiving a data aggregation query request, the data aggregation query request containing a plurality of data aggregation dimensions and the value of each data aggregation dimension;
[0126] Generating an aggregation query statement corresponding to all value combinations of the plurality of data aggregation dimensions according to the data aggregation query request, the aggregation query statement including a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination;
[0127] Using the first aggregation query statement to query in a backend database to obtain full-amount data query results under the first value combination returned by the backend database;
[0128] Using the second aggregation query statement to query in the full-amount data query results to obtain data aggregation query results under the second value combination.
[0129] The above as described in the present application Figure 1The method performed by the data aggregation query apparatus disclosed in the embodiments shown can be applied in a processor or implemented by the processor. The processor can be an integrated circuit chip with processing capability. In implementation process, each step of the above method can be completed by hardware integrated logic circuit or software form of instruction in the processor. The processor mentioned above can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; or can be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. Each method, step and logic block diagram disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or any conventional processor. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read only memory, a programmable read only memory or an electrically erasable programmable memory, a register, etc. The storage medium in the memory is read by the processor, and the hardware thereof is combined to complete the steps of the above method.
[0130] The electronic device can also execute the method performed by the data aggregation query apparatus in the method, and implement the functions of the data aggregation query apparatus in the method. Figure 1 The electronic device can also execute the method performed by the data aggregation query apparatus in the method, and implement the functions of the data aggregation query apparatus in the method. Figure 1 The electronic device can also execute the method performed by the data aggregation query apparatus in the method, and implement the functions of the data aggregation query apparatus in the method.
[0131] The embodiments of the present application also propose a computer readable storage medium storing one or more programs, the one or more programs including instructions, which when executed by an electronic device including a plurality of applications, can enable the electronic device to execute the method performed by the data aggregation query apparatus in the embodiments shown, and specifically execute the following steps: Figure 1 The electronic device can also execute the method performed by the data aggregation query apparatus in the method, and implement the functions of the data aggregation query apparatus in the method.
[0132] receiving a data aggregation query request, the data aggregation query request including a plurality of data aggregation dimensions and a value of each data aggregation dimension;
[0133] generating an aggregation query statement corresponding to all value combination of the plurality of data aggregation dimensions according to the data aggregation query request, the aggregation query statement comprising a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination;
[0134] querying in the backend database by using the first aggregation query statement to obtain full-amount data query result under the first value combination returned by the backend database;
[0135] querying in the full-amount data query result by using the second aggregation query statement to obtain data aggregation query result under the second value combination.
[0136] Those skilled in the art will understand that embodiments of the present application can be provided as methods, systems, or computer program products. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer readable program code.
[0137] The present application is described in reference to the flowcharts and / or block diagrams of the methods, apparatus (systems) and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, a special purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus produce the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for performing the functions specified in the flowchart
[0138] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer readable memory produce a product including instruction means, which implement the functions specified in the flowcharts and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for performing the functions specified in the flowchart
[0139] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are performed on the computer or other programmable data processing apparatus to produce a computer implemented process, so that the instructions executed on the computer or other programmable data processing apparatus provide functions for implementing the functions specified in the flowcharts and / or block diagrams.Figure 1 one or more processes and / or functions specified in one or more blocks one or more blocks or any combination thereof for indicating functionality
[0140] In one typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0141] The memory can include non-persistent memory and / or volatile memory, such as random access memory (RAM) about which the computer stores information about an operating system. Memory is an example of computer readable media.
[0142] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.
[0143] It is also important to note that the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element preceded by "comprises... a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or apparatus that includes the recited element.
[0144] Those skilled in the art will appreciate that embodiments of the present application can be devised for a method, a system, or a computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer-readable program code thereon for use by or in connection with an instruction execution system. For the purposes of this description, a computer-usable or computer readable storage medium can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
[0145] The above descriptions are only some embodiments of the present application and are not intended to limit the present application. Various modifications and changes can be made by those skilled in the art to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the scope of claims of the present application.
Claims
1. A data aggregation query method, executed by a query server, wherein, The data aggregation query method includes: Receive a data aggregation query request, which contains multiple data aggregation dimensions and the value of each data aggregation dimension; Based on the data aggregation query request, generate aggregation query statements corresponding to all value combinations of multiple data aggregation dimensions. The aggregation query statements include a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination. The first aggregate query statement is used to query the backend database to obtain the full data query results under the first value combination returned by the backend database. The second aggregation query statement is used to query the full data query results to obtain the data aggregation query results under the second value combination.
2. The data aggregation query method as described in claim 1, wherein, The step of generating the aggregation query statement corresponding to all combinations of values for multiple data aggregation dimensions based on the data aggregation query request includes: Based on the data aggregation query request and the binary representation, generate binary representations corresponding to all combinations of values for multiple data aggregation dimensions; Generate aggregate query statements corresponding to all value combinations across multiple data aggregation dimensions based on the binary representation of all value combinations.
3. The data aggregation query method as described in claim 2, wherein, The step of generating binary representations corresponding to all combinations of values for multiple data aggregation dimensions based on the data aggregation query request and binary representations includes: The data aggregation dimensions are classified into value types based on the values of multiple data aggregation dimensions. The value types include all values and specific values. Based on the number of dimensions of multiple data aggregation dimensions, multiple binary representations are generated using binary, and each binary representation consists of multiple characters; Based on multiple data aggregation dimensions and the value types of the data aggregation dimensions, determine the data aggregation dimension and value type corresponding to the value of each character in each binary representation.
4. The data aggregation query method as described in claim 3, wherein, The step of generating aggregate query statements corresponding to all value combinations of multiple data aggregation dimensions based on the binary representation of all value combinations includes: Iterate through the binary representation of each character corresponding to each value combination; Based on the data aggregation dimension and value type corresponding to the value of each character traversed, generate an aggregate query statement corresponding to all combinations of values of multiple data aggregation dimensions.
5. The data aggregation query method as described in claim 4, wherein, The process of generating aggregate query statements corresponding to all combinations of values across multiple data aggregation dimensions based on the data aggregation dimension and value type corresponding to the value of each traversed character includes: If the value type corresponding to each character in a binary representation is all values, then the first aggregation query statement corresponding to the first value combination is generated according to the data aggregation dimension corresponding to the value of each character. The first aggregation query statement does not contain a WHERE clause. Otherwise, a second aggregation query statement corresponding to the second value combination is generated based on the data aggregation dimension and value type corresponding to the value of each character traversed. The second aggregation query statement contains a WHERE clause.
6. The data aggregation query method as described in claim 1, wherein, The step of using the second aggregate query statement to query the full data query results and obtain the data aggregate query results under the second value combination includes: In the memory of the query server, a preset mapping mechanism is used to map the full data query results under the first value combination into a data table format; Execute the second aggregation query statement on the full data query results in the form of a data table to obtain the data aggregation query results under the second value combination.
7. The data aggregation query method according to any one of claims 1 to 6, wherein, After using the second aggregation query statement to query the full data query results and obtain the data aggregation query results under the second value combination, the data aggregation query method further includes: The results of the full data query under the first value combination and the data aggregation query results under the second value combination are summarized and returned to the user.
8. A data aggregation and query device, applied to a query server, wherein, The data aggregation and query device includes: A receiving unit is used to receive a data aggregation query request, wherein the data aggregation query request contains multiple data aggregation dimensions and the value of each data aggregation dimension; The generation unit is used to generate an aggregation query statement corresponding to all value combinations of multiple data aggregation dimensions according to the data aggregation query request. The aggregation query statement includes a first aggregation query statement corresponding to a first value combination and a second aggregation query statement corresponding to a second value combination. The first query unit is used to perform a query in the backend database using the first aggregate query statement to obtain the full data query result under the first value combination returned by the backend database. The second query unit is used to perform a query on the full data query result using the second aggregate query statement to obtain the data aggregate query result under the second value combination.
9. An electronic device, comprising: processor; as well as A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform any of the data aggregation query methods of claims 1 to 7.
10. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of applications, cause the electronic device to perform any one of the data aggregation query methods of claims 1 to 7.