org.apache.hadoop.hbase.Cell Java Examples

The following examples show how to use org.apache.hadoop.hbase.Cell. 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: StoreHotnessProtector.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void finish(Map<byte[], List<Cell>> familyMaps) {
  if (!isEnable()) {
    return;
  }

  for (Map.Entry<byte[], List<Cell>> e : familyMaps.entrySet()) {
    Store store = this.region.getStore(e.getKey());
    if (store == null || e.getValue() == null) {
      continue;
    }
    if (e.getValue().size() > this.parallelPutToStoreThreadLimitCheckMinColumnCount) {
      AtomicInteger counter = preparePutToStoreMap.get(e.getKey());
      // preparePutToStoreMap will be cleared when changing the configuration, so it may turn
      // into a negative value. It will be not accuracy in a short time, it's a trade-off for
      // performance.
      if (counter != null && counter.decrementAndGet() < 0) {
        counter.incrementAndGet();
      }
    }
  }
}
 
Example #2
Source File: TupleProjector.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Iterate over the list of cells returned from the scan and return a tuple projector for the
 * dynamic columns by parsing the metadata stored for the list of dynamic columns
 * @param result list of cells
 * @param dynCols list of dynamic columns to be populated
 * @param dynColCells list of cells corresponding to dynamic columns to be populated
 * @return The tuple projector corresponding to dynamic columns or null if there are no dynamic
 * columns to process
 * @throws InvalidProtocolBufferException Thrown if there is an error parsing byte[] to protobuf
 */
public static TupleProjector getDynamicColumnsTupleProjector(List<Cell> result,
        List<PColumn> dynCols, List<Cell> dynColCells) throws InvalidProtocolBufferException {
    Set<Pair<ByteBuffer, ByteBuffer>> dynColCellQualifiers = new HashSet<>();
    populateDynColsFromResult(result, dynCols, dynColCellQualifiers);
    if (dynCols.isEmpty()) {
        return null;
    }
    populateDynamicColumnCells(result, dynColCellQualifiers, dynColCells);
    if (dynColCells.isEmpty()) {
        return null;
    }
    KeyValueSchema dynColsSchema = PhoenixRuntime.buildKeyValueSchema(dynCols);
    Expression[] expressions = new Expression[dynCols.size()];
    for (int i = 0; i < dynCols.size(); i++) {
        expressions[i] = new KeyValueColumnExpression(dynCols.get(i));
    }
    return new TupleProjector(dynColsSchema, expressions);
}
 
Example #3
Source File: ResultTuple.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append("keyvalues=");
  if(this.result == null || this.result.isEmpty()) {
    sb.append("NONE");
    return sb.toString();
  }
  sb.append("{");
  boolean moreThanOne = false;
  for(Cell kv : this.result.listCells()) {
    if(moreThanOne) {
      sb.append(", \n");
    } else {
      moreThanOne = true;
    }
    sb.append(kv.toString()+"/value="+Bytes.toString(kv.getValueArray(), 
      kv.getValueOffset(), kv.getValueLength()));
  }
  sb.append("}\n");
  return sb.toString();
}
 
Example #4
Source File: MockHBaseClientService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public boolean checkAndPut(final String tableName, final byte[] rowId, final byte[] family, final byte[] qualifier, final byte[] value, final PutColumn column) throws IOException {
    for (Result result : results.values()) {
        if (Arrays.equals(result.getRow(), rowId)) {
            Cell[] cellArray = result.rawCells();
            for (Cell cell : cellArray) {
                if (Arrays.equals(cell.getFamilyArray(), family) && Arrays.equals(cell.getQualifierArray(), qualifier)) {
                     if (value == null || !Arrays.equals(cell.getValueArray(), value)) {
                         return false;
                     }
                }
            }
        }
    }

    final List<PutColumn> putColumns = new ArrayList<PutColumn>();
    putColumns.add(column);
    put(tableName, rowId, putColumns);
    return true;
}
 
