Java Code Examples for org.apache.hadoop.hbase.client.Get#addFamily()

The following examples show how to use org.apache.hadoop.hbase.client.Get#addFamily() . 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: PcapGetterHBaseImpl.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the get request.
 * 
 * @param key
 *          the key
 * @param startTime
 *          the start time
 * @param endTime
 *          the end time
 * @return the gets the
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
@VisibleForTesting
Get createGetRequest(String key, long startTime, long endTime)
    throws IOException {
  Get get = new Get(Bytes.toBytes(key));
  // set family name
  get.addFamily(ConfigurationUtil.getColumnFamily());

  // set column family, qualifier
  get.addColumn(ConfigurationUtil.getColumnFamily(),
      ConfigurationUtil.getColumnQualifier());

  // set max versions
  get.setMaxVersions(ConfigurationUtil.getMaxVersions());

  // set time range
  setTimeRangeOnGet(get, startTime, endTime);
  return get;
}
 
Example 2
Source File: HBaseManager.java    From hbase-secondary-index with GNU General Public License v3.0 6 votes vote down vote up
public ResultScanner getVer(byte[] tableName, byte[] rowkey,
		byte[] columnFamily, String[] columns, int ver) throws IOException {
	table = new HTable(config, tableName);
	Get get = new Get(rowkey);
	if (null != columnFamily && null != columns && columns.length > 0) {
		for (int i = 0; i < columns.length; i++) {
			get.addColumn(columnFamily, Bytes.toBytes(columns[i]));
		}
	} else if (null != columnFamily
			&& (null == columns || columns.length == 0)) {
		get.addFamily(columnFamily);
	}

	Scan scanner = new Scan(get);
	scanner.setMaxVersions(ver);
	return table.getScanner(scanner);
}
 
Example 3
Source File: HBaseSpanViewer.java    From incubator-retired-htrace with Apache License 2.0 6 votes vote down vote up
public List<SpanProtos.Span> getSpans(long traceid) throws IOException {
  startClient();
  List<SpanProtos.Span> spans = new ArrayList<SpanProtos.Span>();
  Get get = new Get(Bytes.toBytes(traceid));
  get.addFamily(this.cf);
  try {
    for (Cell cell : htable.get(get).listCells()) {
      InputStream in = new ByteArrayInputStream(cell.getQualifierArray(),
                                                cell.getQualifierOffset(),
                                                cell.getQualifierLength());
      spans.add(SpanProtos.Span.parseFrom(in));
    }
  } catch (IOException e) {
    LOG.warn("Failed to get spans from HBase. " + e.getMessage());
    stopClient();
  }
  return spans;
}
 
Example 4
Source File: MetaTableAccessor.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the HRegionLocation from meta for the given region
 * @param connection connection we're using
 * @param regionName region we're looking for
 * @return HRegionLocation for the given region
 */
public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName)
  throws IOException {
  byte[] row = regionName;
  RegionInfo parsedInfo = null;
  try {
    parsedInfo = CatalogFamilyFormat.parseRegionInfoFromRegionName(regionName);
    row = CatalogFamilyFormat.getMetaKeyForRegion(parsedInfo);
  } catch (Exception parseEx) {
    // Ignore. This is used with tableName passed as regionName.
  }
  Get get = new Get(row);
  get.addFamily(HConstants.CATALOG_FAMILY);
  Result r;
  try (Table t = getMetaHTable(connection)) {
    r = t.get(get);
  }
  RegionLocations locations = CatalogFamilyFormat.getRegionLocations(r);
  return locations == null ? null :
    locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId());
}
 
