Java 类org.apache.hadoop.hbase.filter.BinaryPrefixComparator 实例源码

项目:ditb    文件:ScannerModel.java   
public ByteArrayComparableModel(
    ByteArrayComparable comparator) {
  String typeName = comparator.getClass().getSimpleName();
  ComparatorType type = ComparatorType.valueOf(typeName);
  this.type = typeName;
  switch (type) {
    case BinaryComparator:
    case BinaryPrefixComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      break;
    case BitComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      this.op = ((BitComparator)comparator).getOperator().toString();
      break;
    case NullComparator:
      break;
    case RegexStringComparator:
    case SubstringComparator:
      this.value = Bytes.toString(comparator.getValue());
      break;
    default:
      throw new RuntimeException("unhandled filter type: " + type);
  }
}
项目:HIndex    文件:ScannerModel.java   
public ByteArrayComparableModel(
    ByteArrayComparable comparator) {
  String typeName = comparator.getClass().getSimpleName();
  ComparatorType type = ComparatorType.valueOf(typeName);
  this.type = typeName;
  switch (type) {
    case BinaryComparator:
    case BinaryPrefixComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      break;
    case BitComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      this.op = ((BitComparator)comparator).getOperator().toString();
      break;
    case NullComparator:
      break;
    case RegexStringComparator:
    case SubstringComparator:
      this.value = Bytes.toString(comparator.getValue());
      break;
    default:
      throw new RuntimeException("unhandled filter type: " + type);
  }
}
项目:hbase    文件:ScannerModel.java   
public ByteArrayComparableModel(
    ByteArrayComparable comparator) {
  String typeName = comparator.getClass().getSimpleName();
  ComparatorType type = ComparatorType.valueOf(typeName);
  this.type = typeName;
  switch (type) {
    case BinaryComparator:
    case BinaryPrefixComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      break;
    case BitComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      this.op = ((BitComparator)comparator).getOperator().toString();
      break;
    case NullComparator:
      break;
    case RegexStringComparator:
    case SubstringComparator:
      this.value = Bytes.toString(comparator.getValue());
      break;
    default:
      throw new RuntimeException("unhandled filter type: " + type);
  }
}
项目:PyroDB    文件:ScannerModel.java   
public ByteArrayComparableModel(
    ByteArrayComparable comparator) {
  String typeName = comparator.getClass().getSimpleName();
  ComparatorType type = ComparatorType.valueOf(typeName);
  this.type = typeName;
  switch (type) {
    case BinaryComparator:
    case BinaryPrefixComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      break;
    case BitComparator:
      this.value = Base64.encodeBytes(comparator.getValue());
      this.op = ((BitComparator)comparator).getOperator().toString();
      break;
    case NullComparator:
      break;
    case RegexStringComparator:
    case SubstringComparator:
      this.value = Bytes.toString(comparator.getValue());
      break;
    default:
      throw new RuntimeException("unhandled filter type: " + type);
  }
}
项目:pinpoint    文件:HbaseApplicationTraceIndexDao.java   
/**
 * make the hbase filter for selecting values of y-axis(response time) in order to select transactions in scatter chart.
 * 4 bytes for elapsed time should be attached for the prefix of column qualifier for to use this filter.
 *
 * @param area
 * @param offsetTransactionId
 * @param offsetTransactionElapsed
 * @return
 */
