org.apache.hadoop.hbase.filter.SingleColumnValueFilter Java Examples

The following examples show how to use org.apache.hadoop.hbase.filter.SingleColumnValueFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultHBaseSerde.java    From envelope with Apache License 2.0 6 votes vote down vote up
private FilterList getColumnValueFilters(Row row) {
  FilterList filterList = new FilterList(Operator.MUST_PASS_ALL);
  Set<String> filterColumnNames = Sets.newHashSet(row.schema().fieldNames());
  
  for (Map.Entry<String, ColumnDef> column : columns.entrySet()) {
    if (!column.getValue().cf.equals("rowkey")) {
      if (filterColumnNames.contains(column.getKey())) {
        byte[] value = getColumnValueAsBytes(column.getValue().name, column.getValue().type, row);
        if (value != null) {
          SingleColumnValueFilter columnValueFilter = new SingleColumnValueFilter(
              Bytes.toBytes(column.getValue().cf),
              Bytes.toBytes(column.getValue().name),
              CompareFilter.CompareOp.EQUAL,
              value
          );
          filterList.addFilter(columnValueFilter);
        }
      }
    }
  }
  
  return filterList;
}
 
Example #2
Source File: ActiveMemberRunner.java    From BigDataArchitect with Apache License 2.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList filterList = new FilterList();
    // 定义mapper中需要获取的列名
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_MEMBER_ID, // 会员id
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
            EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION, // 浏览器版本号
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME // 添加一个事件名称获取列,在使用singlecolumnvaluefilter的时候必须指定对应的列是一个返回列
    };
    filterList.addFilter(this.getColumnFilter(columns));
    // 只需要page view事件,所以进行过滤
    filterList.addFilter(new SingleColumnValueFilter(ActiveMemberMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));

    return filterList;
}
 
Example #3
Source File: PageViewRunner.java    From BigDataArchitect with Apache License 2.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList filterList = new FilterList();
    // 只需要pageview事件
    filterList.addFilter(new SingleColumnValueFilter(PageViewMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventLogConstants.EventEnum.PAGEVIEW.alias)));
    // 定义mapper中需要获取的列名
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, // 获取事件名称
            EventLogConstants.LOG_COLUMN_NAME_CURRENT_URL, // 当前url
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
            EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
            EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION // 浏览器版本号
    };
    filterList.addFilter(this.getColumnFilter(columns));

    return filterList;
}
 
Example #4
Source File: HBaseDemo.java    From BigDataArchitect with Apache License 2.0 6 votes vote down vote up
/**
 * 查询某个用户所有的主叫电话(type=1)
 *  某个用户
 *  type=1
 *
 */
@Test
public void getType() throws IOException {
    Scan scan = new Scan();
    //创建过滤器集合
    FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    //创建过滤器
    SingleColumnValueFilter filter1 = new SingleColumnValueFilter(Bytes.toBytes("cf"),Bytes.toBytes("type"),CompareOperator.EQUAL,Bytes.toBytes("1"));
    filters.addFilter(filter1);
    //前缀过滤器
    PrefixFilter filter2 = new PrefixFilter(Bytes.toBytes("15883348450"));
    filters.addFilter(filter2);
    scan.setFilter(filters);
    ResultScanner rss = table.getScanner(scan);
    for (Result rs:rss) {
        System.out.print(Bytes.toString(CellUtil.cloneValue(rs.getColumnLatestCell(Bytes.toBytes("cf"),Bytes.toBytes("dnum")))));
        System.out.print("--"+Bytes.toString(CellUtil.cloneValue(rs.getColumnLatestCell(Bytes.toBytes("cf"),Bytes.toBytes("type")))));
        System.out.print("--"+Bytes.toString(CellUtil.cloneValue(rs.getColumnLatestCell(Bytes.toBytes("cf"),Bytes.toBytes("length")))));
        System.out.println("--"+Bytes.toString(CellUtil.cloneValue(rs.getColumnLatestCell(Bytes.toBytes("cf"),Bytes.toBytes("date")))));
    }
}
 
