Java Code Examples for org.apache.hadoop.hbase.client.HTableInterface#get()
The following examples show how to use
org.apache.hadoop.hbase.client.HTableInterface#get() .
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: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception { Result result = table.get(get); if (expectedValues == null) { assertTrue(result.isEmpty()); } else { assertFalse(result.isEmpty()); byte[] family = TestBytes.family; byte[] col = TestBytes.qualifier; if (get.hasFamilies()) { family = get.getFamilyMap().keySet().iterator().next(); col = get.getFamilyMap().get(family).first(); } Iterator<Cell> it = result.getColumnCells(family, col).iterator(); for (byte[] expectedValue : expectedValues) { Assert.assertTrue(it.hasNext()); assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next())); } } }
Example 2
Source File: HBaseBackedTransactionLogger.java From hbase-secondary-index with GNU General Public License v3.0 | 6 votes |
public TransactionStatus getStatusForTransaction(final long transactionId) throws IOException { HTableInterface table = getTable(); try { Result result = table.get(new Get(getRow(transactionId))); if (result == null || result.isEmpty()) { return null; } byte[] statusCell = result.getValue(INFO_FAMILY, STATUS_QUALIFIER); if (statusCell == null) { throw new RuntimeException("No status cell for row " + transactionId); } String statusString = Bytes.toString(statusCell); return TransactionStatus.valueOf(statusString); } catch (IOException e) { throw new RuntimeException(e); } finally { putTable(table); } }
Example 3
Source File: AbstractHBaseClient.java From jstorm with Apache License 2.0 | 6 votes |
protected KVSerializable getRow(String tableName, Class clazz, byte[] key) { HTableInterface table = getHTableInterface(tableName); Get get = new Get(key); HTableInterface htable; try { htable = getHTableInterface(tableName); KVSerializable kvInst = (KVSerializable) clazz.getConstructors()[0].newInstance(); Result result = htable.get(get); if (result != null) { kvInst.fromKV(key, result.getValue(CF, V_DATA)); return kvInst; } } catch (Exception ex) { logger.error("Scan metric meta error, class:{}", clazz.getSimpleName(), ex); } finally { closeTable(table); } return null; }
Example 4
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception { Result result = table.get(get); if (expectedValues == null) { assertTrue(result.isEmpty()); } else { assertFalse(result.isEmpty()); byte[] family = TestBytes.family; byte[] col = TestBytes.qualifier; if (get.hasFamilies()) { family = get.getFamilyMap().keySet().iterator().next(); col = get.getFamilyMap().get(family).first(); } Iterator<Cell> it = result.getColumnCells(family, col).iterator(); for (byte[] expectedValue : expectedValues) { Assert.assertTrue(it.hasNext()); assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next())); } } }
Example 5
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception { Result result = table.get(get); if (expectedValues == null) { assertTrue(result.isEmpty()); } else { assertFalse(result.isEmpty()); byte[] family = TestBytes.family; byte[] col = TestBytes.qualifier; if (get.hasFamilies()) { family = get.getFamilyMap().keySet().iterator().next(); col = get.getFamilyMap().get(family).first(); } Iterator<Cell> it = result.getColumnCells(family, col).iterator(); for (byte[] expectedValue : expectedValues) { Assert.assertTrue(it.hasNext()); assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next())); } } }
Example 6
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private void verifyRows(HTableInterface table, Get get, List<byte[]> expectedValues) throws Exception { Result result = table.get(get); if (expectedValues == null) { assertTrue(result.isEmpty()); } else { assertFalse(result.isEmpty()); byte[] family = TestBytes.family; byte[] col = TestBytes.qualifier; if (get.hasFamilies()) { family = get.getFamilyMap().keySet().iterator().next(); col = get.getFamilyMap().get(family).first(); } Iterator<Cell> it = result.getColumnCells(family, col).iterator(); for (byte[] expectedValue : expectedValues) { Assert.assertTrue(it.hasNext()); assertArrayEquals(expectedValue, CellUtil.cloneValue(it.next())); } } }
Example 7
Source File: DataJanitorState.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@VisibleForTesting int getRegionCountForTime(HTableInterface stateTable, long time) throws IOException { Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time)))); get.addColumn(FAMILY, REGION_TIME_COL); Result result = stateTable.get(get); byte[] value = result.getValue(FAMILY, REGION_TIME_COL); return value == null ? -1 : Bytes.toInt(value); }
Example 8
Source File: DataJanitorState.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@VisibleForTesting int getRegionCountForTime(HTableInterface stateTable, long time) throws IOException { Get get = new Get(makeTimeRegionCountKey(Bytes.toBytes(getInvertedTime(time)))); get.addColumn(FAMILY, REGION_TIME_COL); Result result = stateTable.get(get); byte[] value = result.getValue(FAMILY, REGION_TIME_COL); return value == null ? -1 : Bytes.toInt(value); }
Example 9
Source File: StatisticsUtil.java From phoenix with Apache License 2.0 | 5 votes |
public static Result readRegionStatistics(HTableInterface statsHTable, byte[] tableNameBytes, ImmutableBytesPtr cf, byte[] regionName, long clientTimeStamp) throws IOException { byte[] prefix = StatisticsUtil.getRowKey(tableNameBytes, cf, regionName); Get get = new Get(prefix); get.setTimeRange(MetaDataProtocol.MIN_TABLE_TIMESTAMP, clientTimeStamp); get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES); get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_BYTES); get.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES); return statsHTable.get(get); }
Example 10
Source File: AclService.java From Kylin with Apache License 2.0 | 5 votes |
@Override public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> oids, List<Sid> sids) throws NotFoundException { Map<ObjectIdentity, Acl> aclMaps = new HashMap<ObjectIdentity, Acl>(); HTableInterface htable = null; Result result = null; try { htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName); for (ObjectIdentity oid : oids) { result = htable.get(new Get(Bytes.toBytes(String.valueOf(oid.getIdentifier())))); if (null != result && !result.isEmpty()) { SidInfo owner = sidSerializer.deserialize(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_OWNER_COLUMN))); Sid ownerSid = (null == owner) ? null : (owner.isPrincipal() ? new PrincipalSid(owner.getSid()) : new GrantedAuthoritySid(owner.getSid())); boolean entriesInheriting = Bytes.toBoolean(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_ENTRY_INHERIT_COLUMN))); Acl parentAcl = null; DomainObjectInfo parentInfo = domainObjSerializer.deserialize(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN))); if (null != parentInfo) { ObjectIdentity parentObj = new ObjectIdentityImpl(parentInfo.getType(), parentInfo.getId()); parentAcl = readAclById(parentObj, null); } AclImpl acl = new AclImpl(oid, oid.getIdentifier(), aclAuthorizationStrategy, permissionGrantingStrategy, parentAcl, null, entriesInheriting, ownerSid); genAces(sids, result, acl); aclMaps.put(oid, acl); } else { throw new NotFoundException("Unable to find ACL information for object identity '" + oid + "'"); } } } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } return aclMaps; }
Example 11
Source File: UserService.java From Kylin with Apache License 2.0 | 5 votes |
@Override public boolean userExists(String username) { HTableInterface htable = null; try { htable = HBaseConnection.get(hbaseUrl).getTable(userTableName); Result result = htable.get(new Get(Bytes.toBytes(username))); return null != result && !result.isEmpty(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(htable); } }
Example 12
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 4 votes |
private Cell[] getRow(HTableInterface table, Get get) throws Exception { Result result = table.get(get); return result.rawCells(); }
Example 13
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 4 votes |
private Cell[] getRow(HTableInterface table, Get get) throws Exception { Result result = table.get(get); return result.rawCells(); }
Example 14
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 4 votes |
private Cell[] getRow(HTableInterface table, Get get) throws Exception { Result result = table.get(get); return result.rawCells(); }
Example 15
Source File: BasicFraudHBaseService.java From hadoop-arch-book with Apache License 2.0 | 4 votes |
public ProfilePojo[] getProfilesFromHBase(List<Long> userIds) throws IOException { ArrayList<Get> getList = new ArrayList<Get>(); for (Long userId: userIds) { getList.add(new Get(generateProfileRowKey(userId))); } HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE); Result[] results = profileTable.get(getList); ProfilePojo[] profiles = new ProfilePojo[getList.size()]; int counter = 0; for (Result result: results) { String[] fixedInfoValues = Bytes.toString(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL).getValue()).split("|"); String username = fixedInfoValues[0]; int age = Integer.parseInt(fixedInfoValues[1]); long firstLogIn = Long.parseLong(fixedInfoValues[2]); long lastLogIn = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL).getValue()); long logInCount = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL).getValue()); long logInCountHavingASell = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL).getValue()); long logInCountHavingAPurchase = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL).getValue()); long totalValueOfPastPurchases = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL).getValue()); long totalValueOfPastSells = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL).getValue()); long currentLogInSellsValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL).getValue()); long currentLogInPurchasesValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL).getValue()); HashSet<String> last20LogOnIpAddresses = new HashSet<String>(); List<KeyValue> ipAddresses = result.getColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES); boolean isFirst = true; String lastLogInIpAddress = null; for (KeyValue kv: ipAddresses) { if (isFirst) { isFirst = false; lastLogInIpAddress = Bytes.toString(kv.getValue()); } else { last20LogOnIpAddresses.add(Bytes.toString(kv.getValue())); } } ProfilePojo pojo = new ProfilePojo(username, age, firstLogIn, lastLogIn, lastLogInIpAddress, logInCount, logInCountHavingASell, totalValueOfPastSells, currentLogInSellsValue, logInCountHavingAPurchase, totalValueOfPastPurchases, currentLogInPurchasesValue, last20LogOnIpAddresses); profiles[counter++] = pojo; } return profiles; }
Example 16
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 4 votes |
private Cell[] getRow(HTableInterface table, Get get) throws Exception { Result result = table.get(get); return result.rawCells(); }
Example 17
Source File: HBaseFactoryTest.java From bigdata-tutorial with Apache License 2.0 | 2 votes |
/** * get a row identified by rowkey * * @param table * @param rowKey * @throws Exception */ public static Result getRow(HTableInterface table, String rowKey) throws Exception { Get get = new Get(Bytes.toBytes(rowKey)); Result result = table.get(get); return result; }