List of usage examples for java.util NavigableMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:org.apache.hadoop.hbase.TestMultiVersions.java
/** * Port of old TestScanMultipleVersions test here so can better utilize the * spun up cluster running more than just a single test. Keep old tests * crazyness.//from w ww. j a va 2 s .c om * * <p>Tests five cases of scans and timestamps. * @throws Exception */ @Test public void testScanMultipleVersions() throws Exception { final byte[] tableName = Bytes.toBytes("testScanMultipleVersions"); final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY)); final byte[][] rows = new byte[][] { Bytes.toBytes("row_0200"), Bytes.toBytes("row_0800") }; final byte[][] splitRows = new byte[][] { Bytes.toBytes("row_0500") }; final long[] timestamp = new long[] { 100L, 1000L }; this.admin.createTable(desc, splitRows); HTable table = new HTable(UTIL.getConfiguration(), tableName); // Assert we got the region layout wanted. NavigableMap<HRegionInfo, ServerName> locations = table.getRegionLocations(); assertEquals(2, locations.size()); int index = 0; for (Map.Entry<HRegionInfo, ServerName> e : locations.entrySet()) { HRegionInfo hri = e.getKey(); if (index == 0) { assertTrue(Bytes.equals(HConstants.EMPTY_START_ROW, hri.getStartKey())); assertTrue(Bytes.equals(hri.getEndKey(), splitRows[0])); } else if (index == 1) { assertTrue(Bytes.equals(splitRows[0], hri.getStartKey())); assertTrue(Bytes.equals(hri.getEndKey(), HConstants.EMPTY_END_ROW)); } index++; } // Insert data for (int i = 0; i < locations.size(); i++) { for (int j = 0; j < timestamp.length; j++) { Put put = new Put(rows[i], timestamp[j]); put.add(HConstants.CATALOG_FAMILY, null, timestamp[j], Bytes.toBytes(timestamp[j])); table.put(put); } } // There are 5 cases we have to test. Each is described below. for (int i = 0; i < rows.length; i++) { for (int j = 0; j < timestamp.length; j++) { Get get = new Get(rows[i]); get.addFamily(HConstants.CATALOG_FAMILY); get.setTimeStamp(timestamp[j]); Result result = table.get(get); int cellCount = 0; for (@SuppressWarnings("unused") Cell kv : result.listCells()) { cellCount++; } assertTrue(cellCount == 1); } table.close(); } // Case 1: scan with LATEST_TIMESTAMP. Should get two rows int count = 0; Scan scan = new Scan(); scan.addFamily(HConstants.CATALOG_FAMILY); ResultScanner s = table.getScanner(scan); try { for (Result rr = null; (rr = s.next()) != null;) { System.out.println(rr.toString()); count += 1; } assertEquals("Number of rows should be 2", 2, count); } finally { s.close(); } // Case 2: Scan with a timestamp greater than most recent timestamp // (in this case > 1000 and < LATEST_TIMESTAMP. Should get 2 rows. count = 0; scan = new Scan(); scan.setTimeRange(1000L, Long.MAX_VALUE); scan.addFamily(HConstants.CATALOG_FAMILY); s = table.getScanner(scan); try { while (s.next() != null) { count += 1; } assertEquals("Number of rows should be 2", 2, count); } finally { s.close(); } // Case 3: scan with timestamp equal to most recent timestamp // (in this case == 1000. Should get 2 rows. count = 0; scan = new Scan(); scan.setTimeStamp(1000L); scan.addFamily(HConstants.CATALOG_FAMILY); s = table.getScanner(scan); try { while (s.next() != null) { count += 1; } assertEquals("Number of rows should be 2", 2, count); } finally { s.close(); } // Case 4: scan with timestamp greater than first timestamp but less than // second timestamp (100 < timestamp < 1000). Should get 2 rows. count = 0; scan = new Scan(); scan.setTimeRange(100L, 1000L); scan.addFamily(HConstants.CATALOG_FAMILY); s = table.getScanner(scan); try { while (s.next() != null) { count += 1; } assertEquals("Number of rows should be 2", 2, count); } finally { s.close(); } // Case 5: scan with timestamp equal to first timestamp (100) // Should get 2 rows. count = 0; scan = new Scan(); scan.setTimeStamp(100L); scan.addFamily(HConstants.CATALOG_FAMILY); s = table.getScanner(scan); try { while (s.next() != null) { count += 1; } assertEquals("Number of rows should be 2", 2, count); } finally { s.close(); } }
From source file:org.apache.hadoop.hbase.regionserver.wal.HLogKey.java
public void readOlderScopes(NavigableMap<byte[], Integer> scopes) { if (scopes != null) { Iterator<Map.Entry<byte[], Integer>> iterator = scopes.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<byte[], Integer> scope = iterator.next(); String key = Bytes.toString(scope.getKey()); if (key.startsWith(PREFIX_CLUSTER_KEY)) { addClusterId(UUID.fromString(key.substring(PREFIX_CLUSTER_KEY.length()))); iterator.remove();/*from www . ja v a 2 s .c o m*/ } } if (scopes.size() > 0) { this.scopes = scopes; } } }
From source file:karma.oss.zookeeper.queue.ZkMessageQueue.java
/** * Get first available (that is un-claimed) element from the ordered child list. Then get the child's data from * zookeeper/* w w w.ja va2 s .co m*/ * @param orderedChildren * List of ordered children from zookeeper * @param markClaimed * Whether to claim this child. If true, the child will not be available in the next read until * put back by calling putbackElement() * @return * Bytes of available element, Optional.absent() otherwise * @throws KeeperException * @throws InterruptedException */ private Optional<Element<byte[]>> getFirstAvailableElement(NavigableMap<Long, String> orderedChildren, boolean markClaimed) throws KeeperException, InterruptedException { boolean hasUnClaimedElements = false; TreeMap<Long, String> claimedChildren = orderedClaimedChildren(null); for (Entry<Long, String> entry : orderedChildren.entrySet()) { // skip children already claimed if (claimedChildren.containsKey(entry.getKey())) { LOG.debug("Element already claimed: " + entry.getValue(), "; skipping"); continue; } hasUnClaimedElements = true; final String elementId = entry.getValue(); try { final String claimPath = claimDir + "/" + elementId; while (markClaimed) { try { final byte[] hostNameBytes = StringUtils.getBytesUtf8(getLocalHostName()); zookeeperRef.get().create(claimPath, hostNameBytes, acl, CreateMode.EPHEMERAL); LOG.info("Element claimed: " + entry.getValue()); break; } catch (KeeperException.NodeExistsException e) { LOG.info("Node at path: " + claimPath + " already exists. Trying different node."); throw e; // will be caught by the outer loop. } catch (KeeperException.NoNodeException e) { createDir(); } } final String path = dir + "/" + elementId; byte[] data = zookeeperRef.get().getData(path, false, null); return Optional.of(Element.create(elementId, data)); } catch (KeeperException.NodeExistsException e) { // Another client claimed the node first. // Refresh claimed children claimedChildren = orderedClaimedChildren(null); } } if (!hasUnClaimedElements) { throw new NoSuchElementException("No unclaimed element found"); } return Optional.absent(); }
From source file:com.example.cloud.bigtable.helloworld.JsonServlet.java
/** * doGet() - for a given row, put all values into a simple JSON request. * (basically a simple map<key,v>) * * Column Family CF1 is well known, so we don't mention it in the JSON output, any additional * families will be encoded as family:col, which is valid JSON, but not valid javascript. * * This is fairly simple code, so if there is a column with invalid syntax for JSON, there will be * an error.//www. j a va 2 s . com * Bigtable (and hbase) fields are basically blobs, so I've chosen to recognize a few "datatypes" * bool is defined as 1 byte (either 0x00 / 0x01) for (false / true) * counter (long) 64 bits 8 bytes and the first 4 bytes are either 0 or -128 * doubles we will keep as text in Bigtable / hbase **/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo(); String key; JSONObject json = new JSONObject(); if (path.length() < 5) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); log("doGet-bad length-" + path.length()); return; } // IMPORTANT - This try() is a java7 try w/ resources which will close() the table at the end. try (Table t = BigtableHelper.getConnection().getTable(TABLE)) { Get g = new Get(Bytes.toBytes(path.substring(1))); g.setMaxVersions(1); Result r = t.get(g); log(r.toString()); NavigableMap<byte[], NavigableMap<byte[], byte[]>> map = r.getNoVersionMap(); if (map == null) { resp.setContentType("application/json"); resp.getWriter().print("{}"); return; } // For Every Family for (Map.Entry<byte[], NavigableMap<byte[], byte[]>> family : map.entrySet()) { String cFamily = Bytes.toString(family.getKey()); // Each column for (Map.Entry<byte[], byte[]> entry : family.getValue().entrySet()) { String col = Bytes.toString(entry.getKey()); byte[] val = entry.getValue(); if (cFamily.equals(cf1)) { key = col; } else { key = cFamily + ":" + col; } // Based on data type, create the json. 8 bytes (leading 0) is an int (counter) // 1 byte (0/1) = (false/true) else string switch (val.length) { case 8: if ((val[0] == 0 && val[1] == 0 && val[2] == 0 && val[3] == 0) || (val[0] == -1 && val[1] == -1 && val[2] == -1 && val[3] == -1)) { json.put(key, Bytes.toLong(val)); } else { String temp = Bytes.toString(val); if (isNumeric(temp)) { if (isDigits(temp)) { json.put(key, Long.parseLong(temp)); } else { json.put(key, Double.parseDouble(temp)); } } else { json.put(key, temp); } } break; case 1: switch (val[0]) { case 0: json.put(key, false); continue; case 1: json.put(key, true); continue; default: } default: String temp = Bytes.toString(val); if (isNumeric(temp)) { if (isDigits(temp)) { json.put(key, Long.parseLong(temp)); } else { json.put(key, Double.parseDouble(temp)); } } else { json.put(key, temp); } } } } resp.addHeader("Access-Control-Allow-Origin", "*"); resp.setContentType("application/json"); json.write(resp.getWriter()); } catch (Exception e) { log("doGet", e); resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } resp.setStatus(HttpServletResponse.SC_OK); }
From source file:org.apache.blur.kvs.HdfsKeyValueStore.java
private Iterable<Entry<BytesRef, BytesRef>> getIterable(NavigableMap<BytesRef, Value> map) { final Set<Entry<BytesRef, Value>> entrySet = map.entrySet(); return new Iterable<Entry<BytesRef, BytesRef>>() { @Override// w w w .ja va 2 s . c o m public Iterator<Entry<BytesRef, BytesRef>> iterator() { final Iterator<Entry<BytesRef, Value>> iterator = entrySet.iterator(); return new Iterator<Entry<BytesRef, BytesRef>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<BytesRef, BytesRef> next() { final Entry<BytesRef, Value> e = iterator.next(); return new Entry<BytesRef, BytesRef>() { @Override public BytesRef setValue(BytesRef value) { throw new RuntimeException("Read only."); } @Override public BytesRef getValue() { return e.getValue()._bytesRef; } @Override public BytesRef getKey() { return e.getKey(); } }; } @Override public void remove() { throw new RuntimeException("Read only."); } }; } }; }
From source file:com.mozilla.socorro.dao.hbase.HbaseCrashCountDao.java
public CorrelationReport getReport(String date, String product, String version, String os, String signature) throws IOException { os = URLDecoder.decode(os, "UTF-8"); signature = URLDecoder.decode(signature, "UTF-8"); CorrelationReport report = new CorrelationReport(product, version, os); OperatingSystem osys = report.getOs(); HTableInterface table = null;/*from w w w . ja v a 2 s . c om*/ try { byte[] osRowKey = makeRowKey(date, product, version, os, null, true); byte[] sigRowKey = makeRowKey(date, product, version, os, signature, true); if (LOG.isInfoEnabled()) { LOG.debug("Date: " + date); LOG.debug("Product: " + product); LOG.debug("Version: " + version); LOG.debug("OS: " + os); LOG.debug("Signature: " + signature); LOG.info("Sig Row Key: " + new String(sigRowKey)); } table = pool.getTable(TABLE_NAME); Get sigGet = new Get(sigRowKey); Result sigResult = table.get(sigGet); if (sigResult != null && !sigResult.isEmpty()) { Signature sig = new Signature(signature); int sigCount = (int) Bytes.toLong(sigResult.getValue(SIGNATURE, COUNT)); sig.setCount(sigCount); NavigableMap<byte[], byte[]> nm = sigResult.getFamilyMap(ARCH); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String archCores = new String(entry.getKey()); long count = Bytes.toLong(entry.getValue()); sig.incrementCoreCount(archCores, (int) count); } nm = sigResult.getFamilyMap(MODULE_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String moduleVersion = new String(entry.getKey()); String[] splits = moduleVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { sig.incrementModuleCount(splits[0], splits[1], (int) count); } else { sig.incrementModuleCount(moduleVersion, "", (int) count); } } nm = sigResult.getFamilyMap(ADDON_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String addonVersion = new String(entry.getKey()); String[] splits = addonVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { sig.incrementAddonCount(splits[0], splits[1], (int) count); } else { sig.incrementAddonCount(addonVersion, "", (int) count); } } osys.addSignature(signature, sig); } else { LOG.warn("Signature result was empty for params: " + String.format("%s, %s, %s, %s, %s", date, product, version, os, signature)); } Get osGet = new Get(osRowKey); Result osResult = table.get(osGet); if (osResult != null && !osResult.isEmpty()) { int osCount = (int) Bytes.toLong(osResult.getValue(OS, COUNT)); osys.setCount(osCount); NavigableMap<byte[], byte[]> nm = osResult.getFamilyMap(ARCH); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String archCores = new String(entry.getKey()); long count = Bytes.toLong(entry.getValue()); osys.incrementCoreCount(archCores, (int) count); } nm = osResult.getFamilyMap(MODULE_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String moduleVersion = new String(entry.getKey()); String[] splits = moduleVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { osys.incrementModuleCount(splits[0], splits[1], (int) count); } else { osys.incrementModuleCount(moduleVersion, "", (int) count); } } nm = osResult.getFamilyMap(ADDON_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String addonVersion = new String(entry.getKey()); String[] splits = addonVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { osys.incrementAddonCount(splits[0], splits[1], (int) count); } else { osys.incrementAddonCount(addonVersion, "", (int) count); } } report.setOs(osys); } else { LOG.warn("OS result was empty for params: " + String.format("%s, %s, %s, %s", date, product, version, os)); } } finally { if (table != null) { pool.putTable(table); } } // calculate module ratios for proper sorting report.calculateModuleRatios(); return report; }
From source file:org.lilyproject.rowlog.impl.RowLogImpl.java
public List<RowLogMessage> getMessages(byte[] rowKey, String... subscriptionIds) throws RowLogException { List<RowLogMessage> messages = new ArrayList<RowLogMessage>(); Get get = new Get(rowKey); get.addFamily(executionStateColumnFamily); try {// w ww . java2 s. c o m Result result = rowTable.get(get); if (!result.isEmpty()) { NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(executionStateColumnFamily); for (Entry<byte[], byte[]> entry : familyMap.entrySet()) { SubscriptionExecutionState executionState = SubscriptionExecutionState .fromBytes(entry.getValue()); boolean add = false; if (subscriptionIds.length == 0) add = true; else { for (String subscriptionId : subscriptionIds) { if (!executionState.getState(subscriptionId)) add = true; } } if (add) messages.add(new RowLogMessageImpl(executionState.getTimestamp(), rowKey, Bytes.toLong(entry.getKey()), null, this)); } } } catch (IOException e) { throw new RowLogException("Failed to get messages", e); } return messages; }
From source file:com.mozilla.socorro.dao.hbase.HbaseCrashCountDao.java
public CorrelationReport getTopCrashers(String date, String product, String version, String os) throws IOException { Scan scan = new Scan(); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); String rowKeyExpr = "^[a-zA-Z0-9]{1}" + new String(makeRowKey(date, product, version, os, null, false)) + ".+"; RowFilter rowFilter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(rowKeyExpr)); filterList.addFilter(rowFilter);//from w w w .java 2 s . c o m SingleColumnValueFilter productFilter = new SingleColumnValueFilter(PRODUCT, Bytes.toBytes(product), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(true)); SingleColumnValueFilter productVersionFilter = new SingleColumnValueFilter(PRODUCT_VERSION, Bytes.toBytes(version), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(true)); SingleColumnValueFilter osFilter = new SingleColumnValueFilter(OS, Bytes.toBytes(os), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(true)); filterList.addFilter(productFilter); filterList.addFilter(productVersionFilter); filterList.addFilter(osFilter); scan.setFilter(filterList); // Want the values of these columns for filtered rows scan.addFamily(SIGNATURE); scan.addFamily(ARCH); scan.addFamily(MODULE_WITH_VERSION); scan.addFamily(ADDON_WITH_VERSION); CorrelationReport report = new CorrelationReport(date, product, version, os); HTableInterface table = null; ResultScanner scanner = null; try { table = pool.getTable(TABLE_NAME); scanner = table.getScanner(scan); long resultCount = 0; for (Result r : scanner) { OperatingSystem osys = report.getOs(); resultCount++; if (Log.isDebugEnabled()) { LOG.debug("Returned row: " + new String(r.getRow())); } byte[] sigBytes = r.getValue(SIGNATURE, NAME); byte[] sigCountBytes = r.getValue(SIGNATURE, COUNT); if (sigBytes != null && sigCountBytes != null) { String rawSignature = new String(sigBytes); Signature sig = null; if (osys.getSignatures().containsKey(rawSignature)) { sig = osys.getSignatures().get(rawSignature); } else { sig = new Signature(rawSignature); } sig.setCount(sig.getCount() + (int) Bytes.toLong(sigCountBytes)); NavigableMap<byte[], byte[]> nm = r.getFamilyMap(ARCH); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String archCores = new String(entry.getKey()); long count = Bytes.toLong(entry.getValue()); sig.incrementCoreCount(archCores, (int) count); } nm = r.getFamilyMap(MODULE_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String moduleVersion = new String(entry.getKey()); String[] splits = moduleVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { sig.incrementModuleCount(splits[0], splits[1], (int) count); } else { sig.incrementModuleCount(moduleVersion, "", (int) count); } } nm = r.getFamilyMap(ADDON_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String addonVersion = new String(entry.getKey()); String[] splits = addonVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { sig.incrementAddonCount(splits[0], splits[1], (int) count); } else { sig.incrementAddonCount(addonVersion, "", (int) count); } } osys.addSignature(sig.getName(), sig); report.setOs(osys); } } if (Log.isDebugEnabled()) { LOG.debug("Result Count: " + resultCount); } byte[] osRowKey = makeRowKey(date, product, version, os, null, true); Get osGet = new Get(osRowKey); Result osResult = table.get(osGet); if (osResult != null && !osResult.isEmpty()) { OperatingSystem osys = report.getOs(); int osCount = (int) Bytes.toLong(osResult.getValue(OS, COUNT)); osys.setCount(osCount); NavigableMap<byte[], byte[]> nm = osResult.getFamilyMap(ARCH); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String archCores = new String(entry.getKey()); long count = Bytes.toLong(entry.getValue()); osys.incrementCoreCount(archCores, (int) count); } nm = osResult.getFamilyMap(MODULE_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String moduleVersion = new String(entry.getKey()); String[] splits = moduleVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { osys.incrementModuleCount(splits[0], splits[1], (int) count); } else { osys.incrementModuleCount(moduleVersion, "", (int) count); } } nm = osResult.getFamilyMap(ADDON_WITH_VERSION); for (Map.Entry<byte[], byte[]> entry : nm.entrySet()) { String addonVersion = new String(entry.getKey()); String[] splits = addonVersion.split(MODULE_INFO_DELIMITER); long count = Bytes.toLong(entry.getValue()); if (splits.length == 2) { osys.incrementAddonCount(splits[0], splits[1], (int) count); } else { osys.incrementAddonCount(addonVersion, "", (int) count); } } report.setOs(osys); } } finally { if (scanner != null) { scanner.close(); } if (table != null) { pool.putTable(table); } } report.calculateModuleRatios(); return report; }
From source file:org.kiji.schema.tools.LsTool.java
/** * Prints cell data from the <code>row</code> for each column specified on the * <code>request</code>.// ww w . ja v a2s . c o m * * @param row The row to read from. * @param mapTypeFamilies The map type families to print. * @param groupTypeColumns The group type columns to print. * @throws IOException if there is an error retrieving data from the KijiRowData. */ private void printRow(KijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns) throws IOException { // Unpack and print result for the map type families. for (Entry<FamilyLayout, List<String>> entry : mapTypeFamilies.entrySet()) { final FamilyLayout family = entry.getKey(); if (family.getDesc().getMapSchema().getType() == SchemaType.COUNTER) { // If this map family of counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { for (String key : row.getQualifiers(family.getName())) { KijiCounter counter = row.getCounter(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), family.getName(), key, Long.valueOf(counter.getValue())); } } // If this map family of counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { KijiCounter counter = row.getCounter(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), family.getName(), key, Long.valueOf(counter.getValue())); } } } } else { // If this map family of non-counters has no qualifiers, print entire family. if (entry.getValue().isEmpty()) { NavigableMap<String, NavigableMap<Long, Object>> keyTimeseriesMap = row .getValues(family.getName(), (Schema) null); for (String key : keyTimeseriesMap.keySet()) { for (Entry<Long, Object> timestampedCell : keyTimeseriesMap.get(key).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue()); } } // If this map family of non-counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { NavigableMap<Long, Object> timeseriesMap = row.getValues(family.getName(), key, (Schema) null); for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue()); } } } } } // Unpack and print result for the group type families. for (Entry<FamilyLayout, List<ColumnLayout>> entry : groupTypeColumns.entrySet()) { String familyName = entry.getKey().getName(); for (ColumnLayout column : entry.getValue()) { final KijiColumnName colName = new KijiColumnName(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final KijiCounter counter = row.getCounter(colName.getFamily(), colName.getQualifier()); if (null != counter) { printCell(row.getEntityId(), counter.getTimestamp(), colName.getFamily(), colName.getQualifier(), Long.valueOf(counter.getValue())); } } else { for (Entry<Long, Object> timestampedCell : row .getValues(colName.getFamily(), colName.getQualifier(), (Schema) null).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(), timestampedCell.getValue()); } } } } getPrintStream().println(""); }
From source file:org.openstreetmap.osmosis.hbase.utility.MockHTable.java
/** * {@inheritDoc}/*from w w w. j a va 2 s . c om*/ */ @Override public Result increment(Increment increment) throws IOException { this.sleeper(); List<KeyValue> kvs = new ArrayList<KeyValue>(); Map<byte[], NavigableMap<byte[], Long>> famToVal = increment.getFamilyMapOfLongs(); for (Map.Entry<byte[], NavigableMap<byte[], Long>> ef : famToVal.entrySet()) { byte[] family = ef.getKey(); NavigableMap<byte[], Long> qToVal = ef.getValue(); for (Map.Entry<byte[], Long> eq : qToVal.entrySet()) { long newValue = incrementColumnValue(increment.getRow(), family, eq.getKey(), eq.getValue()); kvs.add(new KeyValue(increment.getRow(), family, eq.getKey(), Bytes.toBytes(newValue))); } } return new Result(kvs); }