Java Code Examples for org.apache.hadoop.hbase.client.Scan#setRowPrefixFilter()

The following examples show how to use org.apache.hadoop.hbase.client.Scan#setRowPrefixFilter() . 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: QuotaTableUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a scanner for all namespace snapshot entries of the given namespace
 * @param namespace name of the namespace whose snapshot entries are to be scanned
 */
static Scan createScanForNamespaceSnapshotSizes(String namespace) {
  Scan s = new Scan();
  if (namespace == null || namespace.isEmpty()) {
    // Read all namespaces, just look at the row prefix
    s.setRowPrefixFilter(QUOTA_NAMESPACE_ROW_KEY_PREFIX);
  } else {
    // Fetch the exact row for the table
    byte[] rowkey = getNamespaceRowKey(namespace);
    // Fetch just this one row
    s.withStartRow(rowkey).withStopRow(rowkey, true);
  }

  // Just the usage family and only the snapshot size qualifiers
  return s.addFamily(QUOTA_FAMILY_USAGE)
      .setFilter(new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER));
}
 
Example 2
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
static Scan createScanForSpaceSnapshotSizes(TableName table) {
  Scan s = new Scan();
  if (null == table) {
    // Read all tables, just look at the row prefix
    s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX);
  } else {
    // Fetch the exact row for the table
    byte[] rowkey = getTableRowKey(table);
    // Fetch just this one row
    s.withStartRow(rowkey).withStopRow(rowkey, true);
  }

  // Just the usage family and only the snapshot size qualifiers
  return s.addFamily(QUOTA_FAMILY_USAGE).setFilter(
      new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER));
}
 
Example 3
Source File: IndexToolForNonTxGlobalIndexIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private List<String> verifyRunStatusFromResultTable(Connection conn, Long scn, String indexTable, int totalRows, List<String> expectedStatus) throws SQLException, IOException {
    Table hIndexToolTable = conn.unwrap(PhoenixConnection.class).getQueryServices()
            .getTable(RESULT_TABLE_NAME_BYTES);
    Assert.assertEquals(totalRows, TestUtil.getRowCount(hIndexToolTable, false));
    List<String> output = new ArrayList<>();
    Scan s = new Scan();
    s.setRowPrefixFilter(Bytes.toBytes(String.format("%s%s%s", scn, ROW_KEY_SEPARATOR, indexTable)));
    ResultScanner rs = hIndexToolTable.getScanner(s);
    int count =0;
    for(Result r : rs) {
        Assert.assertTrue(r != null);
        List<Cell> cells = r.getColumnCells(RESULT_TABLE_COLUMN_FAMILY, INDEX_TOOL_RUN_STATUS_BYTES);
        Assert.assertEquals(cells.size(), 1);
        Assert.assertTrue(Bytes.toString(CellUtil.cloneRow(cells.get(0))).startsWith(String.valueOf(scn)));
        output.add(Bytes.toString(CellUtil.cloneValue(cells.get(0))));
        count++;
    }
    //for each region
    Assert.assertEquals(3, count);
    for(int i=0; i< count; i++) {
        Assert.assertEquals(expectedStatus.get(i), output.get(i));
    }
    return output;
}
 
Example 4
Source File: EdgeIndexModel.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
private Scan getEdgeEndpointsScan(Vertex vertex, Direction direction, String... labels) {
    LOGGER.trace("Executing Scan, type: {}, id: {}", "key", vertex.id());

    final String key = Constants.CREATED_AT;
    byte[] startRow = serializeForRead(vertex, direction != Direction.BOTH ? direction : null, false,
            key, labels.length == 1 ? labels[0] : null, null);
    Scan scan = new Scan(startRow);
    scan.setRowPrefixFilter(startRow);
    scan.setFilter(applyEdgeLabelsRowFilter(vertex, direction, key, labels));
    return scan;
}
 
Example 5
Source File: EdgeIndexModel.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
private Scan getEdgesScan(Vertex vertex, Direction direction, boolean isUnique, String key, String label, Object value) {
    LOGGER.trace("Executing Scan, type: {}, id: {}", "key-value", vertex.id());

    byte[] startRow = serializeForRead(vertex, direction, isUnique, key, label, value);
    Scan scan = new Scan(startRow);
    scan.setRowPrefixFilter(startRow);
    return scan;
}
 
Example 6
Source File: DropIndex.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
@Override
protected Scan getInputScan(final HBaseGraph graph, final IndexMetadata index) {
    if (index.type() == ElementType.EDGE) {
        return new Scan();
    } else {
        // optimization for vertex index scans
        byte[] startRow = graph.getVertexIndexModel().serializeForRead(
                index.label(), index.isUnique(), index.propertyKey(), null);
        Scan scan = new Scan(startRow);
        scan.setRowPrefixFilter(startRow);
        return scan;
    }
}
 
Example 7
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Scan} which returns only {@link SpaceQuotaSnapshot} from the quota table for a
 * specific table.
 * @param tn Optionally, a table name to limit the scan's rowkey space. Can be null.
 */
public static Scan makeQuotaSnapshotScanForTable(TableName tn) {
  Scan s = new Scan();
  // Limit to "u:v" column
  s.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY);
  if (null == tn) {
    s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX);
  } else {
    byte[] row = getTableRowKey(tn);
    // Limit rowspace to the "t:" prefix
    s.withStartRow(row, true).withStopRow(row, true);
  }
  return s;
}
 
Example 8
Source File: IndexTool.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public boolean isValidLastVerifyTime(Long lastVerifyTime) throws Exception {
    try(Connection conn = getConnection(configuration)) {
        Table hIndexToolTable = conn.unwrap(PhoenixConnection.class).getQueryServices()
                .getTable(IndexVerificationResultRepository.RESULT_TABLE_NAME_BYTES);
        Scan s = new Scan();
        ConnectionQueryServices cqs = conn.unwrap(PhoenixConnection.class).getQueryServices();
        boolean isNamespaceMapped = SchemaUtil.isNamespaceMappingEnabled(null, cqs.getProps());
        s.setRowPrefixFilter(Bytes.toBytes(String.format("%s%s%s", lastVerifyTime,
                ROW_KEY_SEPARATOR,
                SchemaUtil.getPhysicalHBaseTableName(schemaName, indexTable, isNamespaceMapped))));
        ResultScanner rs = hIndexToolTable.getScanner(s);
        return rs.next() != null;
    }
}
 
Example 9
Source File: IndexToolForNonTxGlobalIndexIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void deleteOneRowFromResultTable(Connection conn,  Long scn, String indexTable)
        throws SQLException, IOException {
    Table hIndexToolTable = conn.unwrap(PhoenixConnection.class).getQueryServices()
            .getTable(RESULT_TABLE_NAME_BYTES);
    Scan s = new Scan();
    s.setRowPrefixFilter(Bytes.toBytes(String.format("%s%s%s", scn, ROW_KEY_SEPARATOR, indexTable)));
    ResultScanner rs = hIndexToolTable.getScanner(s);
    hIndexToolTable.delete(new Delete(rs.next().getRow()));
}
 
Example 10
Source File: VertexIndexModel.java    From hgraphdb with Apache License 2.0 4 votes vote down vote up
private Scan getVertexIndexScan(String label, boolean isUnique, String key, Object value) {
    byte[] startRow = serializeForRead(label, isUnique, key, value);
    Scan scan = new Scan(startRow);
    scan.setRowPrefixFilter(startRow);
    return scan;
}