org.apache.hadoop.hbase.client.Result Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.Result. 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: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void verifyNumericRows(Table table, final byte[] f, int startRow, int endRow,
    int replicaId)
    throws IOException {
  for (int i = startRow; i < endRow; i++) {
    String failMsg = "Failed verification of row :" + i;
    byte[] data = Bytes.toBytes(String.valueOf(i));
    Get get = new Get(data);
    get.setReplicaId(replicaId);
    get.setConsistency(Consistency.TIMELINE);
    Result result = table.get(get);
    assertTrue(failMsg, result.containsColumn(f, null));
    assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
    Cell cell = result.getColumnLatestCell(f, null);
    assertTrue(failMsg,
      Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
        cell.getValueLength()));
  }
}
 
Example #2
Source File: ResultSerialization.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public Result deserialize(Result mutation) throws IOException {
  int totalBuffer = in.readInt();
  if (totalBuffer == 0) {
    return Result.EMPTY_RESULT;
  }
  byte[] buf = new byte[totalBuffer];
  readChunked(in, buf, 0, totalBuffer);
  List<Cell> kvs = new ArrayList<>();
  int offset = 0;
  while (offset < totalBuffer) {
    int keyLength = Bytes.toInt(buf, offset);
    offset += Bytes.SIZEOF_INT;
    kvs.add(new KeyValue(buf, offset, keyLength));
    offset += keyLength;
  }
  return Result.create(kvs);
}
 
Example #3
Source File: HbaseServiceImpl.java    From searchanalytics-bigdata with MIT License 6 votes vote down vote up
@Override
public List<String> getSearchClicks() {
	LOG.debug("Checking searchclicks table content!");
	Scan scan = new Scan();
	scan.addFamily(HbaseJsonEventSerializer.COLUMFAMILY_CLIENT_BYTES);
	scan.addFamily(HbaseJsonEventSerializer.COLUMFAMILY_SEARCH_BYTES);
	scan.addFamily(HbaseJsonEventSerializer.COLUMFAMILY_FILTERS_BYTES);
	List<String> rows = hbaseTemplate.find("searchclicks", scan,
			new RowMapper<String>() {
				@Override
				public String mapRow(Result result, int rowNum)
						throws Exception {
					return Arrays.toString(result.rawCells());
				}
			});
	for (String row : rows) {
		LOG.debug("searchclicks table content, Table returned row: {}", row);
	}
	LOG.debug("Checking searchclicks table content done!");
	return rows;
}
 
Example #4
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
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: TestReplicationStuckWithDroppedTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void verifyReplicationStuck() throws Exception {
  try (Table normalTable = utility1.getConnection().getTable(NORMAL_TABLE)) {
    Put put = new Put(ROW);
    put.addColumn(FAMILY, QUALIFIER, VALUE);
    normalTable.put(put);
  }
  try (Table normalTable = utility2.getConnection().getTable(NORMAL_TABLE)) {
    for (int i = 0; i < NB_RETRIES; i++) {
      Result result = normalTable.get(new Get(ROW).addColumn(FAMILY, QUALIFIER));
      if (result != null && !result.isEmpty()) {
        fail("Edit should have been stuck behind dropped tables, but value is " + Bytes
            .toString(result.getValue(FAMILY, QUALIFIER)));
      } else {
        LOG.info("Row not replicated, let's wait a bit more...");
        Thread.sleep(SLEEP_TIME);
      }
    }
  }
}
 
Example #6
Source File: HBaseStore.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private String getValue(HBaseColumn hBaseColumn, Result result) {
  String value = null;
  if (result.isEmpty()) {
    return value;
  }
  if (!hBaseColumn.getCf().isPresent() || !hBaseColumn.getQualifier().isPresent()) {
    Map<String, String> columnMap = new HashMap<>();
    // parse column family, column, timestamp, and value
    for (Map.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> entry : result.getMap().entrySet()) {
      String columnFamily = Bytes.toString(entry.getKey());
      for (Map.Entry<byte[], NavigableMap<Long, byte[]>> cells : entry.getValue().entrySet()) {
        String column = Bytes.toString(cells.getKey());
        NavigableMap<Long, byte[]> cell = cells.getValue();
        Map.Entry<Long, byte[]> v = cell.lastEntry();
        String columnValue = Bytes.toString(v.getValue());
        columnMap.put(columnFamily + ":" + column, columnValue);
      }
    }
    JSONObject json = new JSONObject(columnMap);
    value = json.toString();
  } else {
    value = Bytes.toString(result.getValue(hBaseColumn.getCf().get(), hBaseColumn.getQualifier().get()));
  }
  return value;
}
 
