Java Code Examples for org.apache.hadoop.hbase.client.Put.addColumn()

The following are Jave code examples for showing how to use addColumn() of the org.apache.hadoop.hbase.client.Put class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ditb   File: MDIndex.java   Source Code and License Vote up 6 votes
/**
 * @param dropIfExists
 */
public void createTable(boolean dropIfExists) throws IOException {
  if (admin.tableExists(secondaryTableName)) {
    if (dropIfExists) {
      admin.disableTable(bucketTableName);
      admin.deleteTable(bucketTableName);
      admin.disableTable(secondaryTableName);
      admin.deleteTable(secondaryTableName);
    } else {
      secondaryTable = conn.getTable(secondaryTableName);
      bucketTable = conn.getTable(bucketTableName);
      return;
    }
  }
  // secondary table
  HTableDescriptor secondaryDesc = new HTableDescriptor(secondaryTableName);
  secondaryDesc
      .addFamily(IndexTableRelation.getDefaultColumnDescriptor(MDHBaseAdmin.SECONDARY_FAMILY));
  admin.createTable(secondaryDesc);
  secondaryTable = conn.getTable(secondaryTableName);
  // bucket table
  HTableDescriptor bucketDesc = new HTableDescriptor(bucketTableName);
  bucketDesc.addFamily(IndexTableRelation.getDefaultColumnDescriptor(MDHBaseAdmin.BUCKET_FAMILY));
  admin.createTable(bucketDesc);
  bucketTable = conn.getTable(bucketTableName);
  // init when init
  int[] starts = new int[dimensions];
  Arrays.fill(starts, 0);
  Put put = new Put(MDUtils.bitwiseZip(starts, dimensions));
  put.addColumn(MDHBaseAdmin.BUCKET_FAMILY, MDHBaseAdmin.BUCKET_PREFIX_LEN_QUALIFIER,
      Bytes.toBytes(dimensions));
  put.addColumn(MDHBaseAdmin.BUCKET_FAMILY, MDHBaseAdmin.BUCKET_SIZE_QUALIFIER,
      Bytes.toBytes(0L));
  bucketTable.put(put);
}
 
Example 2
Project: ditb   File: IndexPutParser.java   Source Code and License Vote up 6 votes
@Override protected Map<TableName, Put> parsePut(Put put, boolean serverSide) {
  Map<TableName, Put> map = new HashMap<>();
  byte[] row = put.getRow();
  for (Map.Entry<byte[], List<Cell>> entry : put.getFamilyCellMap().entrySet()) {
    byte[] family = entry.getKey();
    for (Cell cell : entry.getValue()) {
      byte[] q = CellUtil.cloneQualifier(cell);
      if (tableRelation.isIndexColumn(family, q)) {
        TableName indexTableName = tableRelation.getIndexTableName(family, q);
        Put newPut = new Put(getIndexRow(row, CellUtil.cloneValue(cell)));
        if (serverSide) newPut
            .addColumn(IndexType.SEDONDARY_FAMILY_BYTES, (byte[]) null, cell.getTimestamp(),
                null);
        else newPut.addColumn(IndexType.SEDONDARY_FAMILY_BYTES, null, null);
        map.put(indexTableName, newPut);
      }
    }
  }
  tableRelation.getIndexFamilyMap();
  return map;
}
 
Example 3
Project: SkyEye   File: HbaseStore.java   Source Code and License Vote up 6 votes
/**
 * 索引表time_consume, 保存每个trace耗时
 * rowkey: serviceId + cs时间
 * columnFamily: trace
 * qualifier: traceId ...
 * value: 整个调用链条耗时
 * @param span
 * @param annotationMap
 * @return
 */
