I have a telco billing software system. In it there are daily logs of users' calls. The logs are horizontally partitioned by date (month). Each partition is stored in a separate database and may be spread over multiple instances.
我有一个电信计费软件系统。其中包含用户呼叫的每日日志。日志按日期(月)水平分区。每个分区都存储在一个单独的数据库中,可以分布在多个实例上。
In the UI the user will specify a date range. The data returned can be sorted on any field. The date range may span over multiple partitions. The application must support paging through the date range's data.
在UI中,用户将指定日期范围。返回的数据可以在任何字段上排序。日期范围可能跨越多个分区。应用程序必须支持通过日期范围的数据进行分页。
I cannot load too many records into memory for sorting. Putting sort inside the query only gives me sorted data inside one result-set.
我无法将太多记录加载到内存中进行排序。在查询中放置排序只能在一个结果集中给出排序数据。
So I need to sort data from multiple partitions which are each individually sorted. How can I return sorted records to the UI from multiple sorted result-sets?
所以我需要对多个分区中的数据进行排序,每个分区都是单独排序的如何从多个已排序的结果集中将已排序的记录返回到UI?
EDIT: After more analysis on this problem, We have some more inputs. There is requirement of pagination also. Due to this we need to find out one more way to do realtime sorting on multiple resultsets.
编辑:经过对此问题的更多分析,我们有更多的输入。也有分页的要求。因此,我们需要找到一种方法来对多个结果集进行实时排序。
1 个解决方案
#1
2
By relying on ResultSet's ability to load limited data in memory we are able to come up with a solution in Java using Dynamic Comparator. Solution is to take first record from each resultSet and sort it in java and return first element from sorted data.
依靠ResultSet在内存中加载有限数据的能力,我们可以使用Dynamic Comparator提供Java解决方案。解决方案是从每个resultSet获取第一条记录并在java中对其进行排序,并从排序数据中返回第一个元素。
Detailed Solution:
详细解决方案
First we built a program which can give us a dymanic Comparator based on the criteria choosed on the screen.
首先,我们建立了一个程序,可以根据屏幕上选择的标准为我们提供一个动态比较器。
Second We have written one AggregateResultSet wrapper over the DAO which is wrapping over ResultSets from different partitions. Note: these individual ResultSets are already sorted with same criteria. Then AggregateResultSet will be given a dynamic comparator.
第二,我们在DAO上编写了一个AggregateResultSet包装器,它包装了来自不同分区的ResultSet。注意:这些单独的ResultSet已按相同条件排序。然后AggregateResultSet将被赋予动态比较器。
This AggregateResultSet will have a data structure to store first element of each result set initially. It will return the next element on call to next(). This element would be the element which comes first as per dynamicComparator. During next() call, We remove this element from temporary data structure and insert the next element from the same result set in the temporary data structure. This way AggregateResultSet will return data in expected order, by merging/storing/sorting very limited data in Java.
此AggregateResultSet将具有一个数据结构,以初始存储每个结果集的第一个元素。它将在调用next()时返回下一个元素。这个元素将是根据dynamicComparator首先出现的元素。在next()调用期间,我们从临时数据结构中删除此元素,并从临时数据结构中的同一结果集中插入下一个元素。这样,AggregateResultSet将以预期的顺序返回数据,方法是在Java中合并/存储/排序非常有限的数据。
We hope to receive no comparison issues as we have mostly numeric/string data in sorting.
我们希望不会收到任何比较问题,因为我们在排序中主要使用数字/字符串数据。
#1
2
By relying on ResultSet's ability to load limited data in memory we are able to come up with a solution in Java using Dynamic Comparator. Solution is to take first record from each resultSet and sort it in java and return first element from sorted data.
依靠ResultSet在内存中加载有限数据的能力,我们可以使用Dynamic Comparator提供Java解决方案。解决方案是从每个resultSet获取第一条记录并在java中对其进行排序,并从排序数据中返回第一个元素。
Detailed Solution:
详细解决方案
First we built a program which can give us a dymanic Comparator based on the criteria choosed on the screen.
首先,我们建立了一个程序,可以根据屏幕上选择的标准为我们提供一个动态比较器。
Second We have written one AggregateResultSet wrapper over the DAO which is wrapping over ResultSets from different partitions. Note: these individual ResultSets are already sorted with same criteria. Then AggregateResultSet will be given a dynamic comparator.
第二,我们在DAO上编写了一个AggregateResultSet包装器,它包装了来自不同分区的ResultSet。注意:这些单独的ResultSet已按相同条件排序。然后AggregateResultSet将被赋予动态比较器。
This AggregateResultSet will have a data structure to store first element of each result set initially. It will return the next element on call to next(). This element would be the element which comes first as per dynamicComparator. During next() call, We remove this element from temporary data structure and insert the next element from the same result set in the temporary data structure. This way AggregateResultSet will return data in expected order, by merging/storing/sorting very limited data in Java.
此AggregateResultSet将具有一个数据结构,以初始存储每个结果集的第一个元素。它将在调用next()时返回下一个元素。这个元素将是根据dynamicComparator首先出现的元素。在next()调用期间,我们从临时数据结构中删除此元素,并从临时数据结构中的同一结果集中插入下一个元素。这样,AggregateResultSet将以预期的顺序返回数据,方法是在Java中合并/存储/排序非常有限的数据。
We hope to receive no comparison issues as we have mostly numeric/string data in sorting.
我们希望不会收到任何比较问题,因为我们在排序中主要使用数字/字符串数据。