Example #5
Source File: LocationRunner.java    From BigDataArchitect with Apache License 2.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList list = new FilterList();
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间戳
            EventLogConstants.LOG_COLUMN_NAME_UUID, // 用户id
            EventLogConstants.LOG_COLUMN_NAME_SESSION_ID, // 会话id
            EventLogConstants.LOG_COLUMN_NAME_COUNTRY, // 国家
            EventLogConstants.LOG_COLUMN_NAME_PROVINCE, // 省份
            EventLogConstants.LOG_COLUMN_NAME_CITY, // 城市
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, // 事件名称
    };
    list.addFilter(this.getColumnFilter(columns));
    // 过滤只需要pageview事件
    list.addFilter(new SingleColumnValueFilter(LocationMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));
    return list;
}
 
Example #6
Source File: ActiveMemberRunner.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
  FilterList filterList = new FilterList();
  // 定义mapper中需要获取的列名
  String[] columns = new String[]{EventLogConstants.LOG_COLUMN_NAME_MEMBER_ID, // 会员id
      EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
      EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION, // 浏览器版本号
      EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME
      // 添加一个事件名称获取列,在使用singlecolumnvaluefilter的时候必须指定对应的列是一个返回列
  };
  filterList.addFilter(this.getColumnFilter(columns));
  // 只需要page view事件,所以进行过滤
  filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes(EventLogConstants.EVENT_LOGS_FAMILY_NAME),
      Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL,
      Bytes.toBytes(EventEnum.PAGEVIEW.alias)));

  return filterList;
}
 
Example #7
Source File: PageViewRunner.java    From BigDataPlatform with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
  FilterList filterList = new FilterList();
  // 只需要pageview事件
  filterList.addFilter(
      new SingleColumnValueFilter(Bytes.toBytes(EventLogConstants.EVENT_LOGS_FAMILY_NAME),
          Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL,
          Bytes.toBytes(EventLogConstants.EventEnum.PAGEVIEW.alias)));
  // 定义mapper中需要获取的列名
  String[] columns = new String[]{EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, // 获取事件名称
      EventLogConstants.LOG_COLUMN_NAME_CURRENT_URL, // 当前url
      EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
      EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, // 浏览器名称
      EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION // 浏览器版本号
  };
  filterList.addFilter(this.getColumnFilter(columns));

  return filterList;
}
 
Example #8
Source File: HBaseTest.java    From xxhadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testScan() throws IOException {
	Connection connection = admin.getConnection();
	Table table = connection.getTable(TableName.valueOf("tbl_girls"));
	
	Scan scan = new Scan(Bytes.toBytes("0001"), Bytes.toBytes("0004"));
	// RowKeyFilter
	Filter filter = new PrefixFilter(Bytes.toBytes("000"));
	scan.setFilter(filter);
	
	Filter filter2 = new RowFilter(CompareOp.EQUAL, new SubstringComparator("000"));
	scan.setFilter(filter2);
	
	//BinaryComparator binaryComparator = new BinaryComparator(Bytes.toBytes(29));		
	Filter filter3 = new SingleColumnValueFilter(Bytes.toBytes("base_info"), Bytes.toBytes("age"), CompareOp.GREATER, Bytes.toBytes(29));
	scan.setFilter(filter3);
	
	ResultScanner resultScanner = table.getScanner(scan);
	for (Result result : resultScanner) {
		LOGGER.info(result.toString());
		int value = Bytes.toInt(result.getValue(Bytes.toBytes("base_info"), Bytes.toBytes("age")));
		LOGGER.info(String.valueOf(value));
	}
}
 