private Filter makeResponseTimeFilter(final SelectedScatterArea area, final TransactionId offsetTransactionId, int offsetTransactionElapsed) {
    // filter by response time
    ResponseTimeRange responseTimeRange = area.getResponseTimeRange();
    byte[] responseFrom = Bytes.toBytes(responseTimeRange.getFrom());
    byte[] responseTo = Bytes.toBytes(responseTimeRange.getTo());
    FilterList filterList = new FilterList(Operator.MUST_PASS_ALL);
    filterList.addFilter(new QualifierFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(responseFrom)));
    filterList.addFilter(new QualifierFilter(CompareOp.LESS_OR_EQUAL, new BinaryPrefixComparator(responseTo)));

    // add offset
    if (offsetTransactionId != null) {
        final Buffer buffer = new AutomaticBuffer(32);
        buffer.putInt(offsetTransactionElapsed);
        buffer.putPrefixedString(offsetTransactionId.getAgentId());
        buffer.putSVLong(offsetTransactionId.getAgentStartTime());
        buffer.putVLong(offsetTransactionId.getTransactionSequence());
        byte[] qualifierOffset = buffer.getBuffer();

        filterList.addFilter(new QualifierFilter(CompareOp.GREATER, new BinaryPrefixComparator(qualifierOffset)));
    }
    return filterList;
}
项目:pentaho-hadoop-shims    文件:CommonHBaseConnectionTest.java   
@Test
public void testAddColumnFilterToScanCompareOpNull() throws Exception {
  ColumnFilter cf = new ColumnFilter( "Family" );
  cf.setConstant( "123" );
  cf.setSignedComparison( true );

  HBaseValueMeta meta = new HBaseValueMeta( "colFamly,colname,Family", 1, 20, 1 );
  meta.setIsLongOrDouble( true );
  VariableSpace space = mockVariableSpace();
  connectionSpy.m_sourceScan = new Scan();
  doReturn( null ).when( connectionSpy ).getCompareOpByComparisonType( any( ColumnFilter.ComparisonType.class ) );

  connectionSpy.addColumnFilterToScan( cf, meta, space, true );
  FilterList filter = (FilterList) connectionSpy.m_sourceScan.getFilter();
  assertFalse( filter.getFilters().isEmpty() );
  Assert.assertEquals( filter.getFilters().size(), 1 );
  Assert.assertEquals( BinaryPrefixComparator.class,
    ( (CompareFilter) filter.getFilters().get( 0 ) ).getComparator().getClass() );
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getRecommendedUserItem(String cp, String collection, long user, Long from, Long startDate,
        Long endDate, int size)
{
    FilterList filters = new FilterList();

    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getStatRecommendedItemKey(
                collection, user))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatRecommendedItemKey(collection, user, from))));
    }

    setDateLimit(STATS_RECOMMENDED_USERITEM, startDate, endDate, filters);

    Scan scan = new Scan().addFamily(STATS_RECOMMENDED_USERITEM).setFilter(filters);

    return getResults(cp, scan, STATS_RECOMMENDED_USERITEM, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getUserRated(String cp, String collection, Long from, Long startDate, Long endDate, int size)
{
    // Put put = new Put(RowKeys.getStatRatingsPerItemKey(collection, item, date));
    Scan scan = new Scan();
    scan.addFamily(STATS_USER_RATINGS);
    FilterList filters = new FilterList();
    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatRatingsPerUserKey(collection))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatRatingsPerUserKey(collection, from.longValue()))));
    }

    setDateLimit(STATS_USER_RATINGS, startDate, endDate, filters);

    scan.setFilter(filters);

    return getResults(cp, scan, STATS_USER_RATINGS, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getItemRated(String cp, String collection, Long from, Long startDate, Long endDate, int size)
{
    // Put put = new Put(RowKeys.getStatRatingsPerItemKey(collection, item, date));
    Scan scan = new Scan();
    scan.addFamily(STATS_ITEM_RATINGS);
    FilterList filters = new FilterList();
    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatRatingsPerItemKey(collection))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatRatingsPerItemKey(collection, from.longValue()))));
    }

    setDateLimit(STATS_ITEM_RATINGS, startDate, endDate, filters);

    scan.setFilter(filters);

    return getResults(cp, scan, STATS_ITEM_RATINGS, size);
}
项目:zieook    文件:StatisticsTable.java   
/**
 * return the list of content providers
 * @param cp
 * @param recommender
 * @return
 * @throws IOException
 * @see nl.gridline.zieook.statistics.SourcesByRecommenderMap
 * @see nl.gridline.zieook.statistics.SourcesByRecommenderReduce
 */