Example #5
Source File: Result.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected int binarySearch(final Cell [] kvs,
                           final byte [] family,
                           final byte [] qualifier) {
  byte[] familyNotNull = notNullBytes(family);
  byte[] qualifierNotNull = notNullBytes(qualifier);
  Cell searchTerm =
      PrivateCellUtil.createFirstOnRow(kvs[0].getRowArray(),
          kvs[0].getRowOffset(), kvs[0].getRowLength(),
          familyNotNull, 0, (byte)familyNotNull.length,
          qualifierNotNull, 0, qualifierNotNull.length);

  // pos === ( -(insertion point) - 1)
  int pos = Arrays.binarySearch(kvs, searchTerm, CellComparator.getInstance());
  // never will exact match
  if (pos < 0) {
    pos = (pos+1) * -1;
    // pos is now insertion point
  }
  if (pos == kvs.length) {
    return -1; // doesn't exist
  }
  return pos;
}
 
Example #6
Source File: TestStoreScanner.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteVersionMaskingMultiplePuts() throws IOException {
  long now = System.currentTimeMillis();
  KeyValue [] kvs1 = new KeyValue[] {
      create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"),
      create("R1", "cf", "a", now, KeyValue.Type.Delete, "dont-care")
  };
  KeyValue [] kvs2 = new KeyValue[] {
      create("R1", "cf", "a", now-500, KeyValue.Type.Put, "dont-care"),
      create("R1", "cf", "a", now-100, KeyValue.Type.Put, "dont-care"),
      create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care")
  };
  List<KeyValueScanner> scanners = scanFixture(kvs1, kvs2);

  try (StoreScanner scan = new StoreScanner(new Scan().withStartRow(Bytes.toBytes("R1")),
      scanInfo, getCols("a"), scanners)) {
    List<Cell> results = new ArrayList<>();
    // the two put at ts=now will be masked by the 1 delete, and
    // since the scan default returns 1 version we'll return the newest
    // key, which is kvs[2], now-100.
    assertEquals(true, scan.next(results));
    assertEquals(1, results.size());
    assertEquals(kvs2[1], results.get(0));
  }
}
 
Example #7
Source File: ReversedKeyValueHeap.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public boolean backwardSeek(Cell seekKey) throws IOException {
  if (current == null) {
    return false;
  }
  heap.add(current);
  current = null;

  KeyValueScanner scanner;
  while ((scanner = heap.poll()) != null) {
    Cell topKey = scanner.peek();
    if ((CellUtil.matchingRows(seekKey, topKey) && comparator
        .getComparator().compare(seekKey, topKey) <= 0)
        || comparator.getComparator().compareRows(seekKey, topKey) > 0) {
      heap.add(scanner);
      current = pollRealKV();
      return current != null;
    }
    if (!scanner.backwardSeek(seekKey)) {
      this.scannersForDelayedClose.add(scanner);
    } else {
      heap.add(scanner);
    }
  }
  return false;
}
 
Example #8
Source File: AuthManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Check if user has given action privilige in cell scope.
 * @param user user name
 * @param table table name
 * @param cell cell to be checked
 * @param action one of action in [Read, Write, Create, Exec, Admin]
 * @return true if user has, false otherwise
 */
public boolean authorizeCell(User user, TableName table, Cell cell, Permission.Action action) {
  try {
    List<Permission> perms = PermissionStorage.getCellPermissionsForUser(user, cell);
    if (LOG.isTraceEnabled()) {
      LOG.trace("Perms for user {} in table {} in cell {}: {}",
        user.getShortName(), table, cell, (perms != null ? perms : ""));
    }
    if (perms != null) {
      for (Permission p: perms) {
        if (p.implies(action)) {
          return true;
        }
      }
    }
  } catch (IOException e) {
    // We failed to parse the KV tag
    LOG.error("Failed parse of ACL tag in cell " + cell);
    // Fall through to check with the table and CF perms we were able
    // to collect regardless
  }
  return false;
}
 