Example #9
Source File: RegionsMerger.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
private List<RegionInfo> getOpenRegions(Connection connection, TableName table) throws Exception {
  List<RegionInfo> regions = new ArrayList<>();
  Table metaTbl = connection.getTable(META_TABLE_NAME);
  String tblName = table.getNameAsString();
  RowFilter rowFilter = new RowFilter(CompareOperator.EQUAL,
    new SubstringComparator(tblName+","));
  SingleColumnValueFilter colFilter = new SingleColumnValueFilter(CATALOG_FAMILY,
    STATE_QUALIFIER, CompareOperator.EQUAL, Bytes.toBytes("OPEN"));
  Scan scan = new Scan();
  FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filter.addFilter(rowFilter);
  filter.addFilter(colFilter);
  scan.setFilter(filter);
  try(ResultScanner rs = metaTbl.getScanner(scan)){
    Result r;
    while ((r = rs.next()) != null) {
      RegionInfo region = RegionInfo.parseFrom(r.getValue(CATALOG_FAMILY, REGIONINFO_QUALIFIER));
      regions.add(region);
    }
  }
  return regions;
}
 
Example #10
Source File: AbstractHBaseLogReader.java    From Eagle with Apache License 2.0 6 votes vote down vote up
/**
 * <h2>History</h2>
 * <ul>
 * 	<li><b>Nov 19th, 2014</b>: Fix for out put all qualifiers</li>
 * </ul>
 * @param s1
 * @param filter
 */
protected void workaroundHBASE2198(Scan s1, Filter filter) {
	if (filter instanceof SingleColumnValueFilter) {
		if(this.qualifiers == null){
			s1.addFamily(((SingleColumnValueFilter) filter).getFamily());
		}else {
			s1.addColumn(((SingleColumnValueFilter) filter).getFamily(), ((SingleColumnValueFilter) filter).getQualifier());
		}
		return;
	}
	if (filter instanceof FilterList) {
		for (Filter f : ((FilterList)filter).getFilters()) {
			workaroundHBASE2198(s1, f);
		}
	}
}
 
Example #11
Source File: AbstractHBaseLogReader.java    From eagle with Apache License 2.0 6 votes vote down vote up
/**
 * <h2>History</h2>.
 * <ul>
 * <li><b>Nov 19th, 2014</b>: Fix for out put all qualifiers</li>
 * </ul>
 *
 * @param s1
 * @param filter
 */
protected void workaroundHBASE2198(Scan s1, Filter filter) {
    if (filter instanceof SingleColumnValueFilter) {
        if (this.qualifiers == null) {
            s1.addFamily(((SingleColumnValueFilter)filter).getFamily());
        } else {
            s1.addColumn(((SingleColumnValueFilter)filter).getFamily(),
                         ((SingleColumnValueFilter)filter).getQualifier());
        }
        return;
    }
    if (filter instanceof FilterList) {
        for (Filter f : ((FilterList)filter).getFilters()) {
            workaroundHBASE2198(s1, f);
        }
    }
}
 
Example #12
Source File: IndexLogReader.java    From eagle with Apache License 2.0 6 votes vote down vote up
protected static void workaroundHBASE2198(Get get, Filter filter, byte[][] qualifiers) {
    if (filter instanceof SingleColumnValueFilter) {
        if (qualifiers == null) {
            get.addFamily(((SingleColumnValueFilter)filter).getFamily());
        } else {
            get.addColumn(((SingleColumnValueFilter)filter).getFamily(),
                          ((SingleColumnValueFilter)filter).getQualifier());
        }
        return;
    }
    if (filter instanceof FilterList) {
        for (Filter f : ((FilterList)filter).getFilters()) {
            workaroundHBASE2198(get, f, qualifiers);
        }
    }
}
 