public List<GroupedData> getSources(String cp, String recommender, String from, Long startDate, Long endDate,
        int size)
{
    Scan scan = new Scan();
    scan.addFamily(STATS_VIEWED_SOURCE);
    FilterList filters = new FilterList();

    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatSourcesKey(recommender))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatSourcesKey(recommender, from))));
    }

    setDateLimit(STATS_VIEWED_SOURCE, startDate, endDate, filters);

    scan.setFilter(filters);

    return getResults(cp, scan, STATS_VIEWED_SOURCE, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getViewed(String cp, String recommender, Long from, Long startDate, Long endDate, int size)
{
    Scan scan = new Scan();
    scan.addFamily(STATS_VIEWED_ITEM);

    FilterList filters = new FilterList();

    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatViewedKey(recommender))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getStatViewedKey(
                recommender, from.longValue()))));
    }

    setDateLimit(STATS_VIEWED_ITEM, startDate, endDate, filters);

    scan.setFilter(filters);

    return getResults(cp, scan, STATS_VIEWED_ITEM, size);
}
项目:zieook    文件:EventLogTable.java   
public long deleteViews(String cp, String recommender)
{
    FilterList filters = new FilterList();

    // filter column-family & recommender name
    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EVENTLOG_COLUMN_USERVIEW)));
    filters
            .addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getUserViewKey(recommender))));

    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_USERVIEW).setFilter(filters);

    // TODO put this in a map-reduce delete.. that executes in background..
    // we only need to pass the table & a scan object. should be quite easy

    long count = deleteAll(scan, cp, EVENTLOG_COLUMN_RECOMMENDED);

    return count;
}
项目:zieook    文件:StatisticsTool.java   
/**
 * return a recommended scanner with an optional start date and end date
 * @param startDate start date
 * @param endDate end date
 * @return
 */
public Scan getEventLogRecommendedScanner(Long startDate, Long endDate)
{
    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_RECOMMENDED);
    FilterList filters = new FilterList();
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRecommendedItemKey())));
    // timestamp filter:
    if (startDate != null)
    {
        SingleColumnValueFilter startFilter = new SingleColumnValueFilter(EVENTLOG_COLUMN_RECOMMENDED,
                ModelConstants.TIMESTAMP, CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(startDate.longValue()));
        startFilter.setFilterIfMissing(true);
        filters.addFilter(startFilter);
    }

    if (endDate != null)
    {
        SingleColumnValueFilter endFilter = new SingleColumnValueFilter(EVENTLOG_COLUMN_RECOMMENDED,
                ModelConstants.TIMESTAMP, CompareOp.LESS, Bytes.toBytes(endDate.longValue()));
        endFilter.setFilterIfMissing(true);
        filters.addFilter(endFilter);
    }

    return scan.setFilter(filters);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getTopRecommended(String cp, String collection, long user, Long startDate, Long endDate,
        int size)
{

    FilterList filters = new FilterList();
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getStatRecommendedItemKey(
            collection, user))));
    setDateLimit(STATS_RECOMMENDED_USERITEM, startDate, endDate, filters);

    Scan scan = new Scan().addFamily(STATS_RECOMMENDED_USERITEM).setFilter(filters);

    return getSortedResults(cp, scan, STATS_RECOMMENDED_USERITEM, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getRecommendedUser(String cp, String collection, long user, Long startDate, Long endDate,
        int size)
{
    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
            .getStatRecommendedKey(collection, user))));
    setDateLimit(STATS_RECOMMENDED_USER, startDate, endDate, filters);
    Scan scan = new Scan().addFamily(STATS_RECOMMENDED_USER).setFilter(filters);
    return getResults(cp, scan, STATS_RECOMMENDED_USER, size);
}
项目:zieook    文件:StatisticsTable.java   
/**
 * @param cp
 * @param collection
 * @param from
 * @param startDate
 * @param endDate
 * @param size
 * @return
 */