Example #7
Source File: TestDeletion.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
private Map<FamCol, Integer> countColsInRows(ResultScanner rs, FamCol... famCols) throws IOException {
    Map<FamCol, Integer> colCount = new HashMap<>();
    Result r = rs.next();
    while (r != null) {
        for (FamCol col : famCols) {
            if (r.containsColumn(col.fam, col.col)) {
                Integer c = colCount.get(col);

                if (c == null) {
                    colCount.put(col, 1);
                } else {
                    colCount.put(col, c + 1);
                }
            }
        }
        r = rs.next();
    }
    return colCount;
}
 
Example #8
Source File: TestPartialResultsFromClientSide.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that result contains all the key values within expKvList. Fails the test otherwise
 * @param result
 * @param expKvList
 * @param msg
 */
static void verifyResult(Result result, List<Cell> expKvList, String msg) {
  if (LOG.isInfoEnabled()) {
    LOG.info(msg);
    LOG.info("Expected count: " + expKvList.size());
    LOG.info("Actual count: " + result.size());
  }

  if (expKvList.isEmpty()) return;

  int i = 0;
  for (Cell kv : result.rawCells()) {
    if (i >= expKvList.size()) {
      break; // we will check the size later
    }

    Cell kvExp = expKvList.get(i++);
    assertTrue("Not equal. get kv: " + kv.toString() + " exp kv: " + kvExp.toString(),
        kvExp.equals(kv));
  }

  assertEquals(expKvList.size(), result.size());
}
 
Example #9
Source File: MockHTable.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Result[] get(List<Get> gets) throws IOException {
    List<Result> results = new ArrayList<Result>();
    for (Get g : gets) {
        results.add(get(g));
    }
    return results.toArray(new Result[results.size()]);
}
 
Example #10
Source File: TestVisibilityLabelsWithDefaultVisLabelService.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testVisibilityLabelsOnWALReplay() throws Exception {
  final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  try (Table table = createTableAndWriteDataWithLabels(tableName,
      "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)) {
    List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster()
        .getRegionServerThreads();
    for (RegionServerThread rsThread : regionServerThreads) {
      rsThread.getRegionServer().abort("Aborting ");
    }
    // Start one new RS
    RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
    waitForLabelsRegionAvailability(rs.getRegionServer());
    Scan s = new Scan();
    s.setAuthorizations(new Authorizations(SECRET));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);
    assertTrue(next.length == 1);
  }
}
 
Example #11
Source File: HelloHBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes Table#get and prints out the contents of the retrieved row.
 *
 * @param table Standard Table object
 * @throws IOException If IO problem encountered
 */
static void getAndPrintRowContents(final Table table) throws IOException {

  Result row = table.get(new Get(MY_ROW_ID));

  System.out.println("Row [" + Bytes.toString(row.getRow())
          + "] was retrieved from Table ["
          + table.getName().getNameAsString()
          + "] in HBase, with the following content:");

  for (Entry<byte[], NavigableMap<byte[], byte[]>> colFamilyEntry
          : row.getNoVersionMap().entrySet()) {
    String columnFamilyName = Bytes.toString(colFamilyEntry.getKey());

    System.out.println("  Columns in Column Family [" + columnFamilyName
            + "]:");

    for (Entry<byte[], byte[]> columnNameAndValueMap
            : colFamilyEntry.getValue().entrySet()) {

      System.out.println("    Value of Column [" + columnFamilyName + ":"
              + Bytes.toString(columnNameAndValueMap.getKey()) + "] == "
              + Bytes.toString(columnNameAndValueMap.getValue()));
    }
  }
}
 
Example #12
Source File: ThriftHBaseServiceHandler.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public List<TRowResult> scannerGetList(int id,int nbRows)
    throws IllegalArgument, IOError {
  LOG.debug("scannerGetList: id={}", id);
  ResultScannerWrapper resultScannerWrapper = getScanner(id);
  if (null == resultScannerWrapper) {
    String message = "scanner ID is invalid";
    LOG.warn(message);
    throw new IllegalArgument("scanner ID is invalid");
  }

  Result [] results;
  try {
    results = resultScannerWrapper.getScanner().next(nbRows);
    if (null == results) {
      return new ArrayList<>();
    }
  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw getIOError(e);
  }
  return ThriftUtilities.rowResultFromHBase(results, resultScannerWrapper.isColumnSorted());
}
 