Example #13
Source File: FromClientSideBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected ResultScanner buildScanner(String keyPrefix, String value, Table ht)
  throws IOException {
  // OurFilterList allFilters = new OurFilterList();
  FilterList allFilters = new FilterList(/* FilterList.Operator.MUST_PASS_ALL */);
  allFilters.addFilter(new PrefixFilter(Bytes.toBytes(keyPrefix)));
  SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes
    .toBytes("trans-tags"), Bytes.toBytes("qual2"), CompareOperator.EQUAL, Bytes
    .toBytes(value));
  filter.setFilterIfMissing(true);
  allFilters.addFilter(filter);

  // allFilters.addFilter(new
  // RowExcludingSingleColumnValueFilter(Bytes.toBytes("trans-tags"),
  // Bytes.toBytes("qual2"), CompareOp.EQUAL, Bytes.toBytes(value)));

  Scan scan = new Scan();
  scan.addFamily(Bytes.toBytes("trans-blob"));
  scan.addFamily(Bytes.toBytes("trans-type"));
  scan.addFamily(Bytes.toBytes("trans-date"));
  scan.addFamily(Bytes.toBytes("trans-tags"));
  scan.addFamily(Bytes.toBytes("trans-group"));
  scan.setFilter(allFilters);

  return ht.getScanner(scan);
}
 
Example #14
Source File: TestJoinedScanners.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void runScanner(Table table, boolean slow) throws Exception {
  long time = System.nanoTime();
  Scan scan = new Scan();
  scan.addColumn(cf_essential, col_name);
  scan.addColumn(cf_joined, col_name);

  SingleColumnValueFilter filter = new SingleColumnValueFilter(
      cf_essential, col_name, CompareOperator.EQUAL, flag_yes);
  filter.setFilterIfMissing(true);
  scan.setFilter(filter);
  scan.setLoadColumnFamiliesOnDemand(!slow);

  ResultScanner result_scanner = table.getScanner(scan);
  Result res;
  long rows_count = 0;
  while ((res = result_scanner.next()) != null) {
    rows_count++;
  }

  double timeSec = (System.nanoTime() - time) / 1000000000.0;
  result_scanner.close();
  LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec)
    + " seconds, got " + Long.toString(rows_count/2) + " rows");
}
 
Example #15
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected Scan constructScan(byte[] valuePrefix) throws IOException {
  FilterList list = new FilterList();
  Filter filter = new SingleColumnValueFilter(FAMILY_ZERO, COLUMN_ZERO,
    CompareOperator.EQUAL, new BinaryComparator(valuePrefix));
  list.addFilter(filter);
  if (opts.filterAll) {
    list.addFilter(new FilterAllFilter());
  }
  Scan scan = new Scan().setCaching(opts.caching).setCacheBlocks(opts.cacheBlocks)
      .setAsyncPrefetch(opts.asyncPrefetch).setReadType(opts.scanReadType)
      .setScanMetricsEnabled(true);
  if (opts.addColumns) {
    for (int column = 0; column < opts.columns; column++) {
      byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column);
      scan.addColumn(FAMILY_ZERO, qualifier);
    }
  } else {
    scan.addFamily(FAMILY_ZERO);
  }
  scan.setFilter(list);
  return scan;
}
 
Example #16
Source File: HbaseServiceImpl.java    From searchanalytics-bigdata with MIT License 6 votes vote down vote up
@Override
public List<String> getSearchClicksRowKeysWithValidQueryString() {
	LOG.debug("Checking getSearchClicksRowKeys searchclicks table content!");
	Scan scan = new Scan();
	scan.addFamily(HbaseJsonEventSerializer.COLUMFAMILY_SEARCH_BYTES);
	SingleColumnValueFilter filter = new SingleColumnValueFilter(HbaseJsonEventSerializer.COLUMFAMILY_SEARCH_BYTES, 
			Bytes.toBytes("querystring"), CompareOp.NOT_EQUAL, Bytes.toBytes("jaiblahblah"));
	filter.setFilterIfMissing(true);
	scan.setFilter(filter);
	List<String> rows = hbaseTemplate.find("searchclicks", scan,
			new RowMapper<String>() {
				@Override
				public String mapRow(Result result, int rowNum)
						throws Exception {
					return new String(result.getRow());
				}
			});
	for (String row : rows) {
		LOG.debug("searchclicks table content, Table returned row key: {}", row);
	}
	LOG.debug("Checking getSearchClicksRowKeys searchclicks table content done!");
	return rows;
}
 