public List<GroupedData> getCollectionSources(String cp, String collection, String from, Long startDate,
        Long endDate, Integer size)
{

    Scan scan = new Scan().addFamily(STATS_COLLECTION_SOURCE);

    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
            .getStatSourcesCollectionKey(collection))));

    if (from == null)
    {
        filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatSourcesCollectionKey(collection))));
    }
    else
    {
        filters.addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(RowKeys
                .getStatSourcesCollectionKey(collection, from))));
    }

    setDateLimit(STATS_COLLECTION_SOURCE, startDate, endDate, filters);

    scan.setFilter(filters);

    return getResults(cp, scan, STATS_COLLECTION_SOURCE, size);
}
项目:zieook    文件:CollectionViewsTable.java   
private FilterList getItemFilter(String collection, String regexp, Set<Long> items)
{

    // Filter on the given items (this is an OR filter on the rows)
    FilterList itemFilter = new FilterList(Operator.MUST_PASS_ONE);
    for (long i : items)
    {
        // row filter is probably faster, (don't know for sure) - otherwise single column-value filter is also
        // possible.
        itemFilter.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryComparator(RowKeys.getCollectionKey(collection,
                i))));

    }

    FilterList filters = new FilterList();
    // filter on collection:
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes(collection))));
    // filter on items:
    filters.addFilter(itemFilter);

    SingleColumnValueFilter value = new SingleColumnValueFilter(COLUMN_INTR, ModelConstants.TITLE, CompareOp.EQUAL,
            new RegexStringComparator(regexp));

    value.setFilterIfMissing(true);
    filters.addFilter(value);

    return filters;

}
项目:zieook    文件:CollectionTable.java   
/**
 * Return the first 100 collection items for the given content provider and collection
 * @param cp content provider name
 * @param collection collection name
 * @return list of collection items
 */
public List<CollectionItem> getItems(String cp, String collection, int size)
{
    Filter filter = new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes(collection)));
    Scan scan = new Scan().addFamily(COLUMN_INTR).setFilter(filter);
    return getItems(cp, scan, size);

}
项目:zieook    文件:CollectionTable.java   
public List<CollectionItem> searchItems(String cp, String collection, String regexTitle, int size)
{
    FilterList filters = new FilterList();

    filters
            .addFilter(new RowFilter(CompareOp.GREATER_OR_EQUAL, new BinaryPrefixComparator(Bytes.toBytes(collection))));
    SingleColumnValueFilter value = new SingleColumnValueFilter(COLUMN_INTR, ModelConstants.TITLE, CompareOp.EQUAL,
            new RegexStringComparator(regexTitle));
    value.setFilterIfMissing(true);
    filters.addFilter(value);

    Scan scan = new Scan().addFamily(COLUMN_INTR).setFilter(filters);
    return getItems(cp, scan, size);
}
项目:zieook    文件:CollectionTable.java   
/**
 * Return the 100 collection items starting from <tt>item</tt>
 * @param cp content provider name
 * @param collection collection name
 * @param item id
 * @return return list of collection items
 */
public List<CollectionItem> getItems(String cp, String collection, long item, int size)
{
    Scan scan = new Scan(RowKeys.getCollectionKey(collection, item)).addFamily(COLUMN_INTR);
    Filter filter = new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes(collection)));
    scan.setFilter(filter);
    return getItems(cp, scan, size);
}
项目:zieook    文件:CollectionTable.java   
/**
 * @param cp
 * @param collection
 */