Example #9
Source File: BigtableMocker.java    From styx with Apache License 2.0 6 votes vote down vote up
private ResultScanner resultOfScan(List<Cell> cells, Scan scan) throws IOException {
  byte[] startRow = scan.getStartRow();
  byte[] stopRow = scan.getStopRow();

  List<Result> inRangeResults = cells.stream().filter(
      cell -> Bytes.compareTo(startRow, cell.getRowArray()) <= 0
              && Bytes.compareTo(stopRow, cell.getRowArray()) > 0)
      .map(cell -> Result.create(new Cell[] {cell}))
      .collect(toList());

  ResultScanner resultScanner = mock(ResultScanner.class);
  when(resultScanner.iterator()).thenReturn(inRangeResults.iterator());

  if (!inRangeResults.isEmpty()) {
    Result first = inRangeResults.get(0);
    Result[] rest = inRangeResults.subList(1, inRangeResults.size())
        .toArray(new Result[inRangeResults.size()]);
    rest[rest.length - 1] = null; // signal end of scanner
    when(resultScanner.next()).thenReturn(first, rest);
  }

  return resultScanner;
}
 
Example #10
Source File: TestMetaTableAccessorNoCluster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetHRegionInfo() throws IOException {
  assertNull(CatalogFamilyFormat.getRegionInfo(new Result()));

  List<Cell> kvs = new ArrayList<>();
  Result r = Result.create(kvs);
  assertNull(CatalogFamilyFormat.getRegionInfo(r));

  byte[] f = HConstants.CATALOG_FAMILY;
  // Make a key value that doesn't have the expected qualifier.
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.SERVER_QUALIFIER, f));
  r = Result.create(kvs);
  assertNull(CatalogFamilyFormat.getRegionInfo(r));
  // Make a key that does not have a regioninfo value.
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, f));
  RegionInfo hri = CatalogFamilyFormat.getRegionInfo(Result.create(kvs));
  assertTrue(hri == null);
  // OK, give it what it expects
  kvs.clear();
  kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER,
    RegionInfo.toByteArray(RegionInfoBuilder.FIRST_META_REGIONINFO)));
  hri = CatalogFamilyFormat.getRegionInfo(Result.create(kvs));
  assertNotNull(hri);
  assertTrue(RegionInfo.COMPARATOR.compare(hri, RegionInfoBuilder.FIRST_META_REGIONINFO) == 0);
}
 
Example #11
Source File: Result.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @return String
 */
@Override
public String toString() {
  StringBuilder sb = new StringBuilder();
  sb.append("keyvalues=");
  if(isEmpty()) {
    sb.append("NONE");
    return sb.toString();
  }
  sb.append("{");
  boolean moreThanOne = false;
  for(Cell kv : this.cells) {
    if(moreThanOne) {
      sb.append(", ");
    } else {
      moreThanOne = true;
    }
    sb.append(kv.toString());
  }
  sb.append("}");
  return sb.toString();
}
 
Example #12
Source File: DataJanitorState.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of {@link RegionPruneInfo} for given regions. Returns all regions if the given regions set is null.
 *
 * @param regions a set of regions
 * @return list of {@link RegionPruneInfo}s.
 * @throws IOException when not able to read the data from HBase
 */
public List<RegionPruneInfo> getPruneInfoForRegions(@Nullable SortedSet<byte[]> regions) throws IOException {
  List<RegionPruneInfo> regionPruneInfos = new ArrayList<>();
  try (Table 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 (regions == null || regions.contains(region)) {
          Cell cell = next.getColumnLatestCell(FAMILY, PRUNE_UPPER_BOUND_COL);
          if (cell != null) {
            byte[] pruneUpperBoundBytes = CellUtil.cloneValue(cell);
            long timestamp = cell.getTimestamp();
            regionPruneInfos.add(new RegionPruneInfo(region, Bytes.toStringBinary(region),
                                                     Bytes.toLong(pruneUpperBoundBytes), timestamp));
          }
        }
      }
    }
  }
  return Collections.unmodifiableList(regionPruneInfos);
}
 