Example #17
Source File: ViewUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Check metadata to find all child views for a given table/view
 * @param sysCatOrsysChildLink For older (pre-4.15.0) clients, we look for child links inside SYSTEM.CATALOG,
 *                             otherwise we look for them inside SYSTEM.CHILD_LINK
 * @param tenantId tenantId
 * @param schemaName table schema name
 * @param tableName table name
 * @param timestamp passed client-side timestamp
 * @return true if the given table has at least one child view
 * @throws IOException
 */
public static boolean hasChildViews(Table sysCatOrsysChildLink, byte[] tenantId, byte[] schemaName,
                                    byte[] tableName, long timestamp) throws IOException {
    byte[] key = SchemaUtil.getTableKey(tenantId, schemaName, tableName);
    Scan scan = MetaDataUtil.newTableRowsScan(key, MetaDataProtocol.MIN_TABLE_TIMESTAMP, timestamp);
    SingleColumnValueFilter linkFilter =
            new SingleColumnValueFilter(TABLE_FAMILY_BYTES, LINK_TYPE_BYTES,
                    CompareFilter.CompareOp.EQUAL,
                    LinkType.CHILD_TABLE.getSerializedValueAsByteArray()) {
                // if we found a row with the CHILD_TABLE link type we are done and can
                // terminate the scan
                @Override
                public boolean filterAllRemaining() {
                    return matchedColumn;
                }
            };
    linkFilter.setFilterIfMissing(true);
    scan.setFilter(linkFilter);
    scan.addColumn(TABLE_FAMILY_BYTES, LINK_TYPE_BYTES);
    try (ResultScanner scanner = sysCatOrsysChildLink.getScanner(scan)) {
        Result result = scanner.next();
        return result!=null; 
    }
}
 
Example #18
Source File: JobHistoryService.java    From hraven with Apache License 2.0 6 votes vote down vote up
/**
 * creates a scan for flow data
 * @param rowPrefix - start row prefix
 * @param limit - limit on scanned results
 * @param version - version to match
 * @return Scan
 */
private Scan createFlowScan(byte[] rowPrefix, int limit, String version) {
  Scan scan = new Scan();
  scan.setStartRow(rowPrefix);

  // using a large scanner caching value with a small limit can mean we scan a
  // lot more data than necessary, so lower the caching for low limits
  scan.setCaching(Math.min(limit, defaultScannerCaching));
  // require that all rows match the prefix we're looking for
  Filter prefixFilter = new WhileMatchFilter(new PrefixFilter(rowPrefix));
  // if version is passed, restrict the rows returned to that version
  if (version != null && version.length() > 0) {
    FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    filters.addFilter(prefixFilter);
    filters.addFilter(new SingleColumnValueFilter(Constants.INFO_FAM_BYTES,
        Constants.VERSION_COLUMN_BYTES, CompareFilter.CompareOp.EQUAL,
        Bytes.toBytes(version)));
    scan.setFilter(filters);
  } else {
    scan.setFilter(prefixFilter);
  }
  return scan;
}
 
Example #19
Source File: SingleFieldEntityFilter.java    From kite with Apache License 2.0 6 votes vote down vote up
public SingleFieldEntityFilter(EntitySchema entitySchema,
    EntitySerDe<?> entitySerDe, String fieldName, Object filterValue,
    CompareFilter.CompareOp equalityOperator) {
  FieldMapping fieldMapping = entitySchema.getColumnMappingDescriptor()
      .getFieldMapping(fieldName);
  if (fieldMapping.getMappingType() != MappingType.COLUMN) {
    throw new DatasetException(
        "SingleColumnValueFilter only compatible with COLUMN mapping types.");
  }

  byte[] family = fieldMapping.getFamily();
  byte[] qualifier = fieldMapping.getQualifier();
  byte[] comparisonBytes = entitySerDe.serializeColumnValueToBytes(fieldName,
      filterValue);

  this.filter = new SingleColumnValueFilter(family, qualifier,
      equalityOperator, comparisonBytes);
}
 