@Override
public Put storeTrace(Span span, Map<String, Annotation> annotationMap) {
    if (null == span.getParentId() && annotationMap.containsKey(AnnotationType.CS.symbol())) {
        // 是root span, 并且是client端
        Annotation csAnnotation = annotationMap.get(AnnotationType.CS.symbol());
        Annotation crAnnotation = annotationMap.get(AnnotationType.CR.symbol());

        long consumeTime = crAnnotation.getTimestamp() - csAnnotation.getTimestamp();
        String rowKey = span.getServiceId() + Constants.UNDER_LINE + csAnnotation.getTimestamp();
        Put put = new Put(Bytes.toBytes(rowKey));
        put.addColumn(Bytes.toBytes(Constants.TABLE_TIME_CONSUME_COLUMN_FAMILY), Bytes.toBytes(span.getTraceId()),
                Bytes.toBytes(consumeTime));
        return put;
    }
    return null;
}
 
Example 4
Project: SkyEye   File: HbaseStore.java   Source Code and License Vote up 6 votes
/**
 * 索引表annotation, 保存自定义的异常信息
 * rowkey: serviceId + ExceptionType + cs/sr时间
 * columnFamily: trace
 * qualifier: traceId ...
 * value: binaryAnnotation的value
 * @param span
 * @param annotationMap
 * @return
 */
@Override
public List<Put> storeAnnotation(Span span, Map<String, Annotation> annotationMap) {
    List<BinaryAnnotation> annotations = span.getBinaryAnnotations();
    if (null != annotations && annotations.size() != 0) {
        List<Put> puts = new ArrayList<Put>();
        // 如果有自定义异常
        for (BinaryAnnotation annotation : annotations) {
            String rowKey = span.getServiceId() + Constants.UNDER_LINE + annotation.getType()
                    + Constants.UNDER_LINE + this.getBinaryAnnotationTimestamp(annotationMap);
            Put put = new Put(Bytes.toBytes(rowKey));
            put.addColumn(Bytes.toBytes(Constants.TABLE_ANNOTATION_COLUMN_FAMILY), Bytes.toBytes(span.getTraceId()),
                    Bytes.toBytes(annotation.getValue() == null ? annotation.getType() : annotation.getValue()));
            puts.add(put);
        }
        return puts;
    }
    return null;
}
 
Example 5
Project: ditb   File: TestHRegion.java   Source Code and License Vote up 6 votes
/**
 * Test that I can use the max flushed sequence id after the close.
 * @throws IOException
 */
@Test (timeout = 100000)
public void testSequenceId() throws IOException {
  HRegion region = initHRegion(tableName, name.getMethodName(), CONF, COLUMN_FAMILY_BYTES);
  assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());
  // Weird. This returns 0 if no store files or no edits. Afraid to change it.
  assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));
  region.close();
  assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());
  assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));
  // Open region again.
  region = initHRegion(tableName, name.getMethodName(), CONF, COLUMN_FAMILY_BYTES);
  byte [] value = Bytes.toBytes(name.getMethodName());
  // Make a random put against our cf.
  Put put = new Put(value);
  put.addColumn(COLUMN_FAMILY_BYTES, null, value);
  region.put(put);
  // No flush yet so init numbers should still be in place.
  assertEquals(HConstants.NO_SEQNUM, region.getMaxFlushedSeqId());
  assertEquals(0, (long)region.getMaxStoreSeqId().get(COLUMN_FAMILY_BYTES));
  region.flush(true);
  long max = region.getMaxFlushedSeqId();
  region.close();
  assertEquals(max, region.getMaxFlushedSeqId());
}
 
Example 6
Project: ditb   File: TestRegionObserverInterface.java   Source Code and License Vote up 6 votes
@Test(timeout = 300000)
public void testHBASE14489() throws IOException {
  TableName tableName = TableName.valueOf("testHBASE14489");
  HTable table = util.createTable(tableName, new byte[][] { A });
  Put put = new Put(ROW);
  put.addColumn(A, A, A);
  table.put(put);

  Scan s = new Scan();
  s.setFilter(new FilterAllFilter());
  ResultScanner scanner = table.getScanner(s);
  try {
    for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
    }
  } finally {
    scanner.close();
  }
  verifyMethodResult(SimpleRegionObserver.class, new String[] { "wasScannerFilterRowCalled" },
    tableName, new Boolean[] { true });
  util.deleteTable(tableName);
  table.close();
}
 