Example #13
Source File: HBaseStorageService.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Map<String, byte[]> get_(String ns, String tn, byte[] key) 
throws IOException {
    ns = (ns.equals(Orca.SYSNS)) ? this.sysns : ns;
        TableName tableName = TableName.valueOf(ns, tn);
    Result r = Helper.get(this.hbaseConnection, tableName, key);
    if (r.isEmpty()) {
        return null;
    }
    Map<String, byte[]> row = new HashMap<>();
    for (Map.Entry<byte[],NavigableMap<byte[],byte[]>> i:r.getNoVersionMap().entrySet()) {
        String cf =  new String(i.getKey());
        for (Map.Entry<byte[],byte[]> j:i.getValue().entrySet()) {
            String q = new String(j.getKey());
            row.put(cf + ":" + q, j.getValue());
        }
    }
    return row;
}
 
Example #14
Source File: HbaseSessions.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
/**
 * Just for debug
 */
@SuppressWarnings("unused")
private void dump(String table, Scan scan) throws IOException {
    System.out.println(String.format(">>>> scan table %s with %s",
                                     table, scan));
    RowIterator iterator = this.scan(table, scan);
    while (iterator.hasNext()) {
        Result row = iterator.next();
        System.out.println(StringEncoding.format(row.getRow()));
        CellScanner cellScanner = row.cellScanner();
        while (cellScanner.advance()) {
            Cell cell = cellScanner.current();
            byte[] key = CellUtil.cloneQualifier(cell);
            byte[] val = CellUtil.cloneValue(cell);
            System.out.println(String.format("  %s=%s",
                               StringEncoding.format(key),
                               StringEncoding.format(val)));
        }
    }
}
 
Example #15
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
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 #16
Source File: HbaseTables.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseRowColumns(Result row, BackendEntry entry,
                               Query query) throws IOException {
    /*
     * Collapse owner-vertex id from edge id, NOTE: unneeded to
     * collapse if BinarySerializer.keyWithIdPrefix set to true
     */
    byte[] key = row.getRow();
    key = Arrays.copyOfRange(key, entry.id().length(), key.length);

    long total = query.total();
    CellScanner cellScanner = row.cellScanner();
    while (cellScanner.advance() && total-- > 0) {
        Cell cell = cellScanner.current();
        assert CellUtil.cloneQualifier(cell).length == 0;
        entry.columns(BackendColumn.of(key, CellUtil.cloneValue(cell)));
    }
}
 
Example #17
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Delete prune upper bounds for the regions that are not in the given exclude set, and the
 * prune upper bound is less than the given value.
 * After the invalid list is pruned up to deletionPruneUpperBound, we do not need entries for regions that have
 * prune upper bound less than deletionPruneUpperBound. We however limit the deletion to only regions that are
 * no longer in existence (due to deletion, etc.), to avoid update/delete race conditions.
 *
 * @param deletionPruneUpperBound prune upper bound below which regions will be deleted
 * @param excludeRegions set of regions that should not be deleted
 * @throws IOException when not able to delete data in HBase
 */
public void deletePruneUpperBounds(long deletionPruneUpperBound, SortedSet<byte[]> excludeRegions)
  throws IOException {
  try (HTableInterface stateTable = stateTableSupplier.get()) {
    byte[] startRow = makeRegionKey(EMPTY_BYTE_ARRAY);
    Scan scan = new Scan(startRow, REGION_KEY_PREFIX_STOP);
    scan.addColumn(FAMILY, PRUNE_UPPER_BOUND_COL);

    try (ResultScanner scanner = stateTable.getScanner(scan)) {
      Result next;
      while ((next = scanner.next()) != null) {
        byte[] region = getRegionFromKey(next.getRow());
        if (!excludeRegions.contains(region)) {
          byte[] timeBytes = next.getValue(FAMILY, PRUNE_UPPER_BOUND_COL);
          if (timeBytes != null) {
            long pruneUpperBoundRegion = Bytes.toLong(timeBytes);
            if (pruneUpperBoundRegion < deletionPruneUpperBound) {
              stateTable.delete(new Delete(next.getRow()));
            }
          }
        }
      }
    }
  }
}
 
Example #18
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private void testDeleteRollback(TxConstants.ConflictDetection conflictDetection) throws Exception {
  String tableName = String.format("%s%s", "TestColFamilyDelete", conflictDetection);
  Table hTable = createTable(Bytes.toBytes(tableName), new byte[][]{TestBytes.family});
  try (TransactionAwareHTable txTable = new TransactionAwareHTable(hTable, conflictDetection)) {
    TransactionContext txContext = new TransactionContext(new InMemoryTxSystemClient(txManager), txTable);
    txContext.start();
    txTable.put(new Put(TestBytes.row).add(TestBytes.family, TestBytes.qualifier, TestBytes.value));
    txContext.finish();

    // Start a tx, delete the row and then abort the tx
    txContext.start();
    txTable.delete(new Delete(TestBytes.row));
    txContext.abort();

    // Start a tx, delete a column family and then abort the tx
    txContext.start();
    txTable.delete(new Delete(TestBytes.row).deleteFamily(TestBytes.family));
    txContext.abort();

    // Above operations should have no effect on the row, since they were aborted
    txContext.start();
    Get get = new Get(TestBytes.row);
    Result result = txTable.get(get);
    assertFalse(result.isEmpty());
    assertArrayEquals(TestBytes.value, result.getValue(TestBytes.family, TestBytes.qualifier));
    txContext.finish();
  }
}
 
