object MergedIndex
purpose of this code:
Sometimes we have two tables (say INR withdraws and BTC withdraws) as below
Table INR withdraws Table BTC withdraws ------------------------------------------- --------------------------------------------
| time | withdrawID | Amount | userID | ... | time | withdrawID | Amount | userID | ...
|------|------------|--------|--------|---- -------|------------|-----------------------
| 23 | wjdejduejd | 34544 | alice | ... | 20 | ecjerjcruc | 146 | alice | ...
| 45 | gtfcnmecnv | 4434 | bob | ... | 29 | roijfoirjf | 444 | carol | ...
| 54 | 4jto4rkmkc | 3444 | alice | ... | 34 | i4jf4jifjj | 3944 | carol | ...
Sometimes we may need a combined table for both INR and BTC withdraws sorted by time and search by max/offset This is not possible with two separate tables
The MergedIndex object below takes care of this
It provides a "merged table" M with the above two tables as "left-half" and "right-half" of that table
The HalfTable encapsulates each half table
case class HalfTable(db:DBManager, indexCol:Col, priKeyCol:Col, filterCol:Col, wheres:Where*){
If sorting by time, then indexCol will be time. Each table should have a primary key column that can be uniqely used to reference a row Finally the filterCol is the one we will use to filter the results by (say userID). Each half table is declared using the above rule.
The resulying MergedTable M will appear like this --------------------------------------
indexCol | priKeyCol | filterCol |
---|---|---|
23 | wjdejduejd | alice |
45 | gtfcnmecnv | bob |
54 | 4jto4rkmkc | alice |
20 | ecjerjcruc | alice |
29 | roijfoirjf | carol |
34 | i4jf4jifjj | carol |
When giving a from-to search query (possibly with a filter on userID), the resulting output will be a (nested query) representing the set of ids from the priKeyCol that can be used to search the original tables
so suppose if we search for time =< 30 and time >= 20 in decreasing order, the the getPriKeys will return a nested query that returns the following keys
ecjerjcruc (corresponding to indexCol 20) wjdejduejd (corresponding to indexCol 23) roijfoirjf (corresponding to indexCol 29)
similarly if we search for time =< 30 and time >= 20 in decreasing order with filter == "alice", the the getPriKeys will return a nested query that returns the following keys
ecjerjcruc (corresponding to indexCol 20) wjdejduejd (corresponding to indexCol 23)
** A Nested query is an "lazy query", i.e., a query exactly like a normal query except that it has not yet been run. However, when it will run, it will return the above data. Examples of nested queries:
SELECT amount FROM T1, (SELECT ID FROM .. AS T2) where T1.ID = T2.ID
OR
SELECT amount FROM T1 where T1.ID IN (SELECT ID FROM T2)
In both examples the value inside ( ) is a nested query
Now suppose M is going to used as a half table in another merged table T (say, transactions), then we can use connectToLeftOf to connect to left of T (we can use connectToRightOf to connect to right)
Then whenever any entry is added to INR withdraws, it will first cause an entry to be added to M and then (through the chaning) to T (Note that we could have done the same thing by manually creating a MergedTable using M and accessing the values (indexCol, priKeyCol, filterCol) of that)
- Alphabetic
- By Inheritance
- MergedIndex
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val LeftHalf: String
- val RightHalf: String
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- val whichHalfCol: Col