Example #13
Source File: TestDefaultMemStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void internalRun() throws IOException {
  for (long i = 0; i < NUM_TRIES && caughtException.get() == null; i++) {
    MultiVersionConcurrencyControl.WriteEntry w =
        mvcc.begin();

    // Insert the sequence value (i)
    byte[] v = Bytes.toBytes(i);

    KeyValue kv = new KeyValue(row, f, q1, i, v);
    kv.setSequenceId(w.getWriteNumber());
    memstore.add(kv, null);
    mvcc.completeAndWait(w);

    // Assert that we can read back
    KeyValueScanner s = this.memstore.getScanners(mvcc.getReadPoint()).get(0);
    s.seek(kv);

    Cell ret = s.next();
    assertNotNull("Didnt find own write at all", ret);
    assertEquals("Didnt read own writes",
                 kv.getTimestamp(), ret.getTimestamp());
  }
}
 
Example #14
Source File: Result.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Return the Cells for the specific column.  The Cells are sorted in
 * the {@link CellComparator} order.  That implies the first entry in
 * the list is the most recent column.  If the query (Scan or Get) only
 * requested 1 version the list will contain at most 1 entry.  If the column
 * did not exist in the result set (either the column does not exist
 * or the column was not selected in the query) the list will be empty.
 *
 * Also see getColumnLatest which returns just a Cell
 *
 * @param family the family
 * @param qualifier
 * @return a list of Cells for this column or empty list if the column
 * did not exist in the result set
 */
public List<Cell> getColumnCells(byte [] family, byte [] qualifier) {
  List<Cell> result = new ArrayList<>();

  Cell [] kvs = rawCells();

  if (kvs == null || kvs.length == 0) {
    return result;
  }
  int pos = binarySearch(kvs, family, qualifier);
  if (pos == -1) {
    return result; // cant find it
  }

  for (int i = pos; i < kvs.length; i++) {
    if (CellUtil.matchingColumn(kvs[i], family,qualifier)) {
      result.add(kvs[i]);
    } else {
      break;
    }
  }

  return result;
}
 
Example #15
Source File: HTableMultiCluster.java    From HBase.MCC with Apache License 2.0 6 votes vote down vote up
private Put setTimeStampOfUnsetValues(final Put put, long ts)
        throws IOException {
  final Put newPut = new Put(put.getRow());
  for (Entry<byte[], List<Cell>> entity : put.getFamilyCellMap().entrySet()) {
    for (Cell cell : entity.getValue()) {
      // If no timestamp was given then use now.
      // This will protect us from a multicluster sumbission
      if (cell.getTimestamp() == HConstants.LATEST_TIMESTAMP) {
        newPut
                .add(cell.getFamily(), cell.getQualifier(), ts, cell.getValue());
      } else {
        newPut.add(cell);
      }
    }
  }
  return newPut;
}
 
Example #16
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
Map<byte[], String> readBulkLoadedFiles(String backupId) throws IOException {
  Scan scan = BackupSystemTable.createScanForBulkLoadedFiles(backupId);
  try (Table table = connection.getTable(bulkLoadTableName);
      ResultScanner scanner = table.getScanner(scan)) {
    Result res = null;
    Map<byte[], String> map = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    while ((res = scanner.next()) != null) {
      res.advance();
      byte[] row = CellUtil.cloneRow(res.listCells().get(0));
      for (Cell cell : res.listCells()) {
        if (CellUtil.compareQualifiers(cell, BackupSystemTable.PATH_COL, 0,
          BackupSystemTable.PATH_COL.length) == 0) {
          map.put(row, Bytes.toString(CellUtil.cloneValue(cell)));
        }
      }
    }
    return map;
  }
}
 
Example #17
Source File: LocalIndexStoreFileScanner.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param kv
 * @param isSeek pass true for seek, false for reseek.
 * @return 
 * @throws IOException
 */