Example #20
Source File: NewInstallUserRunner.java    From BigDataArchitect with Apache License 2.0 5 votes vote down vote up
/**
     * 初始化scan集合
     * 
     * @param job
     * @return
     */
    private List<Scan> initScans(Job job) {
        // 时间戳+....
        Configuration conf = job.getConfiguration();
        // 获取运行时间: yyyy-MM-dd
        String date = conf.get(GlobalConstants.RUNNING_DATE_PARAMES);
        long startDate = TimeUtil.parseString2Long(date);
        long endDate = startDate + GlobalConstants.DAY_OF_MILLISECONDS;

        Scan scan = new Scan();
        // 定义hbase扫描的开始rowkey和结束rowkey
        scan.setStartRow(Bytes.toBytes("" + startDate));
        scan.setStopRow(Bytes.toBytes("" + endDate));
        
        FilterList filterList = new FilterList();
        // 过滤数据,只分析launch事件
        filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes(EventLogConstants.EVENT_LOGS_FAMILY_NAME), Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.LAUNCH.alias)));
        // 定义mapper中需要获取的列名
        String[] columns = new String[] {
        			EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME, 
        			EventLogConstants.LOG_COLUMN_NAME_UUID, 
        			EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, 
        			EventLogConstants.LOG_COLUMN_NAME_PLATFORM, 
        			EventLogConstants.LOG_COLUMN_NAME_BROWSER_NAME, 
        			EventLogConstants.LOG_COLUMN_NAME_BROWSER_VERSION };
//        scan.addColumn(family, qualifier)
        filterList.addFilter(this.getColumnFilter(columns));

        scan.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, Bytes.toBytes(EventLogConstants.HBASE_NAME_EVENT_LOGS));
        scan.setFilter(filterList);
        return Lists.newArrayList(scan);
    }
 
Example #21
Source File: MetaDataEndpointImpl.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param tableName parent table's name
 * @return true if there exist a table that use this table as their base table.
 * TODO: should we pass a timestamp here?
 */
private boolean hasViews(HRegion region, byte[] tenantId, PTable table) throws IOException {
    byte[] schemaName = table.getSchemaName().getBytes();
    byte[] tableName = table.getTableName().getBytes();
    Scan scan = new Scan();
    // If the table is multi-tenant, we need to check across all tenant_ids,
    // so we can't constrain the row key. Otherwise, any views would have
    // the same tenantId.
    if (!table.isMultiTenant()) {
        byte[] startRow = ByteUtil.concat(tenantId, QueryConstants.SEPARATOR_BYTE_ARRAY);
        byte[] stopRow = ByteUtil.nextKey(startRow);
        scan.setStartRow(startRow);
        scan.setStopRow(stopRow);
    }
    SingleColumnValueFilter filter1 = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, BASE_SCHEMA_NAME_BYTES, EQUAL, schemaName);
    filter1.setFilterIfMissing(schemaName.length > 0);
    SingleColumnValueFilter filter2 = new SingleColumnValueFilter(TABLE_FAMILY_BYTES, BASE_TABLE_NAME_BYTES, EQUAL, tableName);
    filter2.setFilterIfMissing(true);
    BinaryComparator comparator = new BinaryComparator(ByteUtil.concat(tenantId, QueryConstants.SEPARATOR_BYTE_ARRAY, schemaName, QueryConstants.SEPARATOR_BYTE_ARRAY, tableName));
    RowFilter filter3 = new RowFilter(CompareOp.NOT_EQUAL,comparator);
    Filter filter = new FilterList(filter1,filter2,filter3);
    scan.setFilter(filter);
    RegionScanner scanner = region.getScanner(scan);
    try {
        List<KeyValue> results = newArrayList();
        scanner.next(results);
        return results.size() > 0;
    }
    finally {
        scanner.close();
    }
}
 
