Java Code Examples for org.apache.hadoop.hbase.client.Result#getFamilyMap()

The following examples show how to use org.apache.hadoop.hbase.client.Result#getFamilyMap() . These examples are extracted from open source projects. 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 Project: zxl   File: BaseDao.java    License: Apache License 2.0 6 votes vote down vote up
protected final Object parseFamily(String familyName, Result result) {
	if (result.isEmpty()) {
		return null;
	}
	try {
		Field familyField = clazz.getDeclaredField(familyName);
		byte[] familyNameBytes = Bytes.toBytes(familyField.getName());
		if (HBaseUtil.isBaseFamily(familyField)) {
			return parseNotArrayClass(familyField, familyNameBytes, result);
		} else if (HBaseUtil.isArrayFamily(familyField)) {
			byte[] countBytes = result.getValue(familyNameBytes, COUNT_COLUMN_BYTE_ARRAY);
			if (countBytes != null) {
				int count = Bytes.toInt(countBytes);
				Map<byte[], byte[]> familyMap = result.getFamilyMap(familyNameBytes);
				if (familyMap != null) {
					return parseArrayClass(familyField, count, familyMap);
				}
			}
		} else {
			LogUtil.warn(LOGGER, "������ݿ��ѯ���ʱ��������[" + familyField.getName() + "]");
		}
		return null;
	} catch (Exception cause) {
		throw new RuntimeException(cause);
	}
}
 
Example 2
Source Project: hraven   File: AppSummaryService.java    License: Apache License 2.0 6 votes vote down vote up
private AppSummary populateAppSummary(Result result, AppSummary as) {

    NavigableMap<byte[], byte[]> infoValues =
        result.getFamilyMap(Constants.INFO_FAM_BYTES);
    as.setTotalMaps(as.getTotalMaps() + ByteUtil
        .getValueAsLong(AggregationConstants.TOTAL_MAPS_BYTES, infoValues));
    as.setTotalReduces(as.getTotalReduces() + ByteUtil
        .getValueAsLong(AggregationConstants.TOTAL_REDUCES_BYTES, infoValues));
    as.setMbMillis(as.getMbMillis() + ByteUtil
        .getValueAsLong(AggregationConstants.MEGABYTEMILLIS_BYTES, infoValues));
    as.setCost(as.getCost() + ByteUtil
        .getValueAsDouble(AggregationConstants.JOBCOST_BYTES, infoValues));
    as.setJobCount(as.getJobCount() + ByteUtil
        .getValueAsLong(AggregationConstants.TOTAL_JOBS_BYTES, infoValues));
    as.setNumberRuns(as.getNumberRuns() + ByteUtil
        .getValueAsLong(AggregationConstants.NUMBER_RUNS_BYTES, infoValues));
    as.setMapSlotMillis(as.getMapSlotMillis() + ByteUtil.getValueAsLong(
        AggregationConstants.SLOTS_MILLIS_MAPS_BYTES, infoValues));
    as.setReduceSlotMillis(as.getReduceSlotMillis() + ByteUtil.getValueAsLong(
        AggregationConstants.SLOTS_MILLIS_REDUCES_BYTES, infoValues));
    as.setQueuesFromString(ByteUtil
        .getValueAsString(AggregationConstants.HRAVEN_QUEUE_BYTES, infoValues));

    return as;
  }
 
Example 3
@Override
public TraceAnnotationDto mapRow(Result res, int rowNum) throws Exception {
    String rowKey = new String(res.getRow());
    NavigableMap<byte[], byte[]> familyMap = res.getFamilyMap(TABLE_ANNOTATION_COLUMN_FAMILY.getBytes());


    String[] ss = rowKey.split("_");
    String iface = ss[0];
    String method = ss[1];
    String type = ss[2];
    long timestamp = Long.parseLong(ss[3]);

    String traceId = "", value = "";
    for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
        traceId = new String(entry.getKey());
        value = new String(entry.getValue());
    }

    TraceAnnotationDto tad = new TraceAnnotationDto();
    tad.setRowKey(rowKey).setIface(iface).setMethod(method).setType(type).setTimestamp(timestamp);
    tad.setTraceId(traceId).setValue(value);
    return tad;
}
 