public void deleteCollection(String cp, String collection)
{
    FilterList filters = new FilterList();
    filters
            .addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getCollectionKey(collection))));

    Scan scan = new Scan().addFamily(COLUMN_INTR).setFilter(filters);
    deleteAll(scan, cp, COLUMN_INTR);

    scan = new Scan().addFamily(COLUMN_RAW).setFilter(filters);
    deleteAll(scan, cp, COLUMN_RAW);

}
项目:zieook    文件:ContentProviderTable.java   
public List<ContentProvider> getContentProviders()
{
    List<ContentProvider> providers = new LinkedList<ContentProvider>();

    Scan scan = new Scan();
    scan.addFamily(COLUMN_CONTENTPROVIDER);
    scan.setFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(CONTENT_PRIVIDER_BYTES)));

    try
    {
        HTableInterface tableInterface = table.getTable();
        ResultScanner scanner = tableInterface.getScanner(scan);
        try
        {
            Result result = null;
            while ((result = scanner.next()) != null)
            {
                providers.add(new ContentProvider(result.getFamilyMap(COLUMN_CONTENTPROVIDER)));
            }
        }
        finally
        {
            scanner.close();
            table.putTable(tableInterface);
        }
    }
    catch (IOException e)
    {
        LOG.error("Error while getting content providers.", e);
    }

    return providers;
}
项目:zieook    文件:EventLogTable.java   
public long deleteViews(String cp, String recommender, long user)
{
    FilterList filters = new FilterList();
    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EVENTLOG_COLUMN_USERVIEW)));
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getUserViewKey(recommender,
            user))));
    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_USERVIEW).setFilter(filters);
    return deleteAll(scan, cp, EVENTLOG_COLUMN_USERVIEW);
}
项目:zieook    文件:EventLogTable.java   
public long deleteView(String cp, String recommender, long user, Long startDate, Long endDate)
{
    FilterList filters = new FilterList();
    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EVENTLOG_COLUMN_USERVIEW)));
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getUserViewKey(recommender,
            user))));
    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_USERVIEW).setFilter(filters);
    return deleteAll(scan, cp, EVENTLOG_COLUMN_USERVIEW);
}
项目:zieook    文件:EventLogTable.java   
public long deleteRecommend(String cp, String recommender)
{
    FilterList filters = new FilterList();

    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EVENTLOG_COLUMN_RECOMMENDED)));
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
            .getRecommendedItemKey(recommender))));

    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_RECOMMENDED).setFilter(filters);
    return deleteAll(scan, cp, EVENTLOG_COLUMN_RECOMMENDED);
}
项目:zieook    文件:EventLogTable.java   
public long deleteRecommend(String cp, String recommender, long user)
{
    FilterList filters = new FilterList();

    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EVENTLOG_COLUMN_RECOMMENDED)));
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRecommendedItemKey(
            recommender, user))));

    Scan scan = new Scan().addFamily(EVENTLOG_COLUMN_RECOMMENDED).setFilter(filters);
    return deleteAll(scan, cp, EVENTLOG_COLUMN_RECOMMENDED);
}
项目:zieook    文件:UserTable.java   
/**
 * delete all ratings for a given {@code user} in a {@code collection}
 * @param cp content provider
 * @param collection collection
 * @param user user id
 */
public void deleteRatings(String cp, String collection, long user)
{
    RowFilter filter = new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRatingKey(collection,
            user)));
    Scan scan = new Scan().addFamily(COLUMN_RATING).setFilter(filter);
    long count = deleteAll(scan, cp, COLUMN_RATING);
    decRating(cp, collection, user, count);
}
项目:zieook    文件:UserTable.java   
/**
 * delete all ratings for a given collection
 * @param cp
 * @param collection
 */
public void deleteRatings(String cp, String collection)
{
    FilterList filters = new FilterList();
    // create a filter:

    filters.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(COLUMN_RATING)));
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRatingKey(collection))));

    Scan scan = new Scan().addFamily(COLUMN_RATING).setFilter(filters);
    deleteAll(scan, cp, COLUMN_RATING);

    // TODO hm... this will fuck up the rating count of a user... & needs a fix - track the users... do a batch
    // decrease on them or something
}
项目:zieook    文件:StatisticsTool.java   
/**
 * return a rating scanner
 * @param collection - collection name
 * @param startDate - optional start date
 * @param endDate - optional end date
 * @return a scanner
 */
