Java Code Examples for org.apache.hadoop.hbase.CellUtil#createCell()

The following examples show how to use org.apache.hadoop.hbase.CellUtil#createCell() . 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: ResponseTimeMapperTest.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeMapperTest() throws Exception {

    Buffer buffer = new AutomaticBuffer();
    HistogramSlot histogramSlot = ServiceType.STAND_ALONE.getHistogramSchema().findHistogramSlot(1000, false);
    short histogramSlotTime = histogramSlot.getSlotTime();
    buffer.putShort(histogramSlotTime);
    buffer.putBytes(Bytes.toBytes("agent"));
    byte[] bufferArray = buffer.getBuffer();
    byte[] valueArray = Bytes.toBytes(1L);

    Cell mockCell = CellUtil.createCell(HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, bufferArray, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum.getCode(), valueArray);

    ResponseTimeMapper responseTimeMapper = new ResponseTimeMapper();
    ResponseTime responseTime = new ResponseTime("applicationName", ServiceType.STAND_ALONE, System.currentTimeMillis());
    responseTimeMapper.recordColumn(responseTime, mockCell);

    Histogram agentHistogram = responseTime.findHistogram("agent");
    long fastCount = agentHistogram.getFastCount();
    Assert.assertEquals(fastCount, 1);
    long normal = agentHistogram.getNormalCount();
    Assert.assertEquals(normal, 0);
    long slow = agentHistogram.getSlowCount();
    Assert.assertEquals(slow, 0);

}
 
Example 2
Source File: TestAppSummaryService.java    From hraven with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateQueueListValue() throws IOException {
  JobDetails jd = new JobDetails(null);
  jd.setQueue("queue1");
  byte[] qb = Bytes.toBytes("queue2!queue3!");
  Cell existingQueuesCell = CellUtil.createCell(Bytes.toBytes("rowkey"),
      Constants.INFO_FAM_BYTES, Constants.HRAVEN_QUEUE_BYTES,
      HConstants.LATEST_TIMESTAMP, KeyValue.Type.Put.getCode(), qb);
  AppSummaryService appSummaryService =
      new AppSummaryService(hbaseConnection);

  String qlist = appSummaryService.createQueueListValue(jd,
      Bytes.toString(CellUtil.cloneValue(existingQueuesCell)));
  assertNotNull(qlist);
  String expQlist = "queue2!queue3!queue1!";
  assertEquals(expQlist, qlist);

  jd.setQueue("queue3");
  qlist = appSummaryService.createQueueListValue(jd,
      Bytes.toString(CellUtil.cloneValue(existingQueuesCell)));
  assertNotNull(qlist);
  expQlist = "queue2!queue3!";
  assertEquals(expQlist, qlist);
}
 
Example 3
Source File: HBaseCellGenerator.java    From geowave with Apache License 2.0 6 votes vote down vote up
public List<Cell> constructKeyValuePairs(final byte[] adapterId, final T entry) {

    final List<Cell> keyValuePairs = new ArrayList<>();
    final GeoWaveRow[] rows =
        BaseDataStoreUtils.getGeoWaveRows(entry, adapter, index, visibilityWriter);

    if ((rows != null) && (rows.length > 0)) {
      for (final GeoWaveRow row : rows) {
        for (final GeoWaveValue value : row.getFieldValues()) {
          final Cell cell =
              CellUtil.createCell(
                  GeoWaveKey.getCompositeId(row),
                  adapterId,
                  row.getDataId(),
                  System.currentTimeMillis(),
                  KeyValue.Type.Put.getCode(),
                  value.getValue());

          keyValuePairs.add(cell);
        }
      }
    }

    return keyValuePairs;
  }
 
Example 4
Source File: TestJobHistoryRawService.java    From hraven with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetApproxSubmitTime()
    throws IOException, MissingColumnInResultException {
  JobHistoryRawService rawService = new JobHistoryRawService(hbaseConnection);
  Cell[] cells = new Cell[1];
  long modts = 1396550668000L;
  cells[0] = CellUtil.createCell(Bytes.toBytes("someRowKey"),
      Constants.INFO_FAM_BYTES, Constants.JOBHISTORY_LAST_MODIFIED_COL_BYTES,
      HConstants.LATEST_TIMESTAMP, KeyValue.Type.Put.getCode(),
      Bytes.toBytes(modts));
  Result result = Result.create(cells);
  long st = rawService.getApproxSubmitTime(result);
  long expts = modts - Constants.AVERGAE_JOB_DURATION;
  assertEquals(expts, st);
}
 