Example 4
Source Project: SkyEye   File: TraceDto.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public TraceDto mapRow(Result res, int rowNum) throws Exception {

    String traceId = new String(res.getRow());
    NavigableMap<byte[], byte[]> data = res.getFamilyMap(Constants.TABLE_TRACE_COLUMN_FAMILY.getBytes());

    String spanId;
    JSONObject spanDetail;
    TreeMap<String, JSONObject> map = new TreeMap<>();
    Set<Map.Entry<byte[], byte[]>> spanEntrySet = data.entrySet();
    for (Map.Entry<byte[], byte[]> entry : spanEntrySet) {
        spanId = new String(entry.getKey());
        spanDetail = JSON.parseObject(new String(entry.getValue()));
        map.put(spanId, spanDetail);
    }
    Set<Map.Entry<String, JSONObject>> spans = map.entrySet();


    TraceDto rtn = new TraceDto();
    rtn.setTraceId(traceId).setSpans(spans);
    return rtn;
}
 
Example 5
@Override
public TraceTimeConsumeDto mapRow(Result res, int rowNum) throws Exception {
    TraceTimeConsumeDto dto = new TraceTimeConsumeDto();
    Map<byte[], byte[]> familyMap = res.getFamilyMap(Constants.TABLE_TIME_CONSUME_COLUMN_FAMILY.getBytes());
    Set<Map.Entry<byte[], byte[]>> entrySet = familyMap.entrySet();
    for (Map.Entry<byte[], byte[]> en : entrySet) {
        dto.setTraceId(new String(en.getKey())).setConsumeTime(RadixUtil.bytesToLong(en.getValue()));
    }
    String[] ss = new String(res.getRow()).split(Constants.UNDER_LINE);
    String iface = ss[0];
    String method = ss[1];
    Long startTime = Long.parseLong(ss[2]);
    Long endTime = startTime + dto.getConsumeTime();
    String rowKey = new String(res.getRow());

    dto.setIface(iface).setMethod(method).setStartTime(startTime).setEndTime(endTime).setRowKey(rowKey);
    return dto;
}
 
Example 6
@Override
public Collection<byte[]> extract(Result result) {
    List<byte[]> values = Lists.newArrayList();

    NavigableMap<byte[], byte[]> qualifiersToValues = result.getFamilyMap(columnFamily);
    if (qualifiersToValues != null) {
        for (byte[] qualifier : qualifiersToValues.navigableKeySet().tailSet(prefix)) {
            if (Bytes.startsWith(qualifier, prefix)) {
                values.add(extractInternal(qualifier, qualifiersToValues.get(qualifier)));
            } else {
                break;
            }
        }
    }
    return values;
}
 