Example 7
Project: ditb   File: TestHRegion.java   Source Code and License Vote up 6 votes
@Test
public void testFlushedFileWithNoTags() throws Exception {
  String method = "testFlushedFileWithNoTags";
  HTableDescriptor htd = new HTableDescriptor(tableName);
  htd.addFamily(new HColumnDescriptor(fam1));
  region = initHRegion(Bytes.toBytes(method), method, TEST_UTIL.getConfiguration(), fam1);
  Put put = new Put(Bytes.toBytes("a-b-0-0"));
  put.addColumn(fam1, qual1, Bytes.toBytes("c1-value"));
  region.put(put);
  region.flush(true);
  Store store = region.getStore(fam1);
  Collection<StoreFile> storefiles = store.getStorefiles();
  for (StoreFile sf : storefiles) {
    assertFalse("Tags should not be present "
        ,sf.getReader().getHFileReader().getFileContext().isIncludesTags());
  }
}
 
Example 8
Project: stroom-stats   File: HBaseUniqueIdReverseMapTable.java   Source Code and License Vote up 5 votes
@Override
void tableSpecificCreationProcessing() {
    LOGGER.info("Creating max ID row in Unique ID table");

    final Put put = new Put(MAXID_ROW);
    put.addColumn(NAME_FAMILY, MAXID_COL_QUALIFIER, Bytes.toBytes(MAXID_INITIAL_VALUE));

    doPut(put);
}
 
Example 9
Project: ditb   File: TestSeekBeforeWithReverseScan.java   Source Code and License Vote up 5 votes
@Test
public void testReverseScanWithoutPadding() throws Exception {
  byte[] row1 = Bytes.toBytes("a");
  byte[] row2 = Bytes.toBytes("ab");
  byte[] row3 = Bytes.toBytes("b");

  Put put1 = new Put(row1);
  put1.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put2 = new Put(row2);
  put2.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);
  Put put3 = new Put(row3);
  put3.addColumn(cfName, cqName, HConstants.EMPTY_BYTE_ARRAY);

  region.put(put1);
  region.put(put2);
  region.put(put3);
  region.flush(true);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  scan.setReversed(true);
  scan.setFilter(new FirstKeyOnlyFilter());
  scan.addFamily(cfName);
  RegionScanner scanner = region.getScanner(scan);
  List<Cell> res = new ArrayList<Cell>();
  int count = 1;
  while (scanner.next(res)) {
    count++;
  }
  assertEquals(Bytes.toString(res.get(0).getRowArray(), res.get(0).getRowOffset(), res.get(0)
      .getRowLength()), "b");
  assertEquals(Bytes.toString(res.get(1).getRowArray(), res.get(1).getRowOffset(), res.get(1)
      .getRowLength()), "ab");
  assertEquals(Bytes.toString(res.get(2).getRowArray(), res.get(2).getRowOffset(), res.get(2)
      .getRowLength()), "a");
  assertEquals(3, count);
}
 
Example 10
Project: ditb   File: UniWorkload.java   Source Code and License Vote up 5 votes
@Override public Put getPut() {
  Put put = new Put(getSaltRowkey());
  put.addColumn(FAMILY_NAME, Bytes.toBytes("a"), Bytes.toBytes(a));
  put.addColumn(FAMILY_NAME, Bytes.toBytes("b"), Bytes.toBytes(b));
  put.addColumn(FAMILY_NAME, Bytes.toBytes("c"), Bytes.toBytes(c));
  for (int i = DATA_COLUMN_OFFSET; i < nbTotalColumns; i++) {
    put.addColumn(FAMILY_NAME, Bytes.toBytes(i), Bytes.toBytes(columnValues[i]));
  }
  return put;
}
 