Example 5
Source File: PcapGetterHBaseImpl.java    From opensoc-streaming with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the get request.
 * 
 * @param key
 *          the key
 * @param startTime
 *          the start time
 * @param endTime
 *          the end time
 * @return the gets the
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
@VisibleForTesting
Get createGetRequest(String key, long startTime, long endTime)
    throws IOException {
  Get get = new Get(Bytes.toBytes(key));
  // set family name
  get.addFamily(ConfigurationUtil.getColumnFamily());

  // set column family, qualifier
  get.addColumn(ConfigurationUtil.getColumnFamily(),
      ConfigurationUtil.getColumnQualifier());

  // set max versions
  get.setMaxVersions(ConfigurationUtil.getMaxVersions());

  // set time range
  setTimeRangeOnGet(get, startTime, endTime);
  return get;
}
 
Example 6
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 7
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
boolean testRow(final int i) throws IOException, InterruptedException {
  Get get = new Get(format(i));
  for (int family = 0; family < opts.families; family++) {
    byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);
    if (opts.addColumns) {
      for (int column = 0; column < opts.columns; column++) {
        byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column);
        get.addColumn(familyName, qualifier);
      }
    } else {
      get.addFamily(familyName);
    }
  }
  if (opts.filterAll) {
    get.setFilter(new FilterAllFilter());
  }
  try {
    updateValueSize(table.get(get).get());
  } catch (ExecutionException e) {
    throw new IOException(e);
  }
  return true;
}
 
Example 8
Source File: TestNamespaceReplication.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void ensureRowNotExisted(Table target, byte[] row, byte[]... families)
    throws Exception {
  for (byte[] fam : families) {
    Get get = new Get(row);
    get.addFamily(fam);
    for (int i = 0; i < NB_RETRIES; i++) {
      if (i == NB_RETRIES - 1) {
        fail("Waited too much time for delete replication");
      }
      Result res = target.get(get);
      if (res.size() >= 1) {
        LOG.info("Row not deleted");
      } else {
        break;
      }
      Thread.sleep(10 * SLEEP_TIME);
    }
  }
}
 
Example 9
Source File: HbaseApplicationIndexDao.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private <T> List<T> selectApplicationIndex0(String applicationName, RowMapper<List<T>> rowMapper) {
    Objects.requireNonNull(applicationName, "applicationName");
    Objects.requireNonNull(rowMapper, "rowMapper");

    byte[] rowKey = Bytes.toBytes(applicationName);

    Get get = new Get(rowKey);
    get.addFamily(descriptor.getColumnFamilyName());

    TableName applicationIndexTableName = descriptor.getTableName();
    return hbaseOperations2.get(applicationIndexTableName, get, rowMapper);
}
 
Example 10
Source File: TestPerTableCFReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void deleteAndWaitWithFamily(byte[] row, byte[] fam,
    Table source, Table... targets)
  throws Exception {
  Delete del = new Delete(row);
  del.addFamily(fam);
  source.delete(del);

  Get get = new Get(row);
  get.addFamily(fam);
  for (int i = 0; i < NB_RETRIES; i++) {
    if (i==NB_RETRIES-1) {
      fail("Waited too much time for del replication");
    }
    boolean removedFromAll = true;
    for (Table target : targets) {
      Result res = target.get(get);
      if (res.size() >= 1) {
        LOG.info("Row not deleted");
        removedFromAll = false;
        break;
      }
    }
    if (removedFromAll) {
      break;
    } else {
      Thread.sleep(SLEEP_TIME);
    }
  }
}
 
Example 11
Source File: PermissionStorage.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Reads user permission assignments stored in the <code>l:</code> column family of the first
 * table row in <code>_acl_</code>.
 * <p>
 * See {@link PermissionStorage class documentation} for the key structure used for storage.
 * </p>
 */