public boolean seekOrReseek(Cell cell, boolean isSeek) throws IOException{
    Cell keyToSeek = cell;
    KeyValue splitKeyValue = new KeyValue.KeyOnlyKeyValue(reader.getSplitkey());
    if (reader.isTop()) {
        if(this.comparator.compare(cell, splitKeyValue, true) < 0){
            if(!isSeek && realSeekDone()) {
                return true;
            }
            return seekOrReseekToProperKey(isSeek, keyToSeek);
        }
        keyToSeek = getKeyPresentInHFiles(cell);
        return seekOrReseekToProperKey(isSeek, keyToSeek);
    } else {
        if (this.comparator.compare(cell, splitKeyValue, true) >= 0) {
            close();
            return false;
        }
        if(!isSeek && reader.getRegionInfo().getStartKey().length == 0 && reader.getSplitRow().length > reader.getRegionStartKeyInHFile().length) {
            keyToSeek = getKeyPresentInHFiles(cell);
        }
    }
    return seekOrReseekToProperKey(isSeek, keyToSeek);
}
 
Example #18
Source File: HBaseUtils.java    From bigdata-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * print info for Result
 *
 * @param r
 */
public static void printResultInfo(Result r) {
	System.out.print(">>>> cell rowkey= [" + new String(r.getRow()) + "]");
	for (Cell cell : r.rawCells()) {
		System.out.print(">>>> cell rowkey= " + new String(CellUtil.cloneRow(cell)));
		System.out.print(",family= " + new String(CellUtil.cloneFamily(cell)) + ":" + new String(CellUtil.cloneQualifier(cell)));
		System.out.println(", value= [" + new String(CellUtil.cloneValue(cell)) + "]");
	}
}
 
Example #19
Source File: PositionBasedResultTuple.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean getValue(byte[] family, byte[] qualifier,
        ImmutableBytesWritable ptr) {
    Cell kv = getValue(family, qualifier);
    if (kv == null)
        return false;
    ptr.set(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
    return true;
}
 
Example #20
Source File: AggregateRegionObserverTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private Cell newCell(byte[] key, HCol col, String decimal, int number) {
    Object[] values = number == Integer.MIN_VALUE ? //
    new Object[] { new BigDecimal(decimal) } //
            : new Object[] { new BigDecimal(decimal), new LongWritable(number) };
    buf.clear();
    col.measureCodec.encode(values, buf);

    Cell keyValue = new KeyValue(key, 0, key.length, //
            col.family, 0, col.family.length, //
            col.qualifier, 0, col.qualifier.length, //
            HConstants.LATEST_TIMESTAMP, Type.Put, //
            buf.array(), 0, buf.position());

    return keyValue;
}
 
Example #21
Source File: TestQuotaTableUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void verifyTableSnapshotSize(
    Table quotaTable, TableName tn, String snapshotName, long expectedSize) throws IOException {
  Result r = quotaTable.get(QuotaTableUtil.makeGetForSnapshotSize(tn, snapshotName));
  CellScanner cs = r.cellScanner();
  assertTrue(cs.advance());
  Cell c = cs.current();
  assertEquals(expectedSize, QuotaProtos.SpaceQuotaSnapshot.parseFrom(
      UnsafeByteOperations.unsafeWrap(
          c.getValueArray(), c.getValueOffset(), c.getValueLength())).getQuotaUsage());
  assertFalse(cs.advance());
}
 
Example #22
Source File: IndexMemStore.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Move forward on the sub-lists set previously by seek.
 * @param key seek value (should be non-null)
 * @return true if there is at least one KV to read, false otherwise
 */
@Override
public synchronized boolean reseek(Cell key) {
  /*
   * See HBASE-4195 & HBASE-3855 & HBASE-6591 for the background on this implementation. This
   * code is executed concurrently with flush and puts, without locks. Two points must be known
   * when working on this code: 1) It's not possible to use the 'kvTail' and 'snapshot'
   * variables, as they are modified during a flush. 2) The ideal implementation for performance
   * would use the sub skip list implicitly pointed by the iterators 'kvsetIt' and 'snapshotIt'.
   * Unfortunately the Java API does not offer a method to get it. So we remember the last keys
   * we iterated to and restore the reseeked set to at least that point.
   */
  kvsetIt = kvsetAtCreation.tailSet(getHighest(PhoenixKeyValueUtil.maybeCopyCell(key), kvsetItRow)).iterator();
  return seekInSubLists();
}
 
Example #23
Source File: QuotaUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static long calculateResultSize(final Result result) {
  long size = 0;
  for (Cell cell : result.rawCells()) {
    size += cell.getSerializedSize();
  }
  return size;
}
 
Example #24
Source File: TestCoprocessorScanPolicy.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get,
    List<Cell> result) throws IOException {
  TableName tableName = c.getEnvironment().getRegion().getTableDescriptor().getTableName();
  Long ttl = this.ttls.get(tableName);
  if (ttl != null) {
    get.setTimeRange(EnvironmentEdgeManager.currentTime() - ttl, get.getTimeRange().getMax());
  }
  Integer version = this.versions.get(tableName);
  if (version != null) {
    get.readVersions(version);
  }
}
 