Example #19
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Check if WAL file is eligible for deletion Future: to support all backup destinations
 * @param file name of a file to check
 * @return true, if deletable, false otherwise.
 * @throws IOException exception
 */
// TODO: multiple backup destination support
public boolean isWALFileDeletable(String file) throws IOException {
  if (LOG.isTraceEnabled()) {
    LOG.trace("Check if WAL file has been already backed up in backup system table " + file);
  }
  try (Table table = connection.getTable(tableName)) {
    Get get = createGetForCheckWALFile(file);
    Result res = table.get(get);
    return (!res.isEmpty());
  }
}
 
Example #20
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private void verifyScan(HTableInterface table, Scan scan, List<KeyValue> expectedCells) throws Exception {
  List<Cell> actualCells = new ArrayList<>();
  try (ResultScanner scanner = table.getScanner(scan)) {
    Result[] results = scanner.next(expectedCells.size() + 1);
    for (Result result : results) {
      actualCells.addAll(Lists.newArrayList(result.rawCells()));
    }
    Assert.assertEquals(expectedCells, actualCells);
  }
}
 
Example #21
Source File: TestPartialResultsFromClientSide.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMayHaveMoreCellsInRowReturnsTrueAndSetBatch() throws IOException {
  Table table = createTestTable(TableName.valueOf(name.getMethodName()), ROWS, FAMILIES,
      QUALIFIERS, VALUE);
  Scan scan = new Scan();
  scan.setBatch(1);
  scan.setFilter(new FirstKeyOnlyFilter());
  ResultScanner scanner = table.getScanner(scan);
  Result result;
  while ((result = scanner.next()) != null) {
    assertTrue(result.rawCells() != null);
    assertEquals(1, result.rawCells().length);
  }
}
 
Example #22
Source File: HBaseEdgeInputFormat.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected Tuple3<K, K, V> mapResultToTuple(Result r) {
    HBaseEdge edge = parseHBaseEdge(r);
    V property = property(edge, getPropertyName());
    return property != null
           ? new Tuple3<>((K) edge.outVertex().id(), (K) edge.inVertex().id (), property)
           : null;
}
 
Example #23
Source File: FlappingLocalIndexIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildIndexWhenUserTableAlreadyHasData() throws Exception {
    String tableName = schemaName + "." + generateUniqueName();
    String indexName = "IDX_" + generateUniqueName();
    String indexTableName = schemaName + "." + indexName;
    TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped);
    String indexPhysicalTableName = physicalTableName.getNameAsString();

    createBaseTable(tableName, null, "('e','i','o')");
    Connection conn1 = DriverManager.getConnection(getUrl());
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')");
    conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')");
    conn1.commit();
    conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
    ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName);
    assertTrue(rs.next());
    assertEquals(4, rs.getInt(1));
    Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
    org.apache.hadoop.hbase.client.Connection hbaseConn = admin.getConnection();
    Table indexTable = hbaseConn.getTable(TableName.valueOf(indexPhysicalTableName));
    Pair<byte[][], byte[][]> startEndKeys = hbaseConn.getRegionLocator(TableName.valueOf(indexPhysicalTableName)).getStartEndKeys();
    byte[][] startKeys = startEndKeys.getFirst();
    byte[][] endKeys = startEndKeys.getSecond();
    for (int i = 0; i < startKeys.length; i++) {
        Scan s = new Scan();
        s.addFamily(QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES);
        s.setStartRow(startKeys[i]);
        s.setStopRow(endKeys[i]);
        ResultScanner scanner = indexTable.getScanner(s);
        int count = 0;
        for(Result r:scanner){
            count++;
        }
        scanner.close();
        assertEquals(1, count);
    }
    indexTable.close();
}
 
Example #24
Source File: SecondaryIndexTable.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
public Result[] get(List<Get> gets) throws IOException {
  try {
    transactionContext.start();
    Result[] result = transactionAwareHTable.get(gets);
    transactionContext.finish();
    return result;
  } catch (Exception e) {
    try {
      transactionContext.abort();
    } catch (TransactionFailureException e1) {
      throw new IOException("Could not rollback transaction", e1);
    }
  }
  return null;
}
 