Example 5
Source File: HBaseMergingFilter.java    From geowave with Apache License 2.0 5 votes vote down vote up
/** Handle the entire row at one time */
@Override
public void filterRowCells(final List<Cell> rowCells) throws IOException {
  if (!rowCells.isEmpty()) {
    if (rowCells.size() > 1) {
      try {
        final Cell firstCell = rowCells.get(0);
        final byte[] singleRow = CellUtil.cloneRow(firstCell);
        final byte[] singleFam = CellUtil.cloneFamily(firstCell);
        final byte[] singleQual = CellUtil.cloneQualifier(firstCell);

        Mergeable mergedValue = null;
        for (final Cell cell : rowCells) {
          final byte[] byteValue = CellUtil.cloneValue(cell);
          final Mergeable value = (Mergeable) URLClassloaderUtils.fromBinary(byteValue);

          if (mergedValue != null) {
            mergedValue.merge(value);
          } else {
            mergedValue = value;
          }
        }

        final Cell singleCell =
            CellUtil.createCell(
                singleRow,
                singleFam,
                singleQual,
                System.currentTimeMillis(),
                KeyValue.Type.Put.getCode(),
                URLClassloaderUtils.toBinary(mergedValue));

        rowCells.clear();
        rowCells.add(singleCell);
      } catch (final Exception e) {
        throw new IOException("Exception in filter", e);
      }
    }
  }
}
 
Example 6
Source File: FixedCardinalitySkippingFilter.java    From geowave with Apache License 2.0 5 votes vote down vote up
private ReturnCode checkNextRow(final Cell cell) {
  final byte[] row = CellUtil.cloneRow(cell);

  System.arraycopy(row, 0, rowCompare, 0, rowCompare.length);

  final int cmp = Bytes.compareTo(rowCompare, nextRow);

  if (cmp < 0) {
    nextCell = CellUtil.createCell(nextRow);
    return ReturnCode.SEEK_NEXT_USING_HINT;
  } else {
    nextCell = null;
    return ReturnCode.INCLUDE;
  }
}
 
Example 7
Source File: AndExpressionTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Cell createCell(String name, Boolean value) {
    byte[] valueBytes = value == null ? null : value ? PBoolean.TRUE_BYTES : PBoolean.FALSE_BYTES;
    return CellUtil.createCell(
        Bytes.toBytes("row"),
        QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES,
        Bytes.toBytes(name),
        1,
        KeyValue.Type.Put.getCode(),
        valueBytes);
}
 
Example 8
Source File: OrExpressionTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Cell createCell(String name, Boolean value) {
    byte[] valueBytes = value == null ? null : value ? PBoolean.TRUE_BYTES : PBoolean.FALSE_BYTES;
    return CellUtil.createCell(
            Bytes.toBytes("row"),
            QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES,
            Bytes.toBytes(name),
            1,
            KeyValue.Type.Put.getCode(),
            valueBytes);
}
 
Example 9
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private List <Mutation> getValidActualMutations(TestType testType,
        List<Mutation> actualMutations) {
    List <Mutation> newActualMutations = new ArrayList<>();
    if(testType.equals(TestType.VALID_EXACT_MATCH)) {
        return actualMutations;
    }
    if (testType.equals(TestType.VALID_MIX_MUTATIONS)) {
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
        newActualMutations.add(getDeleteMutation(actualMutations.get(0), new Long(1)));
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
    }
    if (testType.equals(TestType.VALID_NEW_UNVERIFIED_MUTATIONS)) {
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), new Long(1)));
    }
    newActualMutations.addAll(actualMutations);
    if(testType.equals(TestType.VALID_MORE_MUTATIONS)) {
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), null));
        newActualMutations.add(getDeleteMutation(actualMutations.get(0), null));
        newActualMutations.add(getDeleteMutation(actualMutations.get(0), new Long(1)));
        newActualMutations.add(getUnverifiedPutMutation(actualMutations.get(0), new Long(1)));
    }
    if(testType.equals(TestType.VALID_EXTRA_CELL)) {
        for (Mutation m : newActualMutations) {
            if (m instanceof Put) {
                List<Cell> origList = m.getFamilyCellMap().firstEntry().getValue();
                Cell newCell =
                        CellUtil.createCell(m.getRow(), CellUtil.cloneFamily(origList.get(0)),
                                Bytes.toBytes("EXTRACOL"), m.getTimestamp(), KeyValue.Type.Put.getCode(),
                                Bytes.toBytes("asdfg"));
                byte[] fam = CellUtil.cloneFamily(origList.get(0));
                m.getFamilyCellMap().get(fam).add(newCell);
                break;
            }
        }
    }
    return newActualMutations;
}
 
Example 10
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Cell getVerifiedEmptyCell(Cell c) {
    return CellUtil.createCell(CellUtil.cloneRow(c), CellUtil.cloneFamily(c),
            indexMaintainer.getEmptyKeyValueQualifier(),
            EnvironmentEdgeManager.currentTimeMillis(),
            KeyValue.Type.Put.getCode(), VERIFIED_BYTES);
}
 