Example #25
Source File: StoreScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Seek storefiles in parallel to optimize IO latency as much as possible
 * @param scanners the list {@link KeyValueScanner}s to be read from
 * @param kv the KeyValue on which the operation is being requested
 * @throws IOException
 */
private void parallelSeek(final List<? extends KeyValueScanner>
    scanners, final Cell kv) throws IOException {
  if (scanners.isEmpty()) return;
  int storeFileScannerCount = scanners.size();
  CountDownLatch latch = new CountDownLatch(storeFileScannerCount);
  List<ParallelSeekHandler> handlers = new ArrayList<>(storeFileScannerCount);
  for (KeyValueScanner scanner : scanners) {
    if (scanner instanceof StoreFileScanner) {
      ParallelSeekHandler seekHandler = new ParallelSeekHandler(scanner, kv,
        this.readPt, latch);
      executor.submit(seekHandler);
      handlers.add(seekHandler);
    } else {
      scanner.seek(kv);
      latch.countDown();
    }
  }

  try {
    latch.await();
  } catch (InterruptedException ie) {
    throw (InterruptedIOException)new InterruptedIOException().initCause(ie);
  }

  for (ParallelSeekHandler handler : handlers) {
    if (handler.getErr() != null) {
      throw new IOException(handler.getErr());
    }
  }
}
 
Example #26
Source File: IndexRebuildRegionScanner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private boolean isVerified(Put mutation) throws IOException {
    List<Cell> cellList = mutation.get(indexMaintainer.getEmptyKeyValueFamily().copyBytesIfNecessary(),
            indexMaintainer.getEmptyKeyValueQualifier());
    Cell cell = (cellList != null && !cellList.isEmpty()) ? cellList.get(0) : null;
    if (cell == null) {
        return false;
    }
    if (Bytes.compareTo(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength(),
            VERIFIED_BYTES, 0, VERIFIED_BYTES.length) == 0) {
        return true;
    }
    return false;
}
 
Example #27
Source File: PhoenixDatabaseMetaData.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple next() throws SQLException {
    Tuple tuple = super.next();

    while (tuple != null
            && getColumn(tuple, columnFamilyIndex) == null && getColumn(tuple, columnNameIndex) == null) {
        // new table, check if it is multitenant
        inMultiTenantTable = getColumn(tuple, multiTenantIndex) == Boolean.TRUE;
        tenantColumnSkipped = false;
        // skip row representing table
        tuple = super.next();
    }

    if (tuple != null && inMultiTenantTable && !tenantColumnSkipped) {
        Object value = getColumn(tuple, keySeqIndex);
        if (value != null && ((Number)value).longValue() == 1L) {
            tenantColumnSkipped = true;
            // skip tenant id primary key column
            return next();
        }
    }

    if (tuple != null && tenantColumnSkipped) {
        ResultTuple resultTuple = (ResultTuple)tuple;
        List<Cell> cells = resultTuple.getResult().listCells();
        KeyValue kv = new KeyValue(resultTuple.getResult().getRow(), TABLE_FAMILY_BYTES,
                TENANT_POS_SHIFT_BYTES, PDataType.TRUE_BYTES);
        List<Cell> newCells = Lists.newArrayListWithCapacity(cells.size() + 1);
        newCells.addAll(cells);
        newCells.add(kv);
        Collections.sort(newCells, KeyValue.COMPARATOR);
        resultTuple.setResult(Result.create(newCells));
    }

    return tuple;
}
 
