-
Notifications
You must be signed in to change notification settings - Fork 10
InterpreterPattern
For complex db queries, we need to manipulate every single query and put the results together. Most popular operations are AND, OR. We need to know all the records satisfying "age=25" AND "payment=600" OR .....
It is an interpreter pattern that we need. The following example is an query with multiple conditions select where age=36 AND payment=600 AND name=Rafael8
/*
* Step1: construct a batch of queries,
* each of them returns an array of records ids for quick processing,
* as we know that fetching the whole long records are time consuming.
*
* It is executed multi-threaded.
*/
/*
* the query is a combination of multiple conditions:
* select where age=36 AND payment=600 AND name=Rafael8
*/
QuerySimpleIDs sq1 = new QuerySimpleIDs("age", "36", 0);
QuerySimpleIDs sq2 = new QuerySimpleIDs("payment", "600", 0);
QuerySimpleIDs sq3 = new QuerySimpleIDs("name", "Rafael8", 0);
LFuture<int[]> ids1 = tc.dispatch(sq1);
LFuture<int[]> ids2 = tc.dispatch(sq2);
LFuture<int[]> ids3 = tc.dispatch(sq3);
LFuture is an internal generic class which is convenient to accept various values returned by task center. In this example it is an array of ids.
OpsStack os = new OpsStack();
/*
* add an nothing-operator just for keeping
* the lengths of ops and candidates the same.
*/
os.addOps(ids1.get(), Ops.NOTHING);
os.addOps(ids2.get(), Ops.AND);
os.addOps(ids3.get(), Ops.AND);
int[] result_ids = os.execute();
/*
* again we use LFuture to accept the return result.
* In this case, it is an array of records.
*/
LFuture<ArrayList<Record32KBytes>> results = tc.dispatch(new QueryRecs(result_ids));
OpsStack pushes data and operations into a stack, and execute them one by one. It is a very simple interpreter. The complete example is Interpreter.
For very big data sets, say 10 million records ids need to computer AND, OR or something else, we have to introduce map-reduce methodology to speed up the procedure. We split 10 million ids to 10 cpu cores, if has, sort them and put the results together. Our advanced topics will do this for you.
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