Example 11
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Cell getCellWithPut(Cell c) {
    return CellUtil.createCell(CellUtil.cloneRow(c),
            CellUtil.cloneFamily(c), Bytes.toBytes(INCLUDED_COLUMN),
            c.getTimestamp(), KeyValue.Type.Put.getCode(),
            Bytes.toBytes("zxcv"));
}
 
Example 12
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Cell getEmptyCell(Mutation orig, List<Cell> origList, Long ts, KeyValue.Type type,
        boolean verified) {
    return CellUtil.createCell(orig.getRow(), CellUtil.cloneFamily(origList.get(0)),
            indexMaintainer.getEmptyKeyValueQualifier(),
            ts, type.getCode(), verified ? VERIFIED_BYTES : UNVERIFIED_BYTES);
}
 
Example 13
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private Cell getNewPutCell(Mutation orig, List<Cell> origList, Long ts, KeyValue.Type type) {
    return CellUtil.createCell(orig.getRow(),
            CellUtil.cloneFamily(origList.get(0)), Bytes.toBytes(INCLUDED_COLUMN),
            ts, type.getCode(), Bytes.toBytes("asdfg"));
}
 
Example 14
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void infiltrateCell(Cell c, List<Cell> newCellList, TestType e) {
    Cell newCell;
    Cell emptyCell;
    switch(e) {
    case INVALID_COLUMN:
        newCell =
                CellUtil.createCell(CellUtil.cloneRow(c), CellUtil.cloneFamily(c),
                        Bytes.toBytes(UNEXPECTED_COLUMN),
                        EnvironmentEdgeManager.currentTimeMillis(),
                        KeyValue.Type.Put.getCode(), Bytes.toBytes("zxcv"));
        newCellList.add(newCell);
        newCellList.add(c);
        break;
    case INVALID_CELL_VALUE:
        if (CellUtil.matchingQualifier(c, EMPTY_COLUMN_BYTES)) {
            newCell = getCellWithPut(c);
            emptyCell = getVerifiedEmptyCell(c);
            newCellList.add(newCell);
            newCellList.add(emptyCell);
        } else {
            newCellList.add(c);
        }
        break;
    case INVALID_EMPTY_CELL:
        if (CellUtil.matchingQualifier(c, EMPTY_COLUMN_BYTES)) {
            newCell =
                    CellUtil.createCell(CellUtil.cloneRow(c), CellUtil.cloneFamily(c),
                            CellUtil.cloneQualifier(c), c.getTimestamp(),
                            KeyValue.Type.Delete.getCode(), VERIFIED_BYTES);
            newCellList.add(newCell);
        } else {
            newCellList.add(c);
        }
        break;
    case INVALID_EXTRA_CELL:
        newCell = getCellWithPut(c);
        emptyCell = getVerifiedEmptyCell(c);
        newCellList.add(newCell);
        newCellList.add(emptyCell);
        newCellList.add(c);
    }
}
 
Example 15
Source File: PrepareIndexMutationsForRebuildTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
void addCellToDelMutation(Delete del, byte[] family, byte[] column, long ts, KeyValue.Type type) throws Exception {
    byte[] rowKey = del.getRow();
    Cell cell = CellUtil.createCell(rowKey, family, column, ts, type.getCode(), null);
    del.addDeleteMarker(cell);
}
 
Example 16
Source File: PrepareIndexMutationsForRebuildTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
void addCellToPutMutation(Put put, byte[] family, byte[] column, long ts, byte[] value) throws Exception {
    byte[] rowKey = put.getRow();
    Cell cell = CellUtil.createCell(rowKey, family, column, ts, KeyValue.Type.Put.getCode(), value);
    put.add(cell);
}
 
Example 17
Source File: TransactionUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static Cell newDeleteColumnMarker(byte[] row, byte[] family, byte[] qualifier, long timestamp) {
    return CellUtil.createCell(row, family, qualifier, timestamp, KeyValue.Type.Put.getCode(), HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 18
Source File: TransactionUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static Cell newDeleteFamilyMarker(byte[] row, byte[] family, long timestamp) {
    return CellUtil.createCell(row, family, FAMILY_DELETE_MARKER, timestamp, KeyValue.Type.Put.getCode(), HConstants.EMPTY_BYTE_ARRAY);
}
 
Example 19
Source File: AbstractTransformMapper.java    From super-cloudops with Apache License 2.0 2 votes vote down vote up
/**
 * Add data to put.
 * 
 * @param put
 * @param family
 * @param qualifier
 * @param value
 * @param timestamp
 * @param type
 * @param hasNextQualifier
 */
protected void addPut(Put put, byte[] family, byte[] qualifier, byte[] value, long timestamp, byte type,
		boolean hasNextQualifier) throws IOException {
	Cell newCell = CellUtil.createCell(put.getRow(), family, qualifier, timestamp, type, value);
	put.add(newCell);
}