public Scan getRatingsScanner(String collection, Long startDate, Long endDate)
{
    final FilterList filter = new FilterList();

    // filter on collection:
    filter.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRatingKey())));

    // set start date if given:
    if (startDate != null)
    {
        final SingleColumnValueFilter startTime = new SingleColumnValueFilter(USERTABLE_COLUMN_RATING,
                ModelConstants.TIMESTAMP, CompareOp.GREATER_OR_EQUAL, new BinaryComparator(Bytes.toBytes(startDate
                        .longValue())));
        startTime.setFilterIfMissing(true);

        filter.addFilter(startTime);
    }

    // set end date if given:
    if (endDate != null)
    {
        final SingleColumnValueFilter endTime = new SingleColumnValueFilter(USERTABLE_COLUMN_RATING,
                ModelConstants.TIMESTAMP, CompareOp.LESS, new BinaryComparator(Bytes.toBytes(endDate.longValue())));
        endTime.setFilterIfMissing(true);

        filter.addFilter(endTime);
    }

    return new Scan().addFamily(USERTABLE_COLUMN_RATING).setFilter(filter);
}
项目:zieook    文件:StatisticsTool.java   
/**
 * create a scanner for user views, within optional start / end range
 * @return a scanner object
 * @throws IOException
 */
public Scan getEventLogViewScanner(Long startDate, Long endDate)
{
    FilterList filters = new FilterList();

    // row prefix filter:
    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getUserViewKey())));

    // timestamp filter:
    if (startDate != null)
    {
        SingleColumnValueFilter startFilter = new SingleColumnValueFilter(EVENTLOG_COLUMN_USERVIEW,
                ModelConstants.TIMESTAMP, CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(startDate.longValue()));
        startFilter.setFilterIfMissing(true);
        filters.addFilter(startFilter);
    }

    if (endDate != null)
    {
        SingleColumnValueFilter endFilter = new SingleColumnValueFilter(EVENTLOG_COLUMN_USERVIEW,
                ModelConstants.TIMESTAMP, CompareOp.LESS, Bytes.toBytes(endDate.longValue()));
        endFilter.setFilterIfMissing(true);
        filters.addFilter(endFilter);
    }

    return new Scan().addFamily(EVENTLOG_COLUMN_USERVIEW).setFilter(filters);
}
项目:zieook    文件:DataPrepareTool.java   
/**
 * Return a scanner for rating column in the user table. Also filters on
 * @return
 * @throws IOException
 */
