org.apache.hadoop.hbase.client.Get Java Examples
The following examples show how to use
org.apache.hadoop.hbase.client.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: CustomSaslAuthenticationProviderTestBase.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testPositiveAuthentication() throws Exception { // Validate that we can read that record back out as the user with our custom auth'n UserGroupInformation user1 = UserGroupInformation.createUserForTesting("user1", new String[0]); user1.addToken(createPasswordToken("user1", USER1_PASSWORD, clusterId)); user1.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try (Connection conn = ConnectionFactory.createConnection(getClientConf()); Table t = conn.getTable(tableName)) { Result r = t.get(new Get(Bytes.toBytes("r1"))); assertNotNull(r); assertFalse("Should have read a non-empty Result", r.isEmpty()); final Cell cell = r.getColumnLatestCell(Bytes.toBytes("f1"), Bytes.toBytes("q1")); assertTrue("Unexpected value", CellUtil.matchingValue(cell, Bytes.toBytes("1"))); return null; } } }); }
Example #2
Source File: HbaseImpl.java From tephra with MIT License | 6 votes |
@Override public JSONObject findById(String tableName, String id) { if (isDisabled() || validator.isEmpty(tableName) || validator.isEmpty(id)) return null; try { Table table = getTable(tableName); Result result = table.get(new Get(Bytes.toBytes(id))); if (result == null || result.isEmpty()) { table.close(); return null; } JSONObject object = new JSONObject(); setToJson(object, id, result); table.close(); return object; } catch (IOException e) { logger.warn(e, "检索HBase数据[{}:{}]时发生异常!", tableName, id); return null; } }
Example #3
Source File: udtfCheck.java From Transwarp-Sample-Code with MIT License | 6 votes |
@Override public void process(Object[] record) throws HiveException { final String document = (String) stringOI.getPrimitiveJavaObject(record[0]); if (document == null) { return; } String[] tokens = document.split(","); String[] results = tokens[1].split(" "); try { hTable = new HTable(conf, "bi"); Get get = new Get(Bytes.toBytes(tokens[0])); result = hTable.exists(get); } catch (Exception e) { e.printStackTrace(); } if (!result) { for (String r : results) { forward(new Object[]{tokens[0], r}); } } }
Example #4
Source File: TransactionAwareHTableTest.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private void verifyRows(Table 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: HBaseManager.java From hbase-secondary-index with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: HbOperate.java From tddl5 with Apache License 2.0 | 6 votes |
private Get buildGet(HbData opData) throws IOException { Get get = new Get(opData.getRowKey()); if (opData.getMaxVersion() > 0) { get.setMaxVersions(opData.getMaxVersion()); } for (HbColumn column : opData.getColumns()) { if (column.getTimestamp() > 0) { get.setTimeStamp(column.getTimestamp()); } else if (opData.getStartTime() > 0 && opData.getEndTime() > 0 && opData.getEndTime() > opData.getStartTime()) { get.setTimeRange(opData.getStartTime(), opData.getEndTime()); } if (StringUtils.isNotEmpty(column.getColumnFamily()) && StringUtils.isNotEmpty(column.getColumnName())) { get.addColumn(Bytes.toBytes(column.getColumnFamily()), Bytes.toBytes(column.getColumnName())); } } return get; }
Example #7
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 #8
Source File: HBaseStorage.java From cantor with Apache License 2.0 | 6 votes |
@Override public List<Long> timeMeta() { List<Long> times = new ArrayList<>(); Get get = (new Get(HBASE_LATTICE_KEY)).addFamily(INST_FAMILY); Result result; try { result = metaTable.get(get); List<Cell> cells = result.listCells(); if (log.isDebugEnabled()) log.debug("Time lattice is {}", cells.stream() .map(c -> Bytes.toLong(c.getValueArray(), c.getValueOffset())) .collect(Collectors.toList())); for (Cell cell : cells) { long current = Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); times.add(current); } } catch (Exception e) { if (log.isErrorEnabled()) log.error("get time lattice from hbase failed", e); } return times; }
Example #9
Source File: BackupSystemTable.java From hbase with Apache License 2.0 | 6 votes |
/** * Get backup set description (list of tables) * @param name set's name * @return list of tables in a backup set * @throws IOException if a table operation fails */ public List<TableName> describeBackupSet(String name) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace(" Backup set describe: " + name); } try (Table table = connection.getTable(tableName)) { Get get = createGetForBackupSet(name); Result res = table.get(get); if (res.isEmpty()) { return null; } res.advance(); String[] tables = cellValueToBackupSet(res.current()); return Arrays.asList(tables).stream().map(item -> TableName.valueOf(item)) .collect(Collectors.toList()); } }
Example #10
Source File: HBaseEventSubscription.java From mewbase with MIT License | 6 votes |
private Event waitForEvent(final long eventNumber) throws Exception { logger.debug("Waiting for event " + eventNumber); Get getter = new Get(Bytes.toBytes( eventNumber )); Event event = null; while ( event == null ) { Result r = channelTable.get(getter); if ( r.isEmpty() ) { Thread.sleep( WATCH_WINDOW_MILLIS); } else { final long timeStamp = r.rawCells()[0].getTimestamp(); final byte[] value = r.getValue(HBaseEventSink.colFamily, HBaseEventSink.qualifier); event = new FileEvent(eventNumber,timeStamp,0L, Unpooled.wrappedBuffer(value)); } } logger.debug("Got Event " + eventNumber); return event; }
Example #11
Source File: LocalMorphlineResultToSolrMapper.java From hbase-indexer with Apache License 2.0 | 6 votes |
@Override public Get getGet(byte[] row) { Get get = new Get(row); if (isSafeMode) { return get; } for (Entry<byte[], NavigableSet<byte[]>> familyMapEntry : familyMap.entrySet()) { // see DefaultResultToSolrMapper byte[] columnFamily = familyMapEntry.getKey(); if (familyMapEntry.getValue() == null) { get.addFamily(columnFamily); } else { for (byte[] qualifier : familyMapEntry.getValue()) { get.addColumn(columnFamily, qualifier); } } } return get; }
Example #12
Source File: SecondaryIndexTable.java From phoenix-tephra with Apache License 2.0 | 6 votes |
public Result[] getByIndex(byte[] value) throws IOException { try { transactionContext.start(); Scan scan = new Scan(value, Bytes.add(value, new byte[0])); scan.addColumn(secondaryIndexFamily, secondaryIndexQualifier); ResultScanner indexScanner = secondaryIndexTable.getScanner(scan); ArrayList<Get> gets = new ArrayList<>(); for (Result result : indexScanner) { for (Cell cell : result.listCells()) { gets.add(new Get(cell.getValue())); } } Result[] results = transactionAwareHTable.get(gets); transactionContext.finish(); return results; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
Example #13
Source File: HBaseRangerAuthorizationTest.java From ranger with Apache License 2.0 | 6 votes |
@Test public void testReadRowFromColFam2AsProcessOwner() throws Exception { final Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "localhost"); conf.set("hbase.zookeeper.property.clientPort", "" + port); conf.set("zookeeper.znode.parent", "/hbase-unsecure"); Connection conn = ConnectionFactory.createConnection(conf); Table table = conn.getTable(TableName.valueOf("temp")); // Read a row Get get = new Get(Bytes.toBytes("row1")); Result result = table.get(get); byte[] valResult = result.getValue(Bytes.toBytes("colfam2"), Bytes.toBytes("col1")); Assert.assertTrue(Arrays.equals(valResult, Bytes.toBytes("val2"))); conn.close(); }
Example #14
Source File: TestStoreScanner.java From hbase with Apache License 2.0 | 6 votes |
/** * Ensure that optimize does not cause the Get to do more seeking than required. Optimize * (see HBASE-15392) was causing us to seek all Cells in a block when a Get Scan if the next block * index/start key was a different row to the current one. A bug. We'd call next too often * because we had to exhaust all Cells in the current row making us load the next block just to * discard what we read there. This test is a little cryptic. Takes a bit of staring to figure * what it up to. */ @Test public void testOptimizeAndGetWithFakedNextBlockIndexStart() throws IOException { // First test a Get of second column in the row R2. Every Get is a Scan. Second column has a // qualifier of R2. Get get = new Get(THREE); get.addColumn(CF, TWO); Scan scan = new Scan(get); try (CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo)) { List<Cell> results = new ArrayList<>(); // For a Get there should be no more next's after the first call. assertEquals(false, scanner.next(results)); // Should be one result only. assertEquals(1, results.size()); // And we should have gone through optimize twice only. assertEquals("First qcode is SEEK_NEXT_COL and second INCLUDE_AND_SEEK_NEXT_ROW", 2, scanner.count.get()); } }
Example #15
Source File: HBaseStore.java From datacollector with Apache License 2.0 | 6 votes |
public Optional<String> get(Pair<String, HBaseColumn> key) throws Exception { if (key.getKey().isEmpty()) { return Optional.absent(); } Get g = new Get(Bytes.toBytes(key.getKey())); HBaseColumn hBaseColumn = key.getValue(); if (hBaseColumn.getCf().isPresent() && hBaseColumn.getQualifier().isPresent()) { g.addColumn(hBaseColumn.getCf().get(), hBaseColumn.getQualifier().get()); } if (hBaseColumn.getTimestamp().isPresent()) { g.setTimeStamp(hBaseColumn.getTimestamp().getAsLong()); } Result result = hBaseProcessor.get(g); String value = getValue(hBaseColumn, result); return Optional.fromNullable(value); }
Example #16
Source File: HBaseResourceStore.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
private Result internalGetFromHTable(Table table, String path, boolean fetchContent, boolean fetchTimestamp) throws IOException { byte[] rowkey = Bytes.toBytes(path); Get get = new Get(rowkey); if (!fetchContent && !fetchTimestamp) { get.setCheckExistenceOnly(true); } else { if (fetchContent) get.addColumn(B_FAMILY, B_COLUMN); if (fetchTimestamp) get.addColumn(B_FAMILY, B_COLUMN_TS); } Result result = table.get(get); boolean exists = result != null && (!result.isEmpty() || (result.getExists() != null && result.getExists())); return exists ? result : null; }
Example #17
Source File: SecondaryIndexTable.java From phoenix-tephra with Apache License 2.0 | 6 votes |
public Result[] getByIndex(byte[] value) throws IOException { try { transactionContext.start(); Scan scan = new Scan(value, Bytes.add(value, new byte[0])); scan.addColumn(secondaryIndexFamily, secondaryIndexQualifier); ResultScanner indexScanner = secondaryIndexTable.getScanner(scan); ArrayList<Get> gets = new ArrayList<Get>(); for (Result result : indexScanner) { for (Cell cell : result.listCells()) { gets.add(new Get(cell.getValue())); } } Result[] results = transactionAwareHTable.get(gets); transactionContext.finish(); return results; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
Example #18
Source File: RemoteHTable.java From hbase with Apache License 2.0 | 5 votes |
@Override public Result[] get(List<Get> gets) throws IOException { byte[][] rows = new byte[gets.size()][]; int maxVersions = 1; int count = 0; for (Get g : gets) { if (count == 0) { maxVersions = g.getMaxVersions(); } else if (g.getMaxVersions() != maxVersions) { LOG.warn( "MaxVersions on Gets do not match, using the first in the list (" + maxVersions + ")"); } if (g.getFilter() != null) { LOG.warn("filters not supported on gets"); } rows[count] = g.getRow(); count++; } String spec = buildMultiRowSpec(rows, maxVersions); return getResults(spec); }
Example #19
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Creates a {@link Get} which returns only {@link SpaceQuotaSnapshot} from the quota table for a * specific table. * @param tn table name to get from. Can't be null. */ public static Get makeQuotaSnapshotGetForTable(TableName tn) { Get g = new Get(getTableRowKey(tn)); // Limit to "u:v" column g.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY); return g; }
Example #20
Source File: TransactionProcessor.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { Transaction tx = getFromOperation(get); if (tx != null) { projectFamilyDeletes(get); get.setMaxVersions(); get.setTimeRange(TxUtils.getOldestVisibleTimestamp(ttlByFamily, tx, readNonTxnData), TxUtils.getMaxVisibleTimestamp(tx)); Filter newFilter = getTransactionFilter(tx, ScanType.USER_SCAN, get.getFilter()); get.setFilter(newFilter); } }
Example #21
Source File: MockHTable.java From metron with Apache License 2.0 | 5 votes |
@Override public Result[] get(List<Get> list) throws IOException { Result[] ret = new Result[list.size()]; int i = 0; for(Get g : list) { ret[i++] = get(g); } return ret; }
Example #22
Source File: TransactionAwareHTable.java From phoenix-tephra with Apache License 2.0 | 5 votes |
@Override public boolean[] exists(List<Get> gets) throws IOException { if (tx == null) { throw new IOException("Transaction not started"); } List<Get> transactionalizedGets = new ArrayList<>(gets.size()); for (Get get : gets) { transactionalizedGets.add(transactionalizeAction(get)); } return hTable.exists(transactionalizedGets); }
Example #23
Source File: TestCompaction.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Test(timeOut = 60_000) public void testNonOmidCFIsUntouched() throws Throwable { String TEST_TABLE = "testNonOmidCFIsUntouched"; createTableIfNotExists(TEST_TABLE, Bytes.toBytes(TEST_FAMILY)); TTable txTable = new TTable(connection, TEST_TABLE); admin.disableTable(TableName.valueOf(TEST_TABLE)); byte[] nonOmidCF = Bytes.toBytes("nonOmidCF"); byte[] nonOmidQual = Bytes.toBytes("nonOmidCol"); HColumnDescriptor nonomidfam = new HColumnDescriptor(nonOmidCF); nonomidfam.setMaxVersions(MAX_VERSIONS); admin.addColumn(TableName.valueOf(TEST_TABLE), nonomidfam); admin.enableTable(TableName.valueOf(TEST_TABLE)); byte[] rowId = Bytes.toBytes("testRow"); Transaction tx = tm.begin(); Put put = new Put(rowId); put.addColumn(fam, qual, Bytes.toBytes("testValue")); txTable.put(tx, put); Put nonTxPut = new Put(rowId); nonTxPut.addColumn(nonOmidCF, nonOmidQual, Bytes.toBytes("nonTxVal")); txTable.getHTable().put(nonTxPut); txTable.flushCommits(); // to make sure it left the client Get g = new Get(rowId); Result result = txTable.getHTable().get(g); assertEquals(result.getColumnCells(nonOmidCF, nonOmidQual).size(), 1, "Should be there, precompact"); assertEquals(result.getColumnCells(fam, qual).size(), 1, "Should be there, precompact"); compactEverything(TEST_TABLE); result = txTable.getHTable().get(g); assertEquals(result.getColumnCells(nonOmidCF, nonOmidQual).size(), 1, "Should be there, postcompact"); assertEquals(result.getColumnCells(fam, qual).size(), 0, "Should not be there, postcompact"); }
Example #24
Source File: HBaseTable.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
@Override public long getIndex(long pKey) { if (_log.isTraceEnabled()) { _log.trace("getIndex {} {}", this.tn.toString(), KeyBytes.toString(pKey)); } if (Thread.interrupted()) { throw new InterruptException(); } try { Table htable = getConnection().getTable(this.tn); Get get = new Get(Helper.antsKeyToHBase(pKey)); Result r = htable.get(get); if (r.isEmpty()) { return 0; } int size = Helper.getSize(r); long pLine = Helper.toIndexLine(getHeap(size * 2 + 0x100), r); if (pLine == 0) { return 0; } IndexLine line = new IndexLine(pLine); return line.getRowKey(); } catch (IOException x) { throw new OrcaHBaseException(x); } }
Example #25
Source File: HBaseNotificationStore.java From streamline with Apache License 2.0 | 5 votes |
@Override public StreamlineEvent getEvent(String eventId) { try { String tableName = eventMapper.getTableName(); LOG.debug("getting event with eventId {} from table {}", eventId, tableName); Get get = new Get(eventId.getBytes(StandardCharsets.UTF_8)); Result result = tables.get(tableName).get().get(get); return result.isEmpty() ? null : eventMapper.entity(result); } catch (IOException ex) { throw new NotificationStoreException("Error getting event id: " + eventId, ex); } }
Example #26
Source File: HBaseLogByRowkeyReader.java From eagle with Apache License 2.0 | 5 votes |
/** * Here all qualifiers' values goes into qualifierValues of InternalLog as given a row, we can't * differentiate it's a tag or a field * * @param rowkeys * @return * @throws IOException */ public List<InternalLog> get(List<byte[]> rowkeys) throws IOException, NoSuchRowException { final List<Get> gets = createGets(rowkeys); final Result[] results = tbl.get(gets); final List<InternalLog> logs = new ArrayList<InternalLog>(); for (Result result : results) { final InternalLog log = buildLog(result); logs.add(log); } return logs; }
Example #27
Source File: HBaseTransactionManager.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Override public Optional<Long> readCommitTimestampFromShadowCell(long startTimestamp) throws IOException { Get get = new Get(hBaseCellId.getRow()); byte[] family = hBaseCellId.getFamily(); byte[] shadowCellQualifier = CellUtils.addShadowCellSuffixPrefix(hBaseCellId.getQualifier()); get.addColumn(family, shadowCellQualifier); get.setMaxVersions(1); get.setTimeStamp(startTimestamp); Result result = tableAccessWrapper.get(get); if (result.containsColumn(family, shadowCellQualifier)) { return Optional.of(Bytes.toLong(result.getValue(family, shadowCellQualifier))); } return Optional.absent(); }
Example #28
Source File: SimpleRegionObserver.java From hbase with Apache License 2.0 | 5 votes |
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> results) throws IOException { RegionCoprocessorEnvironment e = c.getEnvironment(); assertNotNull(e); assertNotNull(e.getRegion()); assertNotNull(get); assertNotNull(results); ctPreGet.incrementAndGet(); }
Example #29
Source File: TestWALSplitToHFile.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testDifferentRootDirAndWALRootDir() throws Exception { // Change wal root dir and reset the configuration Path walRootDir = UTIL.createWALRootDir(); this.conf = HBaseConfiguration.create(UTIL.getConfiguration()); FileSystem walFs = CommonFSUtils.getWALFileSystem(this.conf); this.oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME); String serverName = ServerName.valueOf(TEST_NAME.getMethodName() + "-manual", 16010, System.currentTimeMillis()) .toString(); this.logName = AbstractFSWALProvider.getWALDirectoryName(serverName); this.logDir = new Path(walRootDir, logName); this.wals = new WALFactory(conf, TEST_NAME.getMethodName()); Pair<TableDescriptor, RegionInfo> pair = setupTableAndRegion(); TableDescriptor td = pair.getFirst(); RegionInfo ri = pair.getSecond(); WAL wal = createWAL(walFs, walRootDir, logName); HRegion region = HRegion.openHRegion(this.conf, this.fs, rootDir, ri, td, wal); writeData(td, region); // Now close the region without flush region.close(true); wal.shutdown(); // split the log WALSplitter.split(walRootDir, logDir, oldLogDir, FileSystem.get(this.conf), this.conf, wals); WAL wal2 = createWAL(walFs, walRootDir, logName); HRegion region2 = HRegion.openHRegion(this.conf, this.fs, rootDir, ri, td, wal2); Result result2 = region2.get(new Get(ROW)); assertEquals(td.getColumnFamilies().length, result2.size()); for (ColumnFamilyDescriptor cfd : td.getColumnFamilies()) { assertTrue(Bytes.equals(VALUE1, result2.getValue(cfd.getName(), QUALIFIER))); } }
Example #30
Source File: PermissionStorage.java From hbase with Apache License 2.0 | 5 votes |
/** * 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; }