static ListMultimap<String, UserPermission> getPermissions(Configuration conf, byte[] entryName,
    Table t, byte[] cf, byte[] cq, String user, boolean hasFilterUser) throws IOException {
  if (entryName == null) {
    entryName = ACL_GLOBAL_NAME;
  }
  // for normal user tables, we just read the table row from _acl_
  ListMultimap<String, UserPermission> perms = ArrayListMultimap.create();
  Get get = new Get(entryName);
  get.addFamily(ACL_LIST_FAMILY);
  Result row = null;
  if (t == null) {
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
      try (Table table = connection.getTable(ACL_TABLE_NAME)) {
        row = table.get(get);
      }
    }
  } else {
    row = t.get(get);
  }
  if (!row.isEmpty()) {
    perms = parsePermissions(entryName, row, cf, cq, user, hasFilterUser);
  } else {
    LOG.info("No permissions found in " + ACL_TABLE_NAME + " for acl entry "
        + Bytes.toString(entryName));
  }

  return perms;
}
 
Example 12
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates Get to retrieve incremental backup table set from backup system table
 * @return get operation
 * @throws IOException exception
 */
private Get createGetForIncrBackupTableSet(String backupRoot) throws IOException {
  Get get = new Get(rowkey(INCR_BACKUP_SET, backupRoot));
  get.addFamily(BackupSystemTable.META_FAMILY);
  get.readVersions(1);
  return get;
}
 
Example 13
Source File: AbstractTestLogRolling.java    From hbase with Apache License 2.0 5 votes vote down vote up
void validateData(Table table, int rownum) throws IOException {
  String row = "row" + String.format("%1$04d", rownum);
  Get get = new Get(Bytes.toBytes(row));
  get.addFamily(HConstants.CATALOG_FAMILY);
  Result result = table.get(get);
  assertTrue(result.size() == 1);
  assertTrue(Bytes.equals(value,
              result.getValue(HConstants.CATALOG_FAMILY, null)));
  LOG.info("Validated row " + row);
}
 
