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
IOException
public HBaseDataModel(String zkConnect, String tableName) throws IOException
IOException
public HBaseDataModel(org.apache.hadoop.hbase.client.HTablePool pool, String tableName, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
public String getTableName()
public LongPrimitiveIterator getUserIDs()
getUserIDs
in interface DataModel
public PreferenceArray getPreferencesFromUser(long userID) throws TasteException
getPreferencesFromUser
in interface DataModel
TasteException
public FastIDSet getItemIDsFromUser(long userID) throws TasteException
getItemIDsFromUser
in interface DataModel
TasteException
public LongPrimitiveIterator getItemIDs()
getItemIDs
in interface DataModel
public PreferenceArray getPreferencesForItem(long itemID) throws TasteException
getPreferencesForItem
in interface DataModel
TasteException
public Float getPreferenceValue(long userID, long itemID) throws TasteException
getPreferenceValue
in interface DataModel
TasteException
public Long getPreferenceTime(long userID, long itemID) throws TasteException
getPreferenceTime
in interface DataModel
TasteException
public int getNumItems()
getNumItems
in interface DataModel
public int getNumUsers()
getNumUsers
in interface DataModel
public int getNumUsersWithPreferenceFor(long itemID) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public int getNumUsersWithPreferenceFor(long itemID1, long itemID2) throws TasteException
getNumUsersWithPreferenceFor
in interface DataModel
TasteException
public void setPreference(long userID, long itemID, float value) throws TasteException
setPreference
in interface DataModel
TasteException
public void removePreference(long userID, long itemID) throws TasteException
removePreference
in interface DataModel
TasteException
public boolean hasPreferenceValues()
hasPreferenceValues
in interface DataModel
public float getMaxPreference()
getMaxPreference
in interface DataModel
public float getMinPreference()
getMinPreference
in interface DataModel
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void refresh(Collection<Refreshable> alreadyRefreshed)
refresh
in interface Refreshable
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.