Reputation: 1601
I'm pondering the best way to implement a one to many relationship in HBase.
Say an ACCOUNT has many TRANSACTION(s). Is it better to
a) Add columns to a transactions: column family on the ACCOUNT table, i.e. transactions:1:amount, transactions:2:amount
b) Only store the key(s) of each TRANSACTION relating to an account in in the transactions: column family of ACCOUNT, and do a lookup of each transaction found on a separate TRANSACTION table?
Upvotes: 5
Views: 3017
Reputation: 910
How about having a single column value and use a separator like $ and #. Below is the sample data:
Column Family: Transactions
Column Value: $ transactionID:1#amount:100 $ transactionID:2#amount:200 $ transactionID:3#amount:300
Now you can use $ and # separators to fetch the values and use String arrays to process the data.
Upvotes: 0
Reputation: 1
I guess option (a) would be ok if the only data item that needs to be tracked for Account, is the amount. However, if you need to capture many other data items, I think we'll have to go with option (b) even though it is less efficient than (a)
Upvotes: 0
Reputation: 906
Generally, option a, is the better approach.
This allows you to easily request all the transactions for an account at once. No additional lookup is needed, for each transaction.
There are use cases where option b may be appropriate, such as frequently running queries on all of the transactions.
Upvotes: 5