Example 14
Source File: HBaseLookupTable.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * Loads mappings for given table name from the lookup table
 * {@link #LOOKUPTABLENAME}. The table name should be in the row key, and
 * the family name should be {@link #LOOKUPCOLUMNFAMILY}.
 *
 * @param tableName HBase table name
 * @throws IOException when HBase operations fail
 */
private void loadMappingMap(String tableName) throws IOException {
    Get lookupRow = new Get(Bytes.toBytes(tableName));
    lookupRow.setMaxVersions(1);
    lookupRow.addFamily(LOOKUPCOLUMNFAMILY);
    Result row;

    row = lookupTable.get(lookupRow);
    rawTableMapping = row.getFamilyMap(LOOKUPCOLUMNFAMILY);
    LOG.debug("lookup table mapping for " + tableName + " has "
            + (rawTableMapping == null ? 0 : rawTableMapping.size())
            + " entries");
}
 
Example 15
Source File: RowKeyLogReader.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws IOException {
    if (isOpen) {
        return; // silently return
    }
    try {
        tbl = EagleConfigFactory.load().getHTable(ed.getTable());
    } catch (RuntimeException ex) {
        throw new IOException(ex);
    }
    final byte[] family = ed.getColumnFamily().getBytes();
    List<Get> gets = new ArrayList<>(this.rowkeys.size());

    for (byte[] rowkey : rowkeys) {
        Get get = new Get(rowkey);
        get.addFamily(family);

        if (qualifiers != null) {
            for (byte[] qualifier : qualifiers) {
                get.addColumn(family, qualifier);
            }
        }

        gets.add(get);
    }

    entityResult = tbl.get(gets);
    isOpen = true;
}
 
Example 16
Source File: TestPerTableCFReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void putAndWaitWithFamily(byte[] row, byte[] fam,
    Table source, Table... targets)
  throws Exception {
  Put put = new Put(row);
  put.addColumn(fam, row, val);
  source.put(put);

  Get get = new Get(row);
  get.addFamily(fam);
  for (int i = 0; i < NB_RETRIES; i++) {
    if (i==NB_RETRIES-1) {
      fail("Waited too much time for put replication");
    }
    boolean replicatedToAll = true;
    for (Table target : targets) {
      Result res = target.get(get);
      if (res.isEmpty()) {
        LOG.info("Row not available");
        replicatedToAll = false;
        break;
      } else {
        assertEquals(1, res.size());
        assertArrayEquals(val, res.value());
      }
    }
    if (replicatedToAll) {
      break;
    } else {
      Thread.sleep(SLEEP_TIME);
    }
  }
}
 
Example 17
Source File: SnapshotScannerHDFSAclController.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static Set<String> getEntryUsers(Table aclTable, byte[] entry) throws IOException {
  Set<String> users = new HashSet<>();
  Get get = new Get(entry);
  get.addFamily(HDFS_ACL_FAMILY);
  Result result = aclTable.get(get);
  List<Cell> cells = result.listCells();
  if (cells != null) {
    for (Cell cell : cells) {
      if (cell != null) {
        users.add(Bytes.toString(CellUtil.cloneQualifier(cell)));
      }
    }
  }
  return users;
}
 
Example 18
Source File: HbaseStringMetaDataDao.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public List<StringMetaDataBo> getStringMetaData(String agentId, long time, int stringId) {
    Objects.requireNonNull(agentId, "agentId");

    StringMetaDataBo stringMetaData = new StringMetaDataBo(agentId, time, stringId);
    byte[] rowKey = getDistributedKey(stringMetaData.toRowKey());

    Get get = new Get(rowKey);
    get.addFamily(descriptor.getColumnFamilyName());

    TableName stringMetaDataTableName = descriptor.getTableName();
    return hbaseOperations2.get(stringMetaDataTableName, get, stringMetaDataMapper);
}
 
Example 19
Source File: TestAccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRead() throws Exception {
  // get action
  AccessTestAction getAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      Get g = new Get(TEST_ROW);
      g.addFamily(TEST_FAMILY);
      try(Connection conn = ConnectionFactory.createConnection(conf);
          Table t = conn.getTable(TEST_TABLE)) {
        t.get(g);
      }
      return null;
    }
  };
  verifyRead(getAction);

  // action for scanning
  AccessTestAction scanAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      Scan s = new Scan();
      s.addFamily(TEST_FAMILY);
      try(Connection conn = ConnectionFactory.createConnection(conf);
          Table table = conn.getTable(TEST_TABLE)) {
        ResultScanner scanner = table.getScanner(s);
        try {
          for (Result r = scanner.next(); r != null; r = scanner.next()) {
            // do nothing
          }
        } finally {
          scanner.close();
        }
      }
      return null;
    }
  };
  verifyRead(scanAction);
}
 
Example 20
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
boolean testRow(final int i) throws IOException, InterruptedException {
  if (opts.randomSleep > 0) {
    Thread.sleep(rd.nextInt(opts.randomSleep));
  }
  Get get = new Get(getRandomRow(this.rand, opts.totalRows));
  for (int family = 0; family < opts.families; family++) {
    byte[] familyName = Bytes.toBytes(FAMILY_NAME_BASE + family);
    if (opts.addColumns) {
      for (int column = 0; column < opts.columns; column++) {
        byte [] qualifier = column == 0? COLUMN_ZERO: Bytes.toBytes("" + column);
        get.addColumn(familyName, qualifier);
      }
    } else {
      get.addFamily(familyName);
    }
  }
  if (opts.filterAll) {
    get.setFilter(new FilterAllFilter());
  }
  get.setConsistency(consistency);
  if (LOG.isTraceEnabled()) LOG.trace(get.toString());
  try {
    if (opts.multiGet > 0) {
      this.gets.add(get);
      if (this.gets.size() == opts.multiGet) {
        Result[] rs =
            this.table.get(this.gets).stream().map(f -> propagate(f::get)).toArray(Result[]::new);
        updateValueSize(rs);
        this.gets.clear();
      } else {
        return false;
      }
    } else {
      updateValueSize(this.table.get(get).get());
    }
  } catch (ExecutionException e) {
    throw new IOException(e);
  }
  return true;
}