-
Notifications
You must be signed in to change notification settings - Fork 10
RangeQuery
Another kind of common query is range query. We want to know all our users that aging from 25 to 40, than we construct a QueryRange object, send it to DBTaskCenter, and get the results.
To perform range query, user must turn on LunarMax real-time module. Consult LunarMax for how to do it in detail.
/*
* Step 1: construct a new range query
*/
QueryRange sq = new QueryRange(table, "age", 25, 38);
LFuture<RGQueryResult> results = tc.dispatch(sq);
QueryRange(table, "age", 25, 38) is a LunarBase object consists of a name of column, the starting value and the end value user wants to search. In this example, the column is age, from 25 to 38. As all kinds of queries, send QueryRange to DBTaskCenter, then we have the RGQueryResult of all the satisfying records.
/*
* Step 2: we have a result of type RGQueryResult, which keeps the records
* that drop in the range 25 to 38.
* What we have to do is call its interface fetchRecords(),
* then returns a list of results.
*/
if(results.get().resultCount() >= 0)
{
ArrayList<Record32KBytes> recs = results.get().fetchRecords();
tc.dispatch(new QueryResult(recs));
}
The results is kept in an object of RGQueryResult, whose major interfaces are:
resultCount(): how many results falling into the range;
fetchRecords(): get all the results as a list;
fetchRecords(int top_n): get the top n results;
fetchRecords(int from, int count): paging the results, for rendering them on each page of screen;
This source code is under the package of LCG.Examples, the seventh example. Range query and point query combined together will meet the most of data retrieval requirements. Results get from db storage to main memory, then we can do further analysis on it. To learn how to construct a complex multi-dimensional query, please check out previous sector interpreter pattern.
1 Home
1.1 summary
1.2 System Preparation
1.3 When LunarBase is your best choice
1.4 Benchmark
1.5 Power consumption
2 Data Model And Process
2.1 Why internal big cache
2.2 Memory Management: LunarMMU
2.3 Garbage Collection
2.4 Transaction Log
2.5 JOIN via materialized view
3 Real Time Computation: LunarMax
3.1 In-Memory File System: Memory Estimation
3.2 Configuration
3.3 Use SSD as a cheaper memory
3.4 Data Safety
3.5 HE Server VS. Cluster
3.6 High Availability
4 Create a database
4.1 Three modes
4.2 creation.conf settings
4.3 Table space
4.4 Multiple Instance
4.5 Database Status
4.6 Remove and Restore a table
5 Insertion
5.1 Insert as normal record
5.2 Insert to search engine
6 Query
6.1 Point Query
6.2 Result Handler: register your own event handler
6.3 Interpreter Pattern: complex query conditions
6.4 Range Query
6.5 Full-text Search
6.6 Algebraic Logical Query
8 Deletion
9 Materialized view
9.1 Eventual consistency
9.2 Update
9.3 MVCC in LunarBase
9.4 Easy JOIN via denormalization
9.5 CRUD in view
10 Distributed integration with
10.1 Kafka
10.2 Storm
10.3 Spark
11 Storage: Lunar Virtual File System
13 Roadmap of LunarBase future
15 FAQ