private Scan getUserDataScanner() throws IOException
{
    String collection = getConf().get(TaskConfig.COLLECTION);
    if (collection == null)
    {
        // fail!
        throw new IOException("collection not set");
    }
    RowFilter filter = new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRatingKey(collection)));
    Scan result = new Scan().addFamily(COLUMN_RATING).setFilter(filter);

    return result;
}
项目:zieook    文件:FreeTextVectorizeTool.java   
public Scan getInputScanner()
{
    Scan scan = new Scan();
    RowFilter filter = new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes(collection)));
    scan.setFilter(filter);
    return scan;
}
项目:incubator-omid    文件:TestUpdateScan.java   
@Test(timeOut = 10_000)
public void testGet(ITestContext context) throws Exception {
    try {
        TransactionManager tm = newTransactionManager(context);
        TTable table = new TTable(hbaseConf, TEST_TABLE);
        Transaction t = tm.begin();
        int[] lInts = new int[]{100, 243, 2342, 22, 1, 5, 43, 56};
        for (int i = 0; i < lInts.length; i++) {
            byte[] data = Bytes.toBytes(lInts[i]);
            Put put = new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t, put);
        }
        int startKeyValue = lInts[3];
        int stopKeyValue = lInts[3];
        byte[] startKey = Bytes.toBytes(startKeyValue);
        byte[] stopKey = Bytes.toBytes(stopKeyValue);
        Get g = new Get(startKey);
        Result r = table.get(t, g);
        if (!r.isEmpty()) {
            int tmp = Bytes.toInt(r.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL)));
            LOG.info("Result:" + tmp);
            assertTrue(tmp == startKeyValue, "Bad value, should be " + startKeyValue + " but is " + tmp);
        } else {
            Assert.fail("Bad result");
        }
        tm.commit(t);

        Scan s = new Scan(startKey);
        CompareFilter.CompareOp op = CompareFilter.CompareOp.LESS_OR_EQUAL;
        RowFilter toFilter = new RowFilter(op, new BinaryPrefixComparator(stopKey));
        boolean startInclusive = true;
        if (!startInclusive) {
            FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
            filters.addFilter(new RowFilter(CompareFilter.CompareOp.GREATER, new BinaryPrefixComparator(startKey)));
            filters.addFilter(new WhileMatchFilter(toFilter));
            s.setFilter(filters);
        } else {
            s.setFilter(new WhileMatchFilter(toFilter));
        }
        t = tm.begin();
        ResultScanner res = table.getScanner(t, s);
        Result rr;
        int count = 0;
        while ((rr = res.next()) != null) {
            int iTmp = Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL)));
            LOG.info("Result: " + iTmp);
            count++;
        }
        assertEquals(count, 1, "Count is wrong");
        LOG.info("Rows found " + count);
        tm.commit(t);
        table.close();
    } catch (Exception e) {
        LOG.error("Exception in test", e);
    }
}
项目:pinpoint    文件:HbaseTraceDaoV2.java   
public QualifierFilter createSpanQualifierFilter() {
    byte indexPrefix = SpanEncoder.TYPE_SPAN;
    BinaryPrefixComparator prefixComparator = new BinaryPrefixComparator(new byte[] {indexPrefix});
    QualifierFilter qualifierPrefixFilter = new QualifierFilter(CompareFilter.CompareOp.EQUAL, prefixComparator);
    return qualifierPrefixFilter;
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getRatedTop(String cp, String collection, Long startDate, Long endDate, int size)
{

    Scan scan = new Scan();
    scan.addFamily(STATS_ITEM_RATINGS);
    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
            .getStatRatingsPerItemKey(collection))));

    setDateLimit(STATS_ITEM_RATINGS, startDate, endDate, filters);

    scan.setFilter(filters);

    return getSortedResults(cp, scan, STATS_ITEM_RATINGS, size);
}
项目:zieook    文件:StatisticsTable.java   
/**
 * @param cp
 * @param collection
 * @param startTime
 * @param endTime
 * @param size
 * @return
 */
public List<GroupedData> getCollectionTopSources(String cp, String collection, Long startDate, Long endDate, int size)
{
    Scan scan = new Scan().addFamily(STATS_COLLECTION_SOURCE);

    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
            .getStatSourcesCollectionKey(collection))));

    setDateLimit(STATS_COLLECTION_SOURCE, startDate, endDate, filters);

    scan.setFilter(filters);

    return getSortedResults(cp, scan, STATS_COLLECTION_SOURCE, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<GroupedData> getTopSources(String cp, String recommender, Long startDate, Long endDate, int size)
{

    Scan scan = new Scan();
    scan.addFamily(STATS_VIEWED_SOURCE);

    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys
            .getStatSourcesKey(recommender))));

    setDateLimit(STATS_VIEWED_SOURCE, startDate, endDate, filters);

    scan.setFilter(filters);

    // use a scanner, and add only if map.size < size

    return getSortedResults(cp, scan, STATS_VIEWED_SOURCE, size);
}
项目:zieook    文件:StatisticsTable.java   
/**
 * @param cp
 * @param recommender
 * @param startDate
 * @param endDate
 * @param size
 * @return
 */