Example 7
Source Project: Eagle   File: HBaseLogByRowkeyReader.java    License: Apache License 2.0 6 votes vote down vote up
private InternalLog buildLog(Result result) {
	final InternalLog log = new InternalLog();
	final byte[] rowkey = result.getRow();
	log.setEncodedRowkey(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
	long timestamp = ByteUtil.bytesToLong(rowkey, 4);
	timestamp = Long.MAX_VALUE - timestamp;
	log.setTimestamp(timestamp);
	Map<String, byte[]> qualifierValues = new HashMap<String, byte[]>();
	log.setQualifierValues(qualifierValues);
	NavigableMap<byte[], byte[]> map = result.getFamilyMap(this.columnFamily.getBytes());
	if(map == null){
		throw new NoSuchRowException(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
	}
	for(Map.Entry<byte[], byte[]> entry : map.entrySet()){
		byte[] qualifier = entry.getKey();
		byte[] value = entry.getValue();
		qualifierValues.put(new String(qualifier), value);
	}
	return log;
}
 
Example 8
Source Project: eagle   File: HBaseLogByRowkeyReader.java    License: Apache License 2.0 6 votes vote down vote up
private InternalLog buildLog(Result result) {
    final InternalLog log = new InternalLog();
    final byte[] rowkey = result.getRow();
    log.setEncodedRowkey(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
    long timestamp = ByteUtil.bytesToLong(rowkey, 4);
    timestamp = Long.MAX_VALUE - timestamp;
    log.setTimestamp(timestamp);
    Map<String, byte[]> qualifierValues = new HashMap<String, byte[]>();
    log.setQualifierValues(qualifierValues);
    NavigableMap<byte[], byte[]> map = result.getFamilyMap(this.columnFamily.getBytes());
    if (map == null) {
        throw new NoSuchRowException(EagleBase64Wrapper.encodeByteArray2URLSafeString(rowkey));
    }
    for (Map.Entry<byte[], byte[]> entry : map.entrySet()) {
        byte[] qualifier = entry.getKey();
        byte[] value = entry.getValue();
        qualifierValues.put(new String(qualifier), value);
    }
    return log;
}
 
Example 9
Source Project: hraven   File: AppSummaryService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * constructs App key from the result set based on cluster, user, appId picks
 * those results that satisfy the time range criteria
 * @param result
 * @param startTime
 * @param endTime
 * @return flow key
 * @throws IOException
 */
private AppKey getNewAppKeyFromResult(Result result, long startTime,
    long endTime) throws IOException {

  byte[] rowKey = result.getRow();
  byte[][] keyComponents = ByteUtil.split(rowKey, Constants.SEP_BYTES);
  String cluster = Bytes.toString(keyComponents[0]);
  String user = Bytes.toString(keyComponents[1]);
  String appId = Bytes.toString(keyComponents[2]);

  NavigableMap<byte[], byte[]> valueMap =
      result.getFamilyMap(Constants.INFO_FAM_BYTES);
  long runId = Long.MAX_VALUE;
  for (Map.Entry<byte[], byte[]> entry : valueMap.entrySet()) {
    long tsl = Bytes.toLong(entry.getValue());
    // get the earliest runid, which indicates the first time this app ran
    if (tsl < runId) {
      runId = tsl;
    }
  }
  if ((runId >= startTime) && (runId <= endTime)) {
    AppKey ak = new AppKey(cluster, user, appId);
    return ak;
  }
  return null;
}
 
Example 10
Source Project: pxf   File: HBaseLookupTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Loads mappings for given table name from the lookup table
 * {@link #LOOKUPTABLENAME}. The table name should be in the row key, and
 * the family name should be {@link #LOOKUPCOLUMNFAMILY}.
 *
 * @param tableName HBase table name
 * @throws IOException when HBase operations fail
 */
private void loadMappingMap(String tableName) throws IOException {
    Get lookupRow = new Get(Bytes.toBytes(tableName));
    lookupRow.setMaxVersions(1);
    lookupRow.addFamily(LOOKUPCOLUMNFAMILY);
    Result row;

    row = lookupTable.get(lookupRow);
    rawTableMapping = row.getFamilyMap(LOOKUPCOLUMNFAMILY);
    LOG.debug("lookup table mapping for " + tableName + " has "
            + (rawTableMapping == null ? 0 : rawTableMapping.size())
            + " entries");
}
 
Example 11
Source Project: zxl   File: BaseDao.java    License: Apache License 2.0 5 votes vote down vote up
protected final E parse(Result result) {
	if (result.isEmpty()) {
		return null;
	}
	try {
		E entity = clazz.newInstance();
		entity.setId(Bytes.toString(result.getRow()));
		for (Field familyField : ReflectUtil.getAllFields(clazz)) {
			if (!HBaseUtil.isFamily(familyField)) {
				continue;
			}
			byte[] familyName = Bytes.toBytes(familyField.getName());
			if (HBaseUtil.isBaseFamily(familyField)) {
				ReflectUtil.setFieldValue(entity, familyField, parseNotArrayClass(familyField, familyName, result));
			} else if (HBaseUtil.isArrayFamily(familyField)) {
				byte[] countBytes = result.getValue(familyName, COUNT_COLUMN_BYTE_ARRAY);
				if (countBytes != null) {
					int count = Bytes.toInt(countBytes);
					Map<byte[], byte[]> familyMap = result.getFamilyMap(familyName);
					if (familyMap != null) {
						ReflectUtil.setFieldValue(entity, familyField, parseArrayClass(familyField, count, familyMap));
					}
				}
			} else {
				LogUtil.warn(LOGGER, "������ݿ��ѯ���ʱ��������[" + familyField.getName() + "]");
			}
		}
		return entity;
	} catch (Exception cause) {
		throw new RuntimeException(cause);
	}
}
 
Example 12
public static long toRow(Heap heap, Result r, TableMeta table, int tableId) {
    if (r.isEmpty()) {
        return 0;
    }

    // some preparation
    
    NavigableMap<byte[], byte[]> dataFamilyMap = r.getFamilyMap(DATA_COLUMN_FAMILY_BYTES);
    byte[] colDataType = dataFamilyMap.get(SYS_COLUMN_DATATYPE_BYTES);
    byte[] sizeBytes = dataFamilyMap.get(SYS_COLUMN_SIZE_BYTES);
    int size = Bytes.toInt(sizeBytes);
    
    // populate the row. system table doesn't come with metadata
    
    VaporizingRow row = null;
    byte[] key = hbaseKeyToAnts(r.getRow());
    if (table != null) {
        row = populateUsingMetadata(heap, table, dataFamilyMap, colDataType, size, key);
    }
    else if (tableId < 0x100) {
        row = populateDirect(heap, dataFamilyMap, colDataType, size, key);
    }
    else {
        throw new OrcaHBaseException("metadata not found for table " + tableId);
    }
    row.setVersion(1);
    long pRow = Row.from(heap, row);
    return pRow;
}
 
Example 13
public static long toIndexLine(Heap heap, Result r) {
    if (r.isEmpty()) {
        return 0;
    }
    NavigableMap<byte[], byte[]> sys = r.getFamilyMap(DATA_COLUMN_FAMILY_BYTES);
    byte[] indexKey = r.getRow();
    byte[] rowKey = sys.get(SYS_COLUMN_INDEXKEY_BYTES);
    byte misc = sys.get(SYS_COLUMN_MISC_BYTES)[0];
    indexKey = hbaseKeyToAnts(indexKey);
    rowKey = hbaseKeyToAnts(rowKey);
    return IndexLine.alloc(heap, indexKey, rowKey, misc).getAddress();
}
 
Example 14
Source Project: metron   File: AbstractConverter.java    License: Apache License 2.0 5 votes vote down vote up
public LookupKV<KEY_T, VALUE_T> fromResult(Result result, String columnFamily, KEY_T key, VALUE_T value) throws IOException {
  if(result == null || result.getRow() == null) {
    return null;
  }
  key.fromBytes(result.getRow());
  byte[] cf = Bytes.toBytes(columnFamily);
  NavigableMap<byte[], byte[]> cols = result.getFamilyMap(cf);
  value.fromColumns(cols.entrySet());
  return new LookupKV<>(key, value);
}
 
Example 15
Source Project: metron   File: UserSettingsClient.java    License: Apache License 2.0 5 votes vote down vote up
public Map<String, String> getAllUserSettings(Result result) {
  if (result == null) {
    return new HashMap<>();
  }
  NavigableMap<byte[], byte[]> columns = result.getFamilyMap(cf);
  if(columns == null || columns.size() == 0) {
    return new HashMap<>();
  }
  Map<String, String> userSettingsMap = new HashMap<>();
  for(Map.Entry<byte[], byte[]> column: columns.entrySet()) {
    userSettingsMap.put(new String(column.getKey(), StandardCharsets.UTF_8), new String(column.getValue(), StandardCharsets.UTF_8));
  }
  return userSettingsMap;
}
 
Example 16
Source Project: kylin   File: AclTableMigrationTool.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, LegacyAceInfo> getAllAceInfo(Result result) throws IOException {
    Map<String, LegacyAceInfo> allAceInfoMap = new HashMap<>();
    NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes(AclConstant.ACL_ACES_FAMILY));

    if (familyMap != null && !familyMap.isEmpty()) {
        for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
            String sid = new String(entry.getKey(), StandardCharsets.UTF_8);
            LegacyAceInfo aceInfo = aceSerializer.deserialize(entry.getValue());
            if (null != aceInfo) {
                allAceInfoMap.put(sid, aceInfo);
            }
        }
    }
    return allAceInfoMap;
}
 
Example 17
public static long getVersion(Result r) {
    NavigableMap<byte[], byte[]> sys = r.getFamilyMap(DATA_COLUMN_FAMILY_BYTES);
    byte[] versionBytes = sys.get(SYS_COLUMN_VERSION_BYTES);
    long version = Bytes.toLong(versionBytes);
    return version;
}
 
Example 18
@Test
public void shouldPatchDocument() throws Exception {
  String guid = "bro_2";

  // request used to find the message
  MockHttpServletRequestBuilder findOneRequest = post(searchUrl + "/findOne")
          .with(httpBasic(user, password))
          .with(csrf())
          .contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
          .content(findMessage0);

  // request used to patch the document
  MockHttpServletRequestBuilder patchRequest = patch(updateUrl + "/patch")
          .with(httpBasic(user, password))
          .with(csrf())
          .contentType(MediaType.parseMediaType("application/json;charset=UTF-8"))
          .content(patch);

  // the document should exist, but without the 'project' field defined
  this.mockMvc.perform(findOneRequest)
          .andExpect(status().isOk())
          .andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
          .andExpect(jsonPath("$.source:type").value("bro"))
          .andExpect(jsonPath("$.guid").value(guid))
          .andExpect(jsonPath("$.project").doesNotExist())
          .andExpect(jsonPath("$.timestamp").value(2));

  // nothing is recorded in HBase
  MockHTable table = (MockHTable) MockHBaseTableProvider.getFromCache(TABLE);
  assertEquals(0,table.size());

  // patch the document
  this.mockMvc.perform(patchRequest)
          .andExpect(status().isOk());

  // the document should now have the 'project' field
  this.mockMvc.perform(findOneRequest)
          .andExpect(status().isOk())
          .andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
          .andExpect(jsonPath("$.source:type").value("bro"))
          .andExpect(jsonPath("$.guid").value(guid))
          .andExpect(jsonPath("$.project").value("metron"))
          .andExpect(jsonPath("$.timestamp").value(2));

  // the change should be recorded in HBase
  assertEquals(1,table.size());
  {
      //ensure hbase is up to date
      Get g = new Get(new HBaseDao.Key(guid,"bro").toBytes());
      Result r = table.get(g);
      NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes(StandardCharsets.UTF_8));
      assertEquals(1, columns.size());
  }
}
 
Example 19
Source Project: hbase   File: TestTableInputFormat.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Verify that the result and key have expected values.
 *
 * @param r single row result
 * @param key the row key
 * @param expectedKey the expected key
 * @param expectedValue the expected value
 * @return true if the result contains the expected key and value, false otherwise.
 */
static boolean checkResult(Result r, ImmutableBytesWritable key,
    byte[] expectedKey, byte[] expectedValue) {
  assertEquals(0, key.compareTo(expectedKey));
  Map<byte[], byte[]> vals = r.getFamilyMap(FAMILY);
  byte[] value = vals.values().iterator().next();
  assertTrue(Arrays.equals(value, expectedValue));
  return true; // if succeed
}
 
Example 20
Source Project: hbase   File: TestTableInputFormat.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Verify that the result and key have expected values.
 *
 * @param r single row result
 * @param key the row key
 * @param expectedKey the expected key
 * @param expectedValue the expected value
 * @return true if the result contains the expected key and value, false otherwise.
 */
static boolean checkResult(Result r, ImmutableBytesWritable key,
    byte[] expectedKey, byte[] expectedValue) {
  assertEquals(0, key.compareTo(expectedKey));
  Map<byte[], byte[]> vals = r.getFamilyMap(FAMILY);
  byte[] value = vals.values().iterator().next();
  assertTrue(Arrays.equals(value, expectedValue));
  return true; // if succeed
}