Example #25
Source File: DefaultResultToSolrMapper.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
@Override
public void map(Result result, SolrUpdateWriter solrUpdateWriter) {
    TimerContext timerContext = mappingTimer.time();
    try {
        SolrInputDocument solrInputDocument = new SolrInputDocument();
        for (SolrDocumentExtractor documentExtractor : resultDocumentExtractors) {
            documentExtractor.extractDocument(result, solrInputDocument);
        }
        solrUpdateWriter.add(solrInputDocument);
    } finally {
        timerContext.stop();
    }
}
 
Example #26
Source File: Results.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static ByteBuffer getValueAsByteBuffer(Result hbaseRow, byte[] cf, byte[] cq) {
    List<Cell> cells = hbaseRow.listCells();
    if (cells == null || cells.size() == 0) {
        return null;
    } else {
        for (Cell c : cells) {
            if (Bytes.compareTo(cf, 0, cf.length, c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength()) == 0 && //
                    Bytes.compareTo(cq, 0, cq.length, c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()) == 0) {
                return ByteBuffer.wrap(c.getValueArray(), c.getValueOffset(), c.getValueLength());
            }
        }
    }
    return null;
}
 
Example #27
Source File: AclService.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
    List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>();
    HTableInterface htable = null;
    try {
        htable = HBaseConnection.get(hbaseUrl).getTable(aclTableName);

        Scan scan = new Scan();
        SingleColumnValueFilter parentFilter = new SingleColumnValueFilter(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_PARENT_COLUMN), CompareOp.EQUAL, domainObjSerializer.serialize(new DomainObjectInfo(parentIdentity)));
        parentFilter.setFilterIfMissing(true);
        scan.setFilter(parentFilter);

        ResultScanner scanner = htable.getScanner(scan);
        for (Result result = scanner.next(); result != null; result = scanner.next()) {
            String id = Bytes.toString(result.getRow());
            String type = Bytes.toString(result.getValue(Bytes.toBytes(ACL_INFO_FAMILY), Bytes.toBytes(ACL_INFO_FAMILY_TYPE_COLUMN)));

            oids.add(new ObjectIdentityImpl(type, id));
        }
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(htable);
    }

    return oids;
}
 
Example #28
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Return an md5 digest of the entire contents of a table.
 */
public String checksumRows(final Table table) throws Exception {

  Scan scan = new Scan();
  ResultScanner results = table.getScanner(scan);
  MessageDigest digest = MessageDigest.getInstance("MD5");
  for (Result res : results) {
    digest.update(res.getRow());
  }
  results.close();
  return digest.toString();
}
 
Example #29
Source File: HBaseInternalLogHelper.java    From Eagle with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param ed
 * @param r
 * @param qualifiers if null, return all qualifiers defined in ed
 * @return
 */
public static InternalLog parse(EntityDefinition ed, Result r, byte[][] qualifiers) {
	final byte[] row = r.getRow();
	// skip the first 4 bytes : prefix
	final int offset = (ed.getPartitions() == null) ? (4) : (4 + ed.getPartitions().length * 4);
	long timestamp = ByteUtil.bytesToLong(row, offset);
	// reverse timestamp
	timestamp = Long.MAX_VALUE - timestamp;
	final byte[] family = ed.getColumnFamily().getBytes();
	final Map<String, byte[]> allQualifierValues = new HashMap<String, byte[]>();

	if (qualifiers != null) {
		int count = qualifiers.length;
		final byte[][] values = new byte[count][];
		for (int i = 0; i < count; i++) {
			// TODO if returned value is null, it means no this column for this row, so why set null to the object?
			values[i] = r.getValue(family, qualifiers[i]);
			allQualifierValues.put(new String(qualifiers[i]), values[i]);
		}
	}else{
		// return all qualifiers
		for(KeyValue kv:r.list()){
			byte[] qualifier = kv.getQualifier();
			byte[] value = kv.getValue();
			allQualifierValues.put(new String(qualifier),value);
		}
	}
	final InternalLog log = buildObject(ed, row, timestamp, allQualifierValues);
	return log;
}
 
Example #30
Source File: BaseDao.java    From zxl with Apache License 2.0 5 votes vote down vote up
protected final List<E> parse(ResultScanner resultScanner) {
	List<E> resultList = new ArrayList<E>();
	if (BeanUtil.isEmpty(resultScanner)) {
		return resultList;
	}
	for (Result result : resultScanner) {
		resultList.add(parse(result));
	}
	return resultList;
}