Example #22
Source File: TestJoinedScanners.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test(expected = DoNotRetryIOException.class)
public void testWithReverseScan() throws Exception {
  try (Connection con = TEST_UTIL.getConnection(); Admin admin = con.getAdmin()) {
    TableName tableName = TableName.valueOf(name.getMethodName());

    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf1"))
        .setColumnFamily(ColumnFamilyDescriptorBuilder.of("cf2"))
        .build();
    admin.createTable(tableDescriptor);

    try (Table table = con.getTable(tableName)) {
      SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("cf1"),
        Bytes.toBytes("col"), CompareOperator.EQUAL, Bytes.toBytes("val"));
      filter.setFilterIfMissing(true);

      // Reverse scan with loading CFs on demand
      Scan scan = new Scan();
      scan.setFilter(filter);
      scan.setReversed(true);
      scan.setLoadColumnFamiliesOnDemand(true);

      try (ResultScanner scanner = table.getScanner(scan)) {
        // DoNotRetryIOException should occur
        scanner.next();
      }
    }
  }
}
 
Example #23
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckAndDeleteHooks() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try {
    Put p = new Put(Bytes.toBytes(0));
    p.addColumn(A, A, A);
    table.put(p);
    Delete d = new Delete(Bytes.toBytes(0));
    table.delete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 0, 0, 0, 0, 0, 0 });

    table.checkAndMutate(Bytes.toBytes(0), A).qualifier(A).ifEquals(A).thenDelete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 1, 1, 1, 0, 0, 0 });

    table.checkAndMutate(Bytes.toBytes(0),
        new SingleColumnValueFilter(A, A, CompareOperator.EQUAL, A))
      .thenDelete(d);
    verifyMethodResult(
      SimpleRegionObserver.class, new String[] { "getPreCheckAndDelete",
        "getPreCheckAndDeleteAfterRowLock", "getPostCheckAndDelete",
        "getPreCheckAndDeleteWithFilter", "getPreCheckAndDeleteWithFilterAfterRowLock",
        "getPostCheckAndDeleteWithFilter" },
      tableName, new Integer[] { 1, 1, 1, 1, 1, 1 });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
 
Example #24
Source File: TestCheckAndMutate.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckAndMutateWithFilterAndTimeRange() throws Throwable {
  try (Table table = createTable()) {
    // Put with specifying the timestamp
    table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));

    // Put with success
    boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
      .ifMatches(new SingleColumnValueFilter(FAMILY,
        Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")))
      .timeRange(TimeRange.between(0, 101))
      .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))));
    assertTrue(ok);

    Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
    assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));

    // Put with failure
    ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
      .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
        CompareOperator.EQUAL, Bytes.toBytes("a")))
      .timeRange(TimeRange.between(0, 100))
      .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))));
    assertFalse(ok);

    assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
  }
}
 
Example #25
Source File: TestCheckAndMutate.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
@Deprecated
public void testCheckAndMutateWithFilterAndTimeRangeForOldApi() throws Throwable {
  try (Table table = createTable()) {
    // Put with specifying the timestamp
    table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));

    // Put with success
    boolean ok = table.checkAndMutate(ROWKEY, new SingleColumnValueFilter(FAMILY,
        Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")))
      .timeRange(TimeRange.between(0, 101))
      .thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")));
    assertTrue(ok);

    Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
    assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));

    // Put with failure
    ok = table.checkAndMutate(ROWKEY, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
        CompareOperator.EQUAL, Bytes.toBytes("a")))
      .timeRange(TimeRange.between(0, 100))
      .thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));
    assertFalse(ok);

    assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
  }
}
 
