public final class HBaseDataModel extends Object implements DataModel, Closeable
Naive approach of storing one preference as one value in the table. Preferences are indexed as (user, item) and (item, user) for O(1) lookups.
The default table name is "taste", this can be set through a constructor argument. Each row has a value starting with "i" or "u" followed by the actual id encoded as a big endian long.
E.g., "u\x00\x00\x00\x00\x00\x00\x04\xd2" is user 1234L
There are two column families: "users" and "items".
The "users" column family holds user->item preferences. Each userID is the column qualifier and the value is the preference.
The "items" column fmaily holds item->user preferences. Each itemID is the column qualifier and the value is the preference.
User IDs and item IDs are cached in a FastIDSet since it requires a full table scan to build these sets. Preferences are not cached since they are pretty cheap lookups in HBase (also caching the Preferences defeats the purpose of a scalable storage engine like HBase).
| Constructor and Description |
|---|
HBaseDataModel(org.apache.hadoop.hbase.client.HTablePool pool,
String tableName,
org.apache.hadoop.conf.Configuration conf) |
HBaseDataModel(String zkConnect) |
HBaseDataModel(String zkConnect,
String tableName) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
LongPrimitiveIterator |
getItemIDs() |
FastIDSet |
getItemIDsFromUser(long userID) |
float |
getMaxPreference() |
float |
getMinPreference() |
int |
getNumItems() |
int |
getNumUsers() |
int |
getNumUsersWithPreferenceFor(long itemID) |
int |
getNumUsersWithPreferenceFor(long itemID1,
long itemID2) |
PreferenceArray |
getPreferencesForItem(long itemID) |
PreferenceArray |
getPreferencesFromUser(long userID) |
Long |
getPreferenceTime(long userID,
long itemID) |
Float |
getPreferenceValue(long userID,
long itemID) |
String |
getTableName() |
LongPrimitiveIterator |
getUserIDs() |
boolean |
hasPreferenceValues() |
void |
refresh(Collection<Refreshable> alreadyRefreshed) |
void |
removePreference(long userID,
long itemID) |
void |
setPreference(long userID,
long itemID,
float value) |
public HBaseDataModel(String zkConnect) throws IOException
IOExceptionpublic HBaseDataModel(String zkConnect, String tableName) throws IOException
IOExceptionpublic HBaseDataModel(org.apache.hadoop.hbase.client.HTablePool pool,
String tableName,
org.apache.hadoop.conf.Configuration conf)
throws IOException
IOExceptionpublic String getTableName()
public LongPrimitiveIterator getUserIDs()
getUserIDs in interface DataModelpublic PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser in interface DataModelTasteExceptionpublic FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser in interface DataModelTasteExceptionpublic LongPrimitiveIterator getItemIDs()
getItemIDs in interface DataModelpublic PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem in interface DataModelTasteExceptionpublic Float getPreferenceValue(long userID, long itemID) throws TasteException
getPreferenceValue in interface DataModelTasteExceptionpublic Long getPreferenceTime(long userID, long itemID) throws TasteException
getPreferenceTime in interface DataModelTasteExceptionpublic int getNumItems()
getNumItems in interface DataModelpublic int getNumUsers()
getNumUsers in interface DataModelpublic int getNumUsersWithPreferenceFor(long itemID)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelTasteExceptionpublic int getNumUsersWithPreferenceFor(long itemID1,
long itemID2)
throws TasteException
getNumUsersWithPreferenceFor in interface DataModelTasteExceptionpublic void setPreference(long userID,
long itemID,
float value)
throws TasteException
setPreference in interface DataModelTasteExceptionpublic void removePreference(long userID,
long itemID)
throws TasteException
removePreference in interface DataModelTasteExceptionpublic boolean hasPreferenceValues()
hasPreferenceValues in interface DataModelpublic float getMaxPreference()
getMaxPreference in interface DataModelpublic float getMinPreference()
getMinPreference in interface DataModelpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void refresh(Collection<Refreshable> alreadyRefreshed)
refresh in interface RefreshableCopyright © 2008–2013 The Apache Software Foundation. All rights reserved.