## org.apache.mahout.cf.taste.impl.model.hbase
Class HBaseDataModel

    java.lang.Object
      org.apache.mahout.cf.taste.impl.model.hbase.HBaseDataModel

All Implemented Interfaces:
  Closeable, Serializable, Refreshable, DataModel

    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).

See Also:
  Serialized Form

Constructor Summary
`HBaseDataModel(org.apache.hadoop.hbase.client.HTablePool pool, String tableName, org.apache.hadoop.conf.Configuration conf)`
`HBaseDataModel(String zkConnect)`
`HBaseDataModel(String zkConnect, String tableName)`

Method Summary
`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)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HBaseDataModel

    public HBaseDataModel(String zkConnect)
                   throws IOException

Throws:
  `IOException`

### HBaseDataModel

    public HBaseDataModel(String zkConnect,
                          String tableName)
                   throws IOException

Throws:
  `IOException`

### HBaseDataModel

    public HBaseDataModel(org.apache.hadoop.hbase.client.HTablePool pool,
                          String tableName,
                          org.apache.hadoop.conf.Configuration conf)
                   throws IOException

Throws:
  `IOException`

Method Detail

### getTableName

    public String getTableName()

### getUserIDs

    public LongPrimitiveIterator getUserIDs()

  Specified by:
    `getUserIDs` in interface `DataModel`

### getPreferencesFromUser

    public PreferenceArray getPreferencesFromUser(long userID)
                                           throws TasteException

  Specified by:
    `getPreferencesFromUser` in interface `DataModel`
  Throws:
    `TasteException`

### getItemIDsFromUser

    public FastIDSet getItemIDsFromUser(long userID)
                                 throws TasteException

  Specified by:
    `getItemIDsFromUser` in interface `DataModel`
  Throws:
    `TasteException`

### getItemIDs

    public LongPrimitiveIterator getItemIDs()

  Specified by:
    `getItemIDs` in interface `DataModel`

### getPreferencesForItem

    public PreferenceArray getPreferencesForItem(long itemID)
                                          throws TasteException

  Specified by:
    `getPreferencesForItem` in interface `DataModel`
  Throws:
    `TasteException`

### getPreferenceValue

    public Float getPreferenceValue(long userID,
                                    long itemID)
                             throws TasteException

  Specified by:
    `getPreferenceValue` in interface `DataModel`
  Throws:
    `TasteException`

### getPreferenceTime

    public Long getPreferenceTime(long userID,
                                  long itemID)
                           throws TasteException

  Specified by:
    `getPreferenceTime` in interface `DataModel`
  Throws:
    `TasteException`

### getNumItems

    public int getNumItems()

  Specified by:
    `getNumItems` in interface `DataModel`

### getNumUsers

    public int getNumUsers()

  Specified by:
    `getNumUsers` in interface `DataModel`

### getNumUsersWithPreferenceFor

    public int getNumUsersWithPreferenceFor(long itemID)
                                     throws TasteException

  Specified by:
    `getNumUsersWithPreferenceFor` in interface `DataModel`
  Throws:
    `TasteException`

### getNumUsersWithPreferenceFor

    public int getNumUsersWithPreferenceFor(long itemID1,
                                            long itemID2)
                                     throws TasteException

  Specified by:
    `getNumUsersWithPreferenceFor` in interface `DataModel`
  Throws:
    `TasteException`

### setPreference

    public void setPreference(long userID,
                              long itemID,
                              float value)
                       throws TasteException

  Specified by:
    `setPreference` in interface `DataModel`
  Throws:
    `TasteException`

### removePreference

    public void removePreference(long userID,
                                 long itemID)
                          throws TasteException

  Specified by:
    `removePreference` in interface `DataModel`
  Throws:
    `TasteException`

### hasPreferenceValues

    public boolean hasPreferenceValues()

  Specified by:
    `hasPreferenceValues` in interface `DataModel`

### getMaxPreference

    public float getMaxPreference()

  Specified by:
    `getMaxPreference` in interface `DataModel`

### getMinPreference

    public float getMinPreference()

  Specified by:
    `getMinPreference` in interface `DataModel`

### close

    public void close()
               throws IOException

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`

### refresh

    public void refresh(Collection<Refreshable> alreadyRefreshed)

  Specified by:
    `refresh` in interface `Refreshable`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.