Data query method and system
By distributing query targets to multiple computing modules and aggregating query results, the problem of inefficiency caused by data landing in cross-data source queries is solved, efficient query of target data is achieved without merging data, and real-time query capabilities are ensured. .
Patent Information
- Application Number
- CN202011449170.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-09
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2040-12-09
AI Technical Summary
In the process of cross-data source query, data landing is time-consuming and labor-intensive, resulting in server memory overflow, lag or even downtime. The query efficiency is low, and millisecond-level real-time query cannot be achieved.
The query target is distributed to multiple computing modules through the distribution module. The computing module accesses the cache module to query the target data according to the distributed query target, and the aggregation module aggregates the query results to achieve cross-data source query without data merging.
It improves the efficiency of data query, realizes efficient query in scenarios where data does not land, avoids server resource overload and query delay, and ensures real-time query capabilities for massive data.
Smart Images

Figure CN112434060B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to database technology, and in particular to a data query method and system. Background Art
[0002] In business development practice, cross-departmental and cross-team collaborative development is usually required. Business data is usually distributed in the databases of different departments or teams, or stored in different data tables. These data from different databases or data tables are data from different data sources. The data stored in different data sources have different data contents, data storage structures and storage locations may also be different. In many scenarios, customers need to start from one data source and query data in other databases or data tables across data sources. For example, when sorting certain fields in a list page, the filter condition fields are stored in the data table of Department A, and the specific values or index values to be sorted are stored in the data table of Department B. At this time, it is necessary to query the corresponding specific values or index values in the data table of Department B based on the data table of Department A.
[0003] In the process of cross-data source query, the data from different data sources must first be landed in the same data source, for example, the data table of Department A is merged with the content stored in the data table of Department B, or the data stored in the data table of Department B is migrated to the data table of Department A. Only on this basis can the corresponding data in the data table of Department B be obtained according to each item in the data table of Department A. However, the data landing process is time-consuming and labor-intensive, and the data is huge after landing in the same data source, which requires a large amount of memory, easily leading to memory overflow and freeze of the server, and even causing the server to crash and unable to query effectively; in addition, for large-scale data that lands in the same data source, the query efficiency is greatly reduced, and millisecond-level real-time query cannot be achieved. Summary of the invention
[0004] The present invention provides a data query method and system, which realizes querying target data across data sources without the data being landed, thereby improving the efficiency of data query.
[0005] In a first aspect, an embodiment of the present disclosure provides a data query method, including:
[0006] The distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources;
[0007] The computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target;
[0008] The aggregation module aggregates the query results of the calculation modules on the target data.
[0009] In a second aspect, the embodiment of the present disclosure further provides a data query system, including: a distribution module, a calculation module, a cache module and an aggregation module;
[0010] The cache module is used to store query targets and target data;
[0011] The distribution module is used to distribute the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources;
[0012] The computing module is used to access the cache module according to the distributed query target to query the target data corresponding to the query target;
[0013] The aggregation module is used to aggregate the query results of the calculation modules on the target data.
[0014] The disclosed embodiments provide a data query method and system. The method includes: a distribution module distributes a query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources; the computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target; and the aggregation module aggregates the query results of the target data by each computing module. The above technical solution improves the efficiency of data query by distributing the query target to different computing modules, and each computing module queries the corresponding target data respectively; and when querying target data across data sources, there is no need to merge the data from different data sources into the same data source first, thereby realizing efficient query of target data in a scenario where data is not landed. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of a data query method provided in Embodiment 1 of the present disclosure;
[0016] Figure 2 A schematic diagram of implementing data query by module interaction provided in the first embodiment of the present disclosure;
[0017] Figure 3 A flowchart of a data query method provided in Embodiment 2 of the present disclosure;
[0018] Figure 4 A flowchart of a data query method provided in Embodiment 3 of the present disclosure;
[0019] Figure 5A flowchart of a data query method provided in Embodiment 4 of the present disclosure;
[0020] Figure 6 A structural diagram of a data query system provided in Embodiment 5 of the present disclosure;
[0021] Figure 7 A schematic diagram of a data query process provided in Embodiment 5 of the present disclosure. DETAILED DESCRIPTION
[0022] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0023] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or performed concurrently. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0024] As used herein, the term “including” and its variations are open inclusions, ie, “including but not limited to.” The term “based on” means “based at least in part on.” The term “one embodiment” means “at least one embodiment.”
[0025] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0026] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0027] In the following embodiments, each embodiment provides optional features and examples at the same time, and the various features recorded in the embodiments can be combined to form multiple optional solutions, and each numbered embodiment should not be regarded as only one technical solution. In addition, the embodiments in this disclosure and the features in the embodiments can be combined with each other without conflict.
[0028] Embodiment 1
[0029] Figure 1A flow chart of a data query method provided for the first embodiment of the present disclosure. The method can be applied to the case of querying target data from different data sources, and specifically, to the case of querying corresponding target data across data sources for the query target. The query in this embodiment includes reading the corresponding target data for the query target, and can also include operations such as sorting, modifying, filtering, classifying or marking the read target data according to the query conditions. The method can be applied to a data query system, which can be composed of a server cluster, including a distribution module, a cache module, a computing module, an aggregation module, etc.
[0030] like Figure 1 As shown, a data query method provided in Embodiment 1 of the present disclosure includes the following steps:
[0031] S110. The distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources.
[0032] In this embodiment, the query target refers to the object to be queried, and can also be understood as a keyword or known data used to query the target data, and the query target can be directly read from the current (or local) database or data table. The target data refers to the data to be queried that cannot be directly read from the current (or local) database or data table. The query target and the target data belong to different data sources, and there is a definite mapping relationship between the two. According to the query target, the corresponding target data can be read from different data sources.
[0033] Specifically, the query target may refer to data containing local fields (fields stored in the current or local database or data table), and the target data refers to data to be queried from a different data source than the data in the local field. In the case of query conditions, the target data may also refer to data from a different data source than the query target that needs to be queried according to the query conditions, wherein the query conditions refer to the screening basis for the target data during the query process, which may be to query a specific number of target data with the largest or smallest value, to query a specific number of target data with the most or least updates within a set period of time, or to query a specific number of target data that has been updated most or least times within a set period of time, etc.
[0034] For example, department A stores the customer IDs of all customers; department B stores the account information of each customer, including account balance, consumption records, etc. The customer IDs stored in department A and the account information stored in department B belong to different data sources, and there is a one-to-one or one-to-many mapping relationship between customer IDs and account information. For each customer ID, the corresponding account balance can be queried from department B according to the mapping relationship.
[0035] For example, to query the account balances of n customers based on the data stored in Department A, the local field is the customer identification field, and the query target is the customer identification of the n customers stored in Department A; the target data to be queried is the account balances corresponding to these n customers stored in Department B.
[0036] For another example, when querying the n customers with the largest account balances based on the data stored in Department A (with query conditions attached), all customer identifiers in Department A can be used as query targets; the query conditions refer to the following: the account balances of the n customers obtained by the query must meet the following requirements: the account balances of these n customers are the largest among all customers' account balances, and the account balance of each customer in Department B is the target data that needs to be queried according to the query conditions.
[0037] Optionally, the query target can be specified through a query request, or can be selected by the distribution module from the current (or local) database or data table according to the query conditions. For example, Department A stores the IDs of 100 customers, and the query request specifies that the account balances of customers with customer IDs c1-c8 are to be queried. Then the query target only includes the customer IDs of customers with customer IDs c1-c8. For another example, if the query condition is to query the account balances of customers whose account balances have changed within 24 hours, then the distribution module only needs to select the customer IDs that have undergone query operations within 24 hours as the query target according to the query condition, and the account balances of other customers that have not undergone any query operations within 24 hours do not need to be queried.
[0038] In this embodiment, the distribution module distributes the query target to at least two computing modules, which can be understood as distributing the query task for each query target to multiple computing modules. Each computing module queries the target data corresponding to the distributed query target, which can reduce the load of each computing module, and each computing module can query concurrently, and each query task is executed asynchronously, thereby improving query efficiency.
[0039] S120: The calculation module accesses the cache module according to the distributed query target to query the target data corresponding to the query target.
[0040] In this embodiment, the query target and its target data can be stored in different cache modules, or in different data tables of the same cache module. The calculation module calls the external interface to access the cache module for the query target distributed to it, so as to query the corresponding target data. For example, if the query target distributed to the calculation module 1 is customer identifiers c1 and c2, then the calculation module 1 can query the account balances of c1 and c2 from the data stored in the B department by accessing the cache module; if the query target distributed to the calculation module 2 is customer identifiers c3, c4 and c5, then the calculation module 2 can query the account balances of c3, c4 and c5 from the data stored in the B department by accessing the cache module; if the query target distributed to the calculation module 3 is customer identifiers c6, c7 and c8, then the calculation module 3 can query the account balances of c6, c7 and c8 from the data stored in the B department by accessing the cache module. The queries of the calculation modules 1, 2 and 3 are performed concurrently.
[0041] S130. An aggregation module aggregates query results of the computing modules on the target data.
[0042] In this embodiment, the aggregation module aggregates the query results of each calculation module to obtain the final query result. For example, calculation module 1 queries the account balances of c1 and c2, calculation module 2 queries the account balances of c3, c4 and c5, and calculation module 3 queries the account balances of c6, c7 and c8. Then the aggregation module aggregates the query results of each calculation module and finally obtains the account balances of c1-c8. In addition, the read target data can also be sorted, modified, filtered, classified or marked.
[0043] In the data query method of the present embodiment, the calculation module utilizes the mapping relationship between the query target and the target data, and can call the external interface to query the target data. Therefore, there is no need to merge the data from different data sources. The data from different data sources can still be stored according to the original structure or format, thereby maintaining the independence of the data from different data sources and ensuring that the business data of each department will not be invaded by external business data.
[0044] Figure 2 This is a schematic diagram of a module interaction to implement data query provided in the first embodiment of the present disclosure. Figure 2 As shown in the figure, after the distribution module receives the query request, the data query process mainly includes:
[0045] 1) The distribution module selects a query target from the query request and accesses the cache module through a related interface, wherein the query target can be specified by the query request or selected by the distribution module from the current (or local) database or data table according to the query conditions, for example, selecting a customer ID whose account balance has changed within 24 hours as the query target;
[0046] 2) The distribution module divides the query target into multiple groups and distributes them to the downstream computing modules. Usually, the target data to be queried is large in scale, there are multiple computing modules, and each computing module queries concurrently;
[0047] 3) The computing module calls the external interface to access the cache module according to the distributed query target to query the corresponding target data. In addition, the query timestamp of the target data can be pushed to the cache module to update the latest query time of the target data recorded in the cache module;
[0048] 4) The calculation module notifies the distribution module that the data query has been completed;
[0049] 5) The query results of each calculation module are pushed to the aggregation module, which aggregates and processes them to obtain the final query results for the target data;
[0050] 6) The distribution module obtains the query results from the aggregation module through the relevant interface.
[0051] It should be noted that the number of the above-mentioned various modules can be one or more, and the functions of each module can be implemented based on one or more servers, and the functions of different modules can also be implemented by the same server. For example, the distribution module, cache module, and aggregation module can be deployed on the same server, and the server is used to distribute the query target to at least two computing modules and aggregate the query results of the computing modules. The computing module can be composed of multiple servers, and each server is used to query the corresponding target data according to the distributed query target to realize distributed query. For another example, the distribution module, cache module, aggregation module, and computing module are respectively composed of different servers, and the cross-data source query of the target data is completed through the interaction of the server cluster.
[0052] In addition, as the number of active accounts increases, the target data to be queried or the query conditions increase, the number of computing modules can be increased to meet the query needs for massive target data. For example, the number of servers included in each module is adjusted according to the amount of data stored in the current (or local) database or data table. The larger the amount of stored data, the more servers are included in the computing module; for example, within a set time period, the more frequently the data stored in the cache module is queried, the more servers are included in the computing module; for example, the more query conditions are included in the query request, the more servers are included in the computing module, etc. Optionally, the number of servers in each module can be expanded or adjusted, and the failure of some servers will not affect the overall query performance, making data query more reliable.
[0053] Optionally, the distribution module is also used to arrange query tasks according to the query target. The process of executing the query task includes: the distribution module divides the query target into at least two data sets, determines the corresponding relationship between each data set and the computing module, and distributes the query task for each data set to the corresponding computing module according to the corresponding relationship; after completing the distributed query task, each computing module sends a notification message to the distribution module on the one hand, and pushes the query result to the aggregation module on the other hand, and the aggregation module aggregates the final query result of the target data and stores it in the cache module; after receiving the notification message from all computing modules, the distribution module obtains the query result of the target data from the cache module. The distribution module orchestrates query tasks, including the functions of each module in the process of executing the query tasks (such as distribution function, aggregation function, query function, and caching function), the timing of each module executing the corresponding function (for example, the distribution module can only obtain the query results for the target data after receiving the notification messages from all computing modules, and the aggregation module can only aggregate after receiving the query results pushed by all computing modules), the message transmission direction between modules (for example, each computing module sends a notification message to the distribution module, and each computing module pushes the query results to the aggregation module), and the size of the memory or computing resources occupied by each module.
[0054] A data query method provided in this embodiment improves the efficiency of data query by distributing the query target to multiple computing modules, and each computing module queries the corresponding target data according to the distributed query target and the mapping relationship, and realizes millisecond-level response for real-time query of massive data in the scenario where the data is not landed; in addition, the distribution module performs global query task scheduling for each module, and after the queries of all computing modules are completed, the aggregation module aggregates the query results of each computing module to ensure the reliability of concurrent queries.
[0055] Embodiment 2
[0056] Figure 3 A flow chart of a data query method provided for the second embodiment of the present disclosure is provided. Based on the first embodiment, the second embodiment specifies the process of concurrent query of each computing module. In this embodiment, the computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target, including: the computing module divides the distributed query target into at least two data sets, and establishes a query thread for each data set; the computing module accesses the cache module through each of the query threads to query the target data corresponding to each data set.
[0057] For details not yet provided in this embodiment, please refer to Embodiment 1.
[0058] like Figure 3As shown, a data query method provided in Embodiment 2 of the present disclosure includes the following steps:
[0059] S210. The distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources.
[0060] S220: The computing module divides the distributed query target into at least two data sets, and establishes a query thread for each data set.
[0061] In this embodiment, the computing modules perform concurrent queries, and each computing module can further divide the distributed query targets into multiple data sets, establish multiple query threads, and the query threads can also perform concurrent queries, further improving query efficiency.
[0062] S230: The computing module accesses the cache module through each query thread to query the target data corresponding to each data set.
[0063] Exemplarily, the query targets distributed to computing module 3 are customer identifiers c6, c7, and c8. Each customer identifier can be taken as a data set, and three query threads can be established. The three query threads can be used to call the external interface to access the cache module. Query thread 1 can be used to query the target data corresponding to c6 from the data stored in department B, query thread 2 can be used to query the target data corresponding to c7, and query thread 3 can be used to query the target data corresponding to c8.
[0064] S240: The aggregation module aggregates the query results of each computing module on the target data.
[0065] In this embodiment, the query result for the target data is obtained by aggregating the query results of each query thread of each computing module. Optionally, each computing module pushes the query results of each query thread to the aggregation module, and the aggregation module performs aggregation; or, each computing module first performs a first round of aggregation on the query results of each query thread, pushes the results of the first round of aggregation to the aggregation module, and then the aggregation module performs a second round of aggregation on the aggregated results pushed by each computing module to obtain the final query result. Aggregation includes summarizing, sorting, modifying, filtering, classifying or marking the query results pushed by each computing module.
[0066] In one embodiment, the computing module queries the target data corresponding to the query target, including: the computing module queries the target data corresponding to the query target according to the reverse mapping index corresponding to the query target, wherein the reverse mapping index is established according to the mapping relationship between the query target and the target data.
[0067] Specifically, there is a mapping relationship between the query target and the target data, and the mapping relationship can be represented by a reverse mapping index. The reverse mapping index, also known as a reverse index or an inverted index, is used to reflect the storage position of each field of the target data in the business data. The reverse mapping index can be established by a cache module that stores the target data. For example, the cache module establishes a data model based on the mapping relationship between databases or data tables of different data sources. In the data model, the reverse mapping index is equivalent to an intermediate field, which is used to associate data with large differences in different businesses, different data contents, different storage structures or different data sources. When the calculation module queries the corresponding target data for the distributed query target, it is based on the reverse mapping index. For example, the query target distributed to the calculation module 3 is customer identification c6, c7 and c8, and the target data to be queried is the account balance. Then, according to the reverse mapping index corresponding to c6, c7 and c8, the calculation module 3 can read the account balances at the corresponding positions in the business data stored by the B department respectively as the query results corresponding to c6, c7 and c8.
[0068] It should be noted that when querying the account balance field in the business data stored in Department B, if there are 100 pages of business data, 10 of which store the account balance field, then using the forward index, all 100 pages need to be scanned to obtain 10 of them and read the account balance, and then filter or sort, etc. The reverse mapping index records all storage locations of the account balance field in the business data stored in Department B. Using the reverse mapping index, the account balance field can be quickly located, so as to read the account balance corresponding to the query target, thereby improving query efficiency.
[0069] In one embodiment, the query mode of the computing module for the target data is a paging query. Specifically, when the target data is directly queried, it is easy to cause the deep paging query to be unavailable, resulting in the failure of the query task, paging errors, and even server crashes. For example, there are usually tens of thousands of target data, and the paging length may be only 50 or 100. Since the full amount of target data needs to be queried, the conventional paging length cannot meet the computing requirements for a large amount of target data. However, under the premise of decomposing the query task and distributing the query target to different computing modules, the present embodiment can adopt the paging query mode. For example, a computing module only needs to query the corresponding 500-800 target data according to the query target distributed, and the remaining thousands of data to be queried are distributed to other computing modules for query. For the computing module, the corresponding target data can be queried according to the preset paging length (for example, 50), which greatly reduces the computational complexity of each computing module, making the paging query more efficient and the system performance more stable.
[0070] A data query method provided in the second embodiment of the present disclosure allows concurrent queries between computing modules, and each computing module can use multiple query threads for concurrent queries, and an aggregation module aggregates the query results of each query thread of each computing module, thereby improving query efficiency; in addition, by establishing a reverse mapping index across data sources, business data of different departments can be connected, thereby achieving efficient query across data sources in a scenario where data is not landed.
[0071] Embodiment 3
[0072] Figure 4 A flow chart of a data query method provided for the third embodiment of the present disclosure. Based on the above embodiments, the third embodiment specifies the concurrent query process and the query result aggregation process. In this embodiment, each computing module uses multiple query threads for concurrent query, and then the computing module aggregates the query results of each query thread, and then the aggregation module aggregates the query results of each computing module, thereby improving the efficiency and stability of concurrent query.
[0073] In this embodiment, the computing module accesses the cache module through each query thread to query the target data corresponding to each data set, including: the computing module accesses the cache module through each query thread to query the first number of target data in the sorted target data corresponding to each data set, and obtains the first query result of each query thread respectively; the computing module summarizes the first query results of each query thread, and queries the second number of target data in the sorted target data in the summarized first query results of each query thread, and obtains the second query result of the computing module.
[0074] In this embodiment, the aggregation module aggregates the query results of each computing module for the target data, including: the aggregation module summarizes the second query results of each computing module, and sets a number of target data in the sorted target data in the summarized second query results of each computing module to obtain the query results for the target data.
[0075] For details not yet provided in this embodiment, please refer to the above embodiments.
[0076] like Figure 4 As shown, a data query method provided in Embodiment 3 of the present disclosure includes the following steps:
[0077] S310, the distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources.
[0078] S320: The computing module divides the distributed query target into at least two data sets, and establishes a query thread for each data set.
[0079] S330. The calculation module accesses the cache module through each query thread to query a first number of target data in the sorted target data corresponding to each data set, and obtains a first query result of each query thread respectively.
[0080] The query in this embodiment mainly refers to TOP-K query, that is, finding K target data from the business data sorted according to the set rules. In addition, by dividing the query target into at least two data sets and establishing a query thread, not only can the global query task be distributed to each computing module, but the query task distributed to each computing module can also be further decomposed into multiple subtasks, and multiple subtasks can be executed asynchronously, thereby realizing concurrent queries between multiple computing modules and multiple threads, and improving query efficiency.
[0081] For example, query the K customers with the highest (or lowest) account balance. For example, take a calculation module as an example, the calculation module is distributed to 10 customer identifiers, which can be divided into three data sets and three query threads are established. Each query thread queries the account balance of the customer identifier in the corresponding data set, and selects the first number (for example, 2) of account balances with the highest account balance as the first query result of the query thread. Then, the calculation module obtains three first query results, which can include up to 2*3=6 account balances.
[0082] S340: The calculation module aggregates the first query results of each query thread, and searches for a second number of target data in the sorted target data in the aggregated first query results of each query thread to obtain a second query result of the calculation module.
[0083] In this embodiment, the calculation module summarizes the first query results of each query thread, and performs a TOP-K query on the summarized first query results again to obtain a second query result. For example, the above-mentioned calculation module summarizes three first query results, including a maximum of 6 account balances, and queries the second number (for example, 4) of account balances with the highest account balances as the second query result of the calculation module. Similarly, each calculation module can obtain the second number of target data in each of the summarized first query results as its corresponding second query result. On this basis, m calculation modules can obtain a maximum of 4*m account balances.
[0084] S350, the aggregation module aggregates the second query results of each computing module, and sets a number of target data in the sorted target data in the aggregated second query results of each computing module to obtain a query result for the target data.
[0085] In this embodiment, the aggregation module aggregates the second query results of each calculation module, and performs a TOP-K query on the aggregated second query results again to obtain the final query result for the target data. For example, the aggregation module queries the account balances of a set number (K) of the highest account balances among the above 4*m account balances as the final query result for the target data.
[0086] It should be noted that if the multi-channel concurrent query results of each computing module and each thread are directly aggregated, in the case of large data computing volume, memory overflow, garbage collection (Full GC) jams and other problems are likely to occur. In this embodiment, each computing module first performs a first round of aggregation on the query results of its query threads, and then the aggregation module performs a second round of aggregation on the aggregation results pushed by each computing module to obtain the final query results. The aggregation task can be divided into multiple subtasks, which can solve the above problems, improve aggregation efficiency and data query efficiency, and ensure the stability of system functions.
[0087] A data query method provided in the third embodiment of the present disclosure distributes the query target to multiple computing modules and establishes multiple query threads to decompose the global query task, and then aggregates the query results of each query thread and the query results of each computing module to achieve multi-way concurrent sub-sorting and global sorting based on the completed sub-sorting, thereby improving query efficiency and stability.
[0088] Embodiment 4
[0089] Figure 5 A flow chart of a data query method provided for the fourth embodiment of the present disclosure. Based on the above embodiments, the fourth embodiment specifies the process of determining the query target and distributing the query target. In this embodiment, before the distribution module distributes the query target to at least two computing modules, it also includes: the distribution module receives the query request; the distribution module extracts the query target from the cache module according to the query request, and the query target includes data that has changed within a set time period.
[0090] In this embodiment, after the calculation module queries the target data corresponding to the query target, it also includes: the calculation module pushes the query timestamp of the target data to the cache module; wherein the query timestamp is used by the distribution module to determine the query target.
[0091] For details not yet provided in this embodiment, please refer to the above embodiments.
[0092] like Figure 5 As shown, a data query method provided in Embodiment 3 of the present disclosure includes the following steps:
[0093] S410: The distribution module receives a query request.
[0094] In this embodiment, the query request may be initiated by the client through the query client, and the query request may include a target field and a condition field, etc.
[0095] S420: The distribution module extracts a query target from the cache module according to the query request, where the query target includes data that has changed within a set time period.
[0096] In this embodiment, the query target includes data that has changed within a set time period, which can also be understood as querying active customer IDs. For example, to query the account balances of customers whose account balances have changed within 24 hours, the distribution module only needs to select customer IDs that have been read, sorted, modified, filtered, classified or marked within 24 hours (the latest query timestamp corresponding to the customer ID or target data is within 24 hours before the current time) as the query target. The account balances of other customers have not been operated within 24 hours and do not need to be queried.
[0097] S430: The distribution module distributes the query target to at least two computing modules according to the mapping relationship between the query target and the target data and in accordance with the load balancing strategy and / or routing strategy.
[0098] In this embodiment, the query target can be distributed to at least two computing modules according to the load balancing strategy; the query target can also be distributed to at least two computing modules according to the routing strategy, and it is ensured that the target data corresponding to the same query target is queried by the same computing module. For example, when querying a customer's account balance and consumption records, the query of the account balance and consumption records of the same customer is executed by the same computing module.
[0099] Specifically, query targets are distributed according to the load balancing strategy, with the aim of making the number of query targets carried by each computing module roughly equal, or limiting the standard deviation, variance, etc. of the number of query targets carried by each computing module within a predetermined range, so as to efficiently utilize the computing resources of each computing module. This can avoid the query speed of some computing modules (or some threads in the computing modules) being too slow and thus slowing down the overall query speed, and can also avoid the problem of some computing modules having idle resources and some computing modules occupying too much resources, thereby fully ensuring query efficiency and system performance.
[0100] The purpose of distributing query targets according to the routing strategy is to ensure that the target data corresponding to the same query target is queried by the same computing module. For example, when querying the account balances and consumption records of customers with customer identifiers c1-c8, the account balance and consumption records of c1 are queried by the same computing module, avoiding assigning query operations for the same customer to different computing modules, thereby simplifying the query process, reducing the amount of calculation, facilitating the distribution and aggregation of query tasks, and improving the stability of queries.
[0101] Routing strategies include consistent hash routing strategy and modulo routing strategy. The consistent hash routing strategy can distribute consistent query tasks to the same computing module, and play a role in load balancing, making full use of buffer space. In addition, when distributing new query tasks, it can minimize changes to distributed query tasks and improve the stability of query task scheduling. Similarly, using the modulo routing strategy, query targets can also be regularly and evenly distributed to different computing modules in turn, improving the stability of query task scheduling.
[0102] S440: The computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target.
[0103] S450: The aggregation module aggregates the query results of each computing module on the target data.
[0104] S460: The calculation module pushes the query timestamp of the target data to the cache module.
[0105] In this embodiment, after each call to the external interface to query the target data, the calculation module also pushes the query timestamp of the target data to the cache module, and the cache module records the latest time when the target data is queried, which is convenient for management and tracing. In addition, the query timestamp can also be used by the distribution module to determine the query target, for example, the customer identifier whose query timestamp of the target data is within 24 hours before the current time (queried within 24 hours) is used as the query target, and the data of inactive customers does not need to be queried, thereby improving the query efficiency.
[0106] A data query method provided in the fourth embodiment of the present disclosure distributes query targets according to the load balancing strategy, which can efficiently utilize the computing resources of each computing module and avoid the situation where some computing modules have idle resources and some computing modules have excessively occupied resources, thus affecting system performance; query targets are distributed according to the routing strategy, which can simplify the query process, reduce the amount of calculation, facilitate the distribution and aggregation of query tasks, and improve the stability of queries; query targets can be selected by recording query timestamps, and there is no need to query the data of inactive customers, thereby improving query efficiency.
[0107] Embodiment 5
[0108] Figure 6A structural diagram of a data query system provided for the fifth embodiment of the present disclosure. The system can be applicable to the situation where target data from different data sources are queried. Specifically, it is applicable to the situation where the target data corresponding to the query target group is queried in the scenario where the data is not landed. Among them, the query includes reading the corresponding target data for the query target, and can also include sorting, modifying, filtering, classifying, recording the query timestamp and other operations on the read target data according to the query conditions. The data query system includes a distribution module, a cache module, a calculation module and an aggregation module. Among them, the number of various modules can be one or more, and the function of each module can be implemented based on one or more servers, and the functions of different modules can also be implemented by the same server.
[0109] like Figure 6 As shown, the data query system includes: a distribution module 510, a calculation module 520, a cache module 530 and an aggregation module 540; the cache module 530 is used to store query targets and target data; the distribution module 510 is used to distribute the query targets to at least two calculation modules 520, wherein there is a mapping relationship between the query targets and the target data, and the query targets and the target data are data from different data sources; the calculation module 520 is used to access the cache module 530 according to the distributed query targets to query the target data corresponding to the query targets; the aggregation module 540 is used to aggregate the query results of each calculation module 520 on the target data.
[0110] The above technical solution improves the efficiency of data query by distributing the query target to different computing modules, and each computing module queries the corresponding target data according to the distributed query target and mapping relationship, and realizes efficient query of target data in scenarios where data is not landed.
[0111] Figure 7 This is a schematic diagram of a data query process provided by Embodiment 5 of the present disclosure. Figure 7 As shown in the figure, the data query process includes:
[0112] 1. The distribution module receives a query request, which includes 8 query targets: c1, c2, c3, c4, c5, c6, c7, c8;
[0113] 2. The distribution module reads the query timestamp in the cache module according to the query request, and determines that the query timestamps of c2, c6, and c7 have not changed within the set time period, so there is no need to send query tasks downstream. The rest need real-time queries, so c1, c3, c4, c5, and c8 are used as query targets;
[0114] 3. The distribution module divides c1, c3, c4, c5, and c8 into three groups according to the load balancing strategy and / or routing strategy, and distributes them to different computing modules respectively, where c1 and c3 are distributed to computing module 1, c4 is distributed to computing module 2, and c5 and c8 are distributed to computing module 3;
[0115] 4. Each computing module queries concurrently through each query thread. Taking computing module 1 as an example, a query thread is established for c1 and c3 respectively, and the external interface is concurrently called to access the cache module to obtain the first query result corresponding to each query thread respectively. The first query results are aggregated to obtain the second query result of computing module 1. Similarly, the second query result of computing module 2 and the second query result of computing module 3 can be obtained.
[0116] 5. Push the second query results of each calculation module to the aggregation module, which aggregates and further queries to obtain the query results for the target data. For example, the query result for the target data of c5 is: the account balance is 1300;
[0117] 6: The calculation module pushes the query timestamp of the target data to the cache module to update the query timestamp of each query target. For example, the query timestamp of the target data of c2 is 202001291954;
[0118] 7. The computing module sends a middleware message (Message Queue, MQ) to notify the distribution module that the data query has been completed;
[0119] 8. The distribution module calls the aggregation module to obtain global or partial query results based on the Remote Dictionary Server (Redis). Redis is a key-value based storage system that supports reading or writing a large number of query results.
[0120] The data query system of this embodiment can meet the requirements of efficient, real-time, and global query of massive, non-local target data, and is scalable. With the increase of active accounts, target data to be queried, and query conditions, the demand for massive target data query can be met by simply increasing the number of computing modules. The distribution module can automatically distribute query targets and arrange query tasks. In addition, the number of various types of servers can be expanded, and the failure of some servers will not affect the overall performance, which has higher reliability.
[0121] Optionally, the calculation module 520 queries the target data corresponding to the query target, including:
[0122] The calculation module 520 searches for target data corresponding to the query target according to a reverse mapping index corresponding to the query target, wherein the reverse mapping index is established according to a mapping relationship between the query target and the target data.
[0123] Optionally, the computing module 520 accesses the cache module 530 according to the distributed query target to query the target data corresponding to the query target, including:
[0124] The calculation module 520 divides the distributed query target into at least two data sets, and establishes a query thread for each data set;
[0125] The calculation module 520 accesses the cache module 530 through each query thread to query the target data corresponding to each data set.
[0126] Optionally, the computing module 520 accesses the cache module 530 through each query thread to query the target data corresponding to each data set, including:
[0127] The calculation module 520 accesses the cache module 530 through each query thread to query a first number of target data in the sorted target data corresponding to each data set, and obtains a first query result of each query thread respectively;
[0128] The calculation module 520 aggregates the first query results of each query thread, and searches for a second number of target data in the sorted target data in the aggregated first query results of each query thread to obtain a second query result of the calculation module 520 .
[0129] Optionally, the aggregation module 540 aggregates the query results of each calculation module 520 on the target data, including:
[0130] The aggregation module 540 aggregates the second query results of each calculation module 520 , and sets a number of target data in the sorted target data in the aggregated second query results of each calculation module 520 , to obtain a query result for the target data.
[0131] Optionally, the distribution module 510 distributes the query target to at least two computing modules 520, including:
[0132] The distribution module 510 distributes the query target to at least two computing modules 520 according to the mapping relationship between the query target and the target data and in accordance with the load balancing strategy.
[0133] Optionally, the distribution module 510 distributes the query target to at least two computing modules 520, including:
[0134] The distribution module 510 distributes the query target to at least two calculation modules 520 according to the mapping relationship between the query target and the target data and in accordance with the routing strategy, wherein the target data corresponding to the same query target is queried by the same calculation module 520;
[0135] The routing strategy includes at least one of the following: a consistent hash routing strategy and a modulo routing strategy.
[0136] Optionally, before the distribution module 510 distributes the query target to the at least two computing modules 520, the method further includes:
[0137] The distribution module 510 receives the query request;
[0138] The distribution module 510 extracts a query target from the cache module 530 according to the query request, and the query target includes data that has changed within a set time period.
[0139] Optionally, after the calculation module 520 queries the target data corresponding to the query target, the method further includes:
[0140] The calculation module 520 pushes the query timestamp of the target data to the cache module 530;
[0141] The query timestamp is used by the distribution module 510 to determine the query target.
[0142] The above data query system can execute the data query method provided by any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method. For the contents not yet fully described in this embodiment, please refer to the above embodiment.
[0143] According to one or more embodiments of the present disclosure, Example 1 provides a data query method, including:
[0144] The distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources;
[0145] The computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target;
[0146] The aggregation module aggregates the query results of the calculation modules on the target data.
[0147] According to one or more embodiments of the present disclosure, Example 2 According to the method described in Example 1, the computing module queries the target data corresponding to the query target, including:
[0148] The calculation module queries the target data corresponding to the query target according to the reverse mapping index corresponding to the query target, wherein the reverse mapping index is established according to the mapping relationship between the query target and the target data.
[0149] According to one or more embodiments of the present disclosure, Example 3 is based on the method described in Example 1, wherein the computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target, including:
[0150] The computing module divides the distributed query target into at least two data sets, and establishes a query thread for each data set;
[0151] The calculation module accesses the cache module through each query thread to query the target data corresponding to each data set.
[0152] According to one or more embodiments of the present disclosure, Example 4 is the method according to Example 3, wherein the computing module accesses the cache module through each query thread to query the target data corresponding to each data set, including:
[0153] The computing module accesses the cache module through each query thread to query a first number of target data in the sorted target data corresponding to each data set, and obtains first query results of each query thread respectively;
[0154] The calculation module aggregates the first query results of each of the query threads, and searches for a second number of target data in the sorted target data in the aggregated first query results of each of the query threads to obtain a second query result of the calculation module.
[0155] According to one or more embodiments of the present disclosure, Example 5, according to the method described in Example 4, the aggregation module aggregates the query results of each computing module on the target data, including:
[0156] The aggregation module aggregates the second query results of each of the calculation modules, and sets a number of target data in the sorted target data in the aggregated second query results of each of the calculation modules to obtain the query result for the target data.
[0157] According to one or more embodiments of the present disclosure, Example 6, according to the method described in Example 1, the distribution module distributes the query target to at least two computing modules, including:
[0158] The distribution module distributes the query target to at least two computing modules according to the mapping relationship between the query target and the target data and the load balancing strategy.
[0159] According to one or more embodiments of the present disclosure, Example 7, according to the method described in Example 1, wherein the distribution module distributes the query target to at least two computing modules, includes:
[0160] The distribution module distributes the query target to at least two computing modules according to the mapping relationship between the query target and the target data and the routing strategy, wherein the target data corresponding to the same query target is queried by the same computing module;
[0161] The routing strategy includes at least one of the following: a consistent hash routing strategy and a modulo routing strategy.
[0162] According to one or more embodiments of the present disclosure, Example 8 is the method according to Example 1, before the distribution module distributes the query target to at least two computing modules, further comprising:
[0163] The distribution module receives the query request;
[0164] The distribution module extracts the query target from the cache module according to the query request, and the query target includes data that has changed within a set time period.
[0165] According to one or more embodiments of the present disclosure, Example 9 is a method according to Example 1, and after the calculation module queries the target data corresponding to the query target, further includes:
[0166] The calculation module pushes the query timestamp of the target data to the cache module;
[0167] The query timestamp is used by the distribution module to determine the query target.
[0168] According to one or more embodiments of the present disclosure, Example 10 provides a data query system, including: a distribution module, a calculation module, a cache module, and an aggregation module;
[0169] The cache module is used to store query targets and target data;
[0170] The distribution module is used to distribute the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, and the query target and the target data are data from different data sources;
[0171] The computing module is used to access the cache module according to the distributed query target to query the target data corresponding to the query target;
[0172] The aggregation module is used to aggregate the query results of the calculation modules on the target data.
[0173] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
Claims
1. A data query method, characterized in that: include: The distribution module distributes the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, the query target and the target data are data from different data sources, the query target is data containing fields stored in the current database or data table, and the target data refers to data to be queried in a data source different from the current database or data table; The computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target, and the data sources of the target data targeted by the query targets of different computing modules are the same; The aggregation module aggregates the query results of the calculation modules on the target data.
2. The method according to claim 1, characterized in that The calculation module queries the target data corresponding to the query target, including: The calculation module queries the target data corresponding to the query target according to the reverse mapping index corresponding to the query target, wherein the reverse mapping index is established according to the mapping relationship between the query target and the target data.
3. The method according to claim 1, characterized in that The computing module accesses the cache module according to the distributed query target to query the target data corresponding to the query target, including: The computing module divides the distributed query target into at least two data sets, and establishes a query thread for each data set; The calculation module accesses the cache module through each query thread to query the target data corresponding to each data set.
4. The method according to claim 3, characterized in that The computing module accesses the cache module through each query thread to query the target data corresponding to each data set, including: The computing module accesses the cache module through each query thread to query a first number of target data in the sorted target data corresponding to each data set, and obtains first query results of each query thread respectively; The calculation module aggregates the first query results of each of the query threads, and searches for a second number of target data in the sorted target data in the aggregated first query results of each of the query threads to obtain a second query result of the calculation module.
5. The method according to claim 4, characterized in that The aggregation module aggregates the query results of each computing module on the target data, including: The aggregation module aggregates the second query results of each of the calculation modules, and sets a number of target data in the sorted target data in the aggregated second query results of each of the calculation modules to obtain the query result for the target data.
6. The method according to claim 1, characterized in that The distribution module distributes the query target to at least two computing modules, including: The distribution module distributes the query target to at least two computing modules according to the mapping relationship between the query target and the target data and the load balancing strategy.
7. The method according to claim 1, characterized in that The distribution module distributes the query target to at least two computing modules, including: The distribution module distributes the query target to at least two computing modules according to the mapping relationship between the query target and the target data and the routing strategy, wherein the target data corresponding to the same query target is queried by the same computing module; The routing strategy includes at least one of the following: a consistent hash routing strategy and a modulo routing strategy.
8. The method according to claim 1, characterized in that Before the distribution module distributes the query target to at least two computing modules, the method further includes: The distribution module receives the query request; The distribution module extracts the query target from the cache module according to the query request, and the query target includes data that has changed within a set time period.
9. The method according to claim 8, characterized in that After the calculation module queries the target data corresponding to the query target, the method further includes: The calculation module pushes the query timestamp of the target data to the cache module; The query timestamp is used by the distribution module to determine the query target.
10. A data query system, characterized in that: include: Distribution module, calculation module, cache module and aggregation module; The cache module is used to store query targets and target data; The distribution module is used to distribute the query target to at least two computing modules, wherein there is a mapping relationship between the query target and the target data, the query target and the target data are data from different data sources, the query target is data containing fields stored in the current database or data table, and the target data refers to data to be queried in a data source different from the current database or data table; The computing module is used to access the cache module according to the distributed query target to query the target data corresponding to the query target, and the data source of the target data targeted by the query targets of different computing modules is the same; The aggregation module is used to aggregate the query results of the calculation modules on the target data.
Citation Information
Patent Citations
Cross-data-source query method, apparatus and system
CN106570022A
Parallel query method and apparatus based on multi-data-source scene
CN106599310A
Data query method, apparatus and system
CN106959963A
Data query method, device and system
CN109656930A
Data query method and device
CN110909022A