Example 11
Project: ditb   File: LMDTester.java   Source Code and License Vote up 5 votes
private void doInsert(int totalSize, int flushSize, boolean flushTable) throws IOException {
  Table table = conn.getTable(tableName);
  List<Put> putList = new ArrayList<>();
  for (int i = 0; i < totalSize; i++) {
    Put put = new Put(Bytes.toBytes(i));
    for (int j = 0; j < indexColumnNames.length; j++) {
      put.addColumn(familyName, Bytes.toBytes(indexColumnNames[j]),
          Bytes.toBytes(i % BUCKET_SIZE));
    }
    for (int j = 0; j < dataColumnNumber; j++) {
      put.addColumn(familyName, Bytes.toBytes("info"), Bytes.toBytes(i * 10));
    }
    putList.add(put);
    if (putList.size() >= INSERT_LIST_SIZE) {
      table.put(putList);
      putList = new ArrayList<>(INSERT_LIST_SIZE);
    }
    if (i > flushSize) {
      hBaseAdmin.flush(tableName);
      flushSize = Integer.MAX_VALUE;
      System.out.println("flush table after " + i);
      try {
        Thread.sleep(3 * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
  table.close();
  if (flushTable) hBaseAdmin.flush(tableName);

  System.out.println("insert " + totalSize + " records into table, flush table=" + flushTable);
}
 
Example 12
Project: ignite-hbase   File: HBaseCacheStore.java   Source Code and License Vote up 5 votes
private Put createPut(Entry<? extends K, ? extends V> entry) {
  try {
    Put put = new Put(keySerializer.serialize(entry.getKey()));
    put.addColumn(family(), QUALIFIER, valueSerializer.serialize(entry.getValue()));
    return put;
  } catch (SerializationException e) {
    throw new CacheWriterException("Failed to create put", e);
  }
}
 
Example 13
Project: ditb   File: PerformanceEvaluation.java   Source Code and License Vote up 5 votes
@Override
void testRow(final int i) throws IOException {
  byte [] bytes = format(i);
  // Put a known value so when we go to check it, it is there.
  Put put = new Put(bytes);
  put.addColumn(FAMILY_NAME, getQualifier(), bytes);
  this.table.put(put);
  Delete delete = new Delete(put.getRow());
  delete.addColumn(FAMILY_NAME, getQualifier());
  this.table.checkAndDelete(bytes, FAMILY_NAME, getQualifier(), CompareOp.EQUAL, bytes, delete);
}
 
Example 14
Project: dremio-oss   File: TestTableGenerator.java   Source Code and License Vote up 5 votes
public static void generateHBaseDatasetCompositeKeyInt(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
  if (admin.tableExists(tableName)) {
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
  }

  HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILY_F));

  if (numberRegions > 1) {
    admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
  } else {
    admin.createTable(desc);
  }

  BufferedMutator table = conn.getBufferedMutator(tableName);

  int startVal = 0;
  int stopVal = 1000;
  int interval = 47;
  long counter = 0;
  for (int i = startVal; i < stopVal; i += interval, counter ++) {
    byte[] rowKey = ByteBuffer.allocate(12).putInt(i).array();

    for(int j = 0; j < 8; ++j) {
      rowKey[4 + j] = (byte)(counter >> (56 - (j * 8)));
    }

    Put p = new Put(rowKey);
    p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
    table.mutate(p);
  }

  table.close();
}
 
Example 15
Project: dremio-oss   File: TestTableGenerator.java   Source Code and License Vote up 5 votes
public static void generateHBaseDatasetDoubleOB(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
  if (admin.tableExists(tableName)) {
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
  }

  HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILY_F));

  if (numberRegions > 1) {
    admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
  } else {
    admin.createTable(desc);
  }

  BufferedMutator table = conn.getBufferedMutator(tableName);

  for (double i = 0.5; i <= 100.00; i += 0.75) {
    byte[] bytes = new byte[9];
    PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
    OrderedBytes.encodeFloat64(br, i, Order.ASCENDING);
    Put p = new Put(bytes);
    p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
    table.mutate(p);
  }

  table.close();

  admin.flush(tableName);
}
 
Example 16
Project: ditb   File: MDBucket.java   Source Code and License Vote up 5 votes
public void insert(byte[] row, List<MDPoint> points) throws IOException {
  Put put = new Put(row);
  for (MDPoint p : points) {
    put.addColumn(MDHBaseAdmin.SECONDARY_FAMILY, p.toQualifier(), p.toValue());
  }
  secondaryTable.put(put);
  mdIndex.notifyInsertion(row, points.size());
}
 