Example #28
Source File: TestMultiRowRangeFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiRowRangeWithFilterListAndOperator() throws IOException {
  tableName = TableName.valueOf(name.getMethodName());
  Table ht = TEST_UTIL.createTable(tableName, family, Integer.MAX_VALUE);
  generateRows(numRows, ht, family, qf, value);

  Scan scan = new Scan();
  scan.readAllVersions();

  List<RowRange> ranges1 = new ArrayList<>();
  ranges1.add(new RowRange(Bytes.toBytes(10), true, Bytes.toBytes(20), false));
  ranges1.add(new RowRange(Bytes.toBytes(30), true, Bytes.toBytes(40), false));
  ranges1.add(new RowRange(Bytes.toBytes(60), true, Bytes.toBytes(70), false));

  MultiRowRangeFilter filter1 = new MultiRowRangeFilter(ranges1);

  List<RowRange> ranges2 = new ArrayList<>();
  ranges2.add(new RowRange(Bytes.toBytes(20), true, Bytes.toBytes(40), false));
  ranges2.add(new RowRange(Bytes.toBytes(80), true, Bytes.toBytes(90), false));

  MultiRowRangeFilter filter2 = new MultiRowRangeFilter(ranges2);

  FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filterList.addFilter(filter1);
  filterList.addFilter(filter2);
  scan.setFilter(filterList);
  int resultsSize = getResultsSize(ht, scan);
  LOG.info("found " + resultsSize + " results");
  List<Cell> results1 = getScanResult(Bytes.toBytes(30), Bytes.toBytes(40), ht);

  assertEquals(results1.size(), resultsSize);

  ht.close();
}
 
Example #29
Source File: TestKeyValueHeap.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testPriorityId() throws IOException {
  Cell kv113A = new KeyValue(row1, fam1, col3, Bytes.toBytes("aaa"));
  Cell kv113B = new KeyValue(row1, fam1, col3, Bytes.toBytes("bbb"));
  TestScanner scan1 = new TestScanner(Arrays.asList(kv111, kv112, kv113A), 1);
  TestScanner scan2 = new TestScanner(Arrays.asList(kv113B), 2);
  List<Cell> expected = Arrays.asList(kv111, kv112, kv113B, kv113A);
  assertCells(expected, Arrays.asList(scan1, scan2));

  scan1 = new TestScanner(Arrays.asList(kv111, kv112, kv113A), 2);
  scan2 = new TestScanner(Arrays.asList(kv113B), 1);
  expected = Arrays.asList(kv111, kv112, kv113A, kv113B);
  assertCells(expected, Arrays.asList(scan1, scan2));
}
 
Example #30
Source File: HbaseEndpoint.java    From hbase-connect-kafka with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param context
 * @return
 */
@Override
public boolean replicate(ReplicateContext context) {
    final List<Entry> entries = context.getEntries();

    final Map<String, List<Entry>> entriesByTable = entries.stream()
                      .filter(entry -> topicNameFilter.test(entry.getKey().getTablename().getNameAsString()))
                      .collect(groupingBy(entry -> entry.getKey().getTablename().getNameAsString()));

    // persist the data to kafka in parallel.
    entriesByTable.entrySet().stream().forEach(entry -> {
        final String tableName = entry.getKey();
        final List<Entry> tableEntries = entry.getValue();

        tableEntries.forEach(tblEntry -> {
           List<Cell> cells = tblEntry.getEdit().getCells();

            // group the data by the rowkey.
         Map<byte[], List<Cell>> columnsByRow = cells.stream()
               .collect(groupingBy(CellUtil::cloneRow));

           // build the list of rows.
         columnsByRow.entrySet().stream().forEach(rowcols -> {
             final byte[] rowkey = rowcols.getKey();
               final List<Cell> columns = rowcols.getValue();
             final HRow row = TO_HROW.apply(rowkey, columns);
             producer.send(tableName, row);
          });
        });
    });
    return true;
}