示例#1
0
  public static Entry<Key, Value> checkColumn(
      Environment env, IteratorSetting iterConf, Bytes row, Column col) {
    Span span = Span.exact(row, col);

    Scanner scanner;
    try {
      // TODO reuse or share scanner
      scanner = env.getConnector().createScanner(env.getTable(), env.getAuthorizations());
    } catch (TableNotFoundException e) {
      // TODO proper exception handling
      throw new RuntimeException(e);
    }
    scanner.setRange(SpanUtil.toRange(span));
    scanner.addScanIterator(iterConf);

    Iterator<Entry<Key, Value>> iter = scanner.iterator();
    if (iter.hasNext()) {
      Entry<Key, Value> entry = iter.next();

      Key k = entry.getKey();
      Bytes r = Bytes.of(k.getRowData().toArray());
      Bytes cf = Bytes.of(k.getColumnFamilyData().toArray());
      Bytes cq = Bytes.of(k.getColumnQualifierData().toArray());
      Bytes cv = Bytes.of(k.getColumnVisibilityData().toArray());

      if (r.equals(row)
          && cf.equals(col.getFamily())
          && cq.equals(col.getQualifier())
          && cv.equals(col.getVisibility())) {
        return entry;
      } else {
        throw new RuntimeException("unexpected key " + k + " " + row + " " + col);
      }
    }

    return null;
  }
示例#2
0
 public static void writeColumn(Column col, DataOutputStream out) throws IOException {
   ByteUtil.write(out, col.getFamily());
   ByteUtil.write(out, col.getQualifier());
   ByteUtil.write(out, col.getVisibility());
 }