Example 17
Project: ditb   File: TestCoprocessorTableEndpoint.java   Source Code and License Vote up 5 votes
private static final void createTable(HTableDescriptor desc) throws Exception {
  Admin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(desc, new byte[][]{ROWS[rowSeperator1], ROWS[rowSeperator2]});
  TEST_UTIL.waitUntilAllRegionsAssigned(desc.getTableName());
  Table table = TEST_UTIL.getConnection().getTable(desc.getTableName());
  try {
    for (int i = 0; i < ROWSIZE; i++) {
      Put put = new Put(ROWS[i]);
      put.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(i));
      table.put(put);
    }
  } finally {
    table.close();    
  }
}
 
Example 18
Project: stroom-stats   File: HBaseUniqueIdForwardMapTable.java   Source Code and License Vote up 4 votes
private boolean checkAndPutKeyValue(final byte[] nameKey, final byte[] newId) {
    if (LOGGER.isTraceEnabled()) {
        final String rowKeyStr = Bytes.toString(nameKey);

        final String valueStr = ByteArrayUtils.byteArrayToHex(newId);

        LOGGER.trace("checkAndPutKeyValue - Key: [" + rowKeyStr + "], Value: [" + valueStr + "]");
    }

    final Put put = new Put(nameKey);
    put.addColumn(ID_FAMILY, ID_COL_QUALIFIER, newId);

    boolean result;

    result = doCheckAndPut(nameKey, ID_FAMILY, ID_COL_QUALIFIER, null, put);

    return result;
}
 
Example 19
Project: dremio-oss   File: TestTableGenerator.java   Source Code and License Vote up 4 votes
public static void generateHBaseDataset2(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
  if (admin.tableExists(tableName)) {
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
  }

  HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor("f"));

  if (numberRegions > 1) {
    admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
  } else {
    admin.createTable(desc);
  }

  BufferedMutator table = conn.getBufferedMutator(tableName);

  int rowCount = 0;
  byte[] bytes = null;
  final int numColumns = 5;
  Random random = new Random();
  int iteration = 0;
  while (rowCount < 1000) {
    char rowKeyChar = 'a';
    for (int i = 0; i < numberRegions; i++) {
      Put p = new Put((""+rowKeyChar+iteration).getBytes());
      for (int j = 1; j <= numColumns; j++) {
        bytes = new byte[5000]; random.nextBytes(bytes);
        p.addColumn("f".getBytes(), ("c"+j).getBytes(), bytes);
      }
      table.mutate(p);

      ++rowKeyChar;
      ++rowCount;
    }
    ++iteration;
  }

  table.close();

  admin.flush(tableName);
}
 
Example 20
Project: dremio-oss   File: TestTableGenerator.java   Source Code and License Vote up 4 votes
public static void generateHBaseDatasetCompositeKeyTime(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
  if (admin.tableExists(tableName)) {
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
  }

  HTableDescriptor desc = new HTableDescriptor(tableName);
  desc.addFamily(new HColumnDescriptor(FAMILY_F));

  if (numberRegions > 1) {
    admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions-1));
  } else {
    admin.createTable(desc);
  }

  BufferedMutator table = conn.getBufferedMutator(tableName);

  long startTime  = 0;
  long MILLISECONDS_IN_A_SEC  = (long)1000;
  long MILLISECONDS_IN_A_DAY = MILLISECONDS_IN_A_SEC * 60 * 60 * 24;
  long endTime    = startTime + MILLISECONDS_IN_A_DAY;
  long smallInterval   = 25;
  long largeInterval   = MILLISECONDS_IN_A_SEC * 42;
  long interval        = smallInterval;

  for (long ts = startTime, counter = 0; ts < endTime; ts += interval, counter ++) {
    byte[] rowKey = ByteBuffer.allocate(16) .putLong(ts).array();

    for(int i = 0; i < 8; ++i) {
      rowKey[8 + i] = (byte)(counter >> (56 - (i * 8)));
    }

    Put p = new Put(rowKey);
    p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
    table.mutate(p);

    if (interval == smallInterval) {
      interval = largeInterval;
    } else {
      interval = smallInterval;
    }
  }

  table.close();
}