public List<GroupedData> getTopViewed(String cp, String recommender, Long startDate, Long endDate, int size)
{
    Scan scan = new Scan();
    scan.addFamily(STATS_VIEWED_ITEM);

    FilterList filters = new FilterList();

    filters.addFilter(new RowFilter(CompareOp.EQUAL,
            new BinaryPrefixComparator(RowKeys.getStatViewedKey(recommender))));

    setDateLimit(STATS_VIEWED_ITEM, startDate, endDate, filters);

    scan.setFilter(filters);

    // use a scanner, and add only if map.size < size

    return getSortedResults(cp, scan, STATS_VIEWED_ITEM, size);
}
项目:zieook    文件:StatisticsTable.java   
public List<Popularity> getPopularity(String cp, String collection, String name, Long startItem, int size)
{
    // create a scanner / filter:
    Scan scan;
    if (startItem != null)
    {
        scan = new Scan(RowKeys.getStatsPopularity(name, collection, startItem.longValue()));
    }
    else
    {
        scan = new Scan();
    }
    scan.setFilter(
            new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getStatsPopularity(name, collection))))
            .addFamily(STATS_ITEM_POPULARITY);

    // list data:
    List<Popularity> result = new ArrayList<Popularity>();
    try
    {
        HTableInterface tableInterface = table.getTable(cp);
        ResultScanner scanner = tableInterface.getScanner(scan);
        try
        {
            Result[] scanResult = scanner.next(size);
            for (Result r : scanResult)
            {
                result.add(new Popularity(r.getFamilyMap(STATS_ITEM_POPULARITY)));
            }
        }
        finally
        {
            scanner.close();
            table.putTable(tableInterface);
        }
    }
    catch (IOException e)
    {
        LOG.error("failed to get result", e);
        return null;
    }

    return result;

}
项目:zieook    文件:CollectionViewsTable.java   
public List<Rating> searchRatings(String cp, String collection, long user, Long startItem, String regexp, int size)
{
    List<Rating> result = new ArrayList<Rating>();

    byte[] start;
    if (startItem != null)
    {
        start = RowKeys.getRatingKey(collection, user, startItem.longValue());
    }
    else
    {
        start = RowKeys.getRatingKey(collection, user);
    }

    Scan scan = new Scan(start).addFamily(COLUMN_RATING).setFilter(
            new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(RowKeys.getRatingKey(collection, user))));

    SingleColumnValueFilter filter = new SingleColumnValueFilter(COLUMN_INTR, ModelConstants.TITLE, CompareOp.EQUAL,
            new RegexStringComparator(regexp));

    Set<Long> allIds = new HashSet<Long>();
    try
    {
        HTableInterface tableInterface = usersTable.getTable(cp);
        ResultScanner scanner = tableInterface.getScanner(scan);
        try
        {
            Result rr = null;
            while ((rr = scanner.next()) != null)
            {
                // Rating userRating = new Rating(rr.getFamilyMap(COLUMN_RATING));
                byte[] item = rr.getValue(COLUMN_RATING, ModelConstants.ITEM);
                if (item != null)
                {
                    long id = Bytes.toLong(item);
                    if (!allIds.contains(id) && accepts(cp, collection, filter, id))
                    {
                        Rating rating = new Rating(rr.getFamilyMap(COLUMN_RATING));
                        rating.setCp(cp);
                        rating.setCollection(collection);
                        result.add(rating);
                    }
                    allIds.add(id);
                }
                if (result.size() > size)
                {
                    return result.subList(0, size);
                }
            }
        }
        finally
        {
            scanner.close();
            usersTable.putTable(tableInterface);
        }

    }
    catch (IOException e)
    {
        LOG.error("failed to get scanner for request", e);
    }

    return result;
}