Example #26
Source File: TestFromClientSide.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test public void testFilterWithLongCompartor() throws Exception {
  final TableName tableName = name.getTableName();
  try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) {
    byte[][] ROWS = makeN(ROW, 10);
    byte[][] values = new byte[10][];
    for (int i = 0; i < 10; i++) {
      values[i] = Bytes.toBytes(100L * i);
    }
    for (int i = 0; i < 10; i++) {
      Put put = new Put(ROWS[i]);
      put.setDurability(Durability.SKIP_WAL);
      put.addColumn(FAMILY, QUALIFIER, values[i]);
      ht.put(put);
    }
    Scan scan = new Scan();
    scan.addFamily(FAMILY);
    Filter filter = new SingleColumnValueFilter(FAMILY, QUALIFIER, CompareOperator.GREATER,
      new LongComparator(500));
    scan.setFilter(filter);
    try (ResultScanner scanner = ht.getScanner(scan)) {
      int expectedIndex = 0;
      for (Result result : scanner) {
        assertEquals(1, result.size());
        assertTrue(Bytes.toLong(result.getValue(FAMILY, QUALIFIER)) > 500);
        expectedIndex++;
      }
      assertEquals(4, expectedIndex);
    }
  }
}
 
Example #27
Source File: HBaseFilterBuilderTest.java    From pxf with Apache License 2.0 5 votes vote down vote up
@Test
public void parseIsNullExpression() throws Exception {
    Filter filter = helper("a1o8", tupleDescription);
    assertTrue(filter instanceof SingleColumnValueFilter);

    SingleColumnValueFilter result = (SingleColumnValueFilter) filter;
    assertNotNull(result);
    assertSame(families[1], result.getFamily());
    assertSame(qualifiers[1], result.getQualifier());
    assertEquals(CompareFilter.CompareOp.EQUAL, result.getOperator());
    assertTrue(result.getComparator() instanceof NullComparator);
}
 
Example #28
Source File: TestAsyncTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
@Deprecated
public void testCheckAndMutateWithFilterAndTimeRangeForOldApi() throws Throwable {
  AsyncTable<?> table = getTable.get();

  // Put with specifying the timestamp
  table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")))
    .get();

  // Put with success
  boolean ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
      CompareOperator.EQUAL, Bytes.toBytes("a")))
    .timeRange(TimeRange.between(0, 101))
    .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))
    .get();
  assertTrue(ok);

  Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
  assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));

  // Put with failure
  ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
      CompareOperator.EQUAL, Bytes.toBytes("a")))
    .timeRange(TimeRange.between(0, 100))
    .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))
    .get();
  assertFalse(ok);

  assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
 
Example #29
Source File: MetaBrowser.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static Filter buildScanRegionStateFilter(final RegionState.State state) {
  return new SingleColumnValueFilter(
    HConstants.CATALOG_FAMILY,
    HConstants.STATE_QUALIFIER,
    CompareOperator.EQUAL,
    // use the same serialization strategy as found in MetaTableAccessor#addRegionStateToPut
    Bytes.toBytes(state.name()));
}
 
Example #30
Source File: InboundBounceRunner.java    From BigDataArchitect with Apache License 2.0 5 votes vote down vote up
@Override
protected Filter fetchHbaseFilter() {
    FilterList list = new FilterList();
    String[] columns = new String[] { EventLogConstants.LOG_COLUMN_NAME_REFERRER_URL, // 前一个页面的url
            EventLogConstants.LOG_COLUMN_NAME_SESSION_ID, // 会话id
            EventLogConstants.LOG_COLUMN_NAME_PLATFORM, // 平台名称
            EventLogConstants.LOG_COLUMN_NAME_SERVER_TIME, // 服务器时间
            EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME // 事件名称
    };
    list.addFilter(this.getColumnFilter(columns));
    list.addFilter(new SingleColumnValueFilter(InboundMapper.family, Bytes.toBytes(EventLogConstants.LOG_COLUMN_NAME_EVENT_NAME), CompareOp.EQUAL, Bytes.toBytes(EventEnum.PAGEVIEW.alias)));
    return list;
}