List of usage examples for java.util NavigableMap entrySet
Set<Map.Entry<K, V>> entrySet();
From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java
public static <T> List<RowResult<Set<T>>> cellsToRows(ListMultimap<Cell, T> cells) { List<RowResult<Set<T>>> result = Lists.newArrayList(); NavigableMap<byte[], SortedMap<byte[], List<T>>> s = Cells.breakCellsUpByRow(Multimaps.asMap(cells)); for (Entry<byte[], SortedMap<byte[], List<T>>> e : s.entrySet()) { result.add(RowResult.create(e.getKey(), listSortedMapToSetSortedMap(e.getValue()))); }// ww w. j a v a 2 s . c om return result; }
From source file:com.inclouds.hbase.utils.RegionServerPoker.java
private static Set<HRegionInfo> regionsForServer(NavigableMap<HRegionInfo, ServerName> map, ServerName sn) { Set<Map.Entry<HRegionInfo, ServerName>> entries = map.entrySet(); Set<HRegionInfo> infos = new HashSet<HRegionInfo>(); LOG.info("Regions for " + sn); for (Map.Entry<HRegionInfo, ServerName> entry : entries) { ServerName s = entry.getValue(); if (s.equals(sn)) { HRegionInfo region = entry.getKey(); LOG.info("Adding region:" + region); infos.add(region);// w w w . j av a 2s . com } } return infos; }
From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java
public static <T> List<RowResult<T>> cellsToRows(Map<Cell, T> cells) { NavigableMap<byte[], SortedMap<byte[], T>> byRow = Cells.breakCellsUpByRow(cells); List<RowResult<T>> result = Lists.newArrayList(); for (Entry<byte[], SortedMap<byte[], T>> e : byRow.entrySet()) { result.add(RowResult.create(e.getKey(), e.getValue())); }/*from w w w . j a v a2 s . c o m*/ return result; }
From source file:nz.co.fortytwo.signalk.model.impl.SignalKModelFactory.java
/** * Save the current state of the signalk config * //w w w.java2 s . com * @throws IOException */ public static void saveConfig(SignalKModel model) throws IOException { if (model != null) { File jsonFile = new File(SIGNALK_CFG_SAVE_FILE); NavigableMap<String, Object> config = model.getSubMap(SignalKConstants.CONFIG); JsonSerializer ser = new JsonSerializer(); ser.setPretty(3); StringBuffer buffer = new StringBuffer(); if (config != null && config.size() > 0) { ser.write(config.entrySet().iterator(), '.', buffer); } else { buffer.append("{}"); } FileUtils.writeStringToFile(jsonFile, buffer.toString()); logger.debug(" Saved model state to " + SIGNALK_CFG_SAVE_FILE); } }
From source file:org.kiji.rest.util.RowResourceUtil.java
/** * Util method to write a rest row into Kiji. * * @param kijiTable is the table to write into. * @param entityId is the entity id of the row to write. * @param kijiRestRow is the row model to write to Kiji. * @param schemaTable is the handle to the schema table used to resolve the KijiRestCell's * writer schema if it was specified as a UID. * @throws IOException if there a failure writing the row. *//*from w ww.j a v a 2 s. com*/ public static void writeRow(KijiTable kijiTable, EntityId entityId, KijiRestRow kijiRestRow, KijiSchemaTable schemaTable) throws IOException { final KijiTableWriter writer = kijiTable.openTableWriter(); // Default global timestamp. long globalTimestamp = System.currentTimeMillis(); try { for (Entry<String, NavigableMap<String, List<KijiRestCell>>> familyEntry : kijiRestRow.getCells() .entrySet()) { String columnFamily = familyEntry.getKey(); NavigableMap<String, List<KijiRestCell>> qualifiedCells = familyEntry.getValue(); for (Entry<String, List<KijiRestCell>> qualifiedCell : qualifiedCells.entrySet()) { final KijiColumnName column = new KijiColumnName(columnFamily, qualifiedCell.getKey()); if (!kijiTable.getLayout().exists(column)) { throw new WebApplicationException( new IllegalArgumentException("Specified column does not exist: " + column), Response.Status.BAD_REQUEST); } for (KijiRestCell restCell : qualifiedCell.getValue()) { final long timestamp; if (null != restCell.getTimestamp()) { timestamp = restCell.getTimestamp(); } else { timestamp = globalTimestamp; } if (timestamp >= 0) { // Put to either a counter or a regular cell. if (SchemaType.COUNTER == kijiTable.getLayout().getCellSchema(column).getType()) { JsonNode parsedCounterValue = BASIC_MAPPER.valueToTree(restCell.getValue()); if (parsedCounterValue.isIntegralNumber()) { // Write the counter cell. writer.put(entityId, column.getFamily(), column.getQualifier(), timestamp, parsedCounterValue.asLong()); } else if (parsedCounterValue.isContainerNode()) { if (null != parsedCounterValue.get(COUNTER_INCREMENT_KEY) && parsedCounterValue.get(COUNTER_INCREMENT_KEY).isIntegralNumber()) { // Counter incrementation does not support timestamp. if (null != restCell.getTimestamp()) { throw new WebApplicationException(new IllegalArgumentException( "Counter incrementation does not support " + "timestamp. Do not specify timestamp in request.")); } // Increment counter cell. writer.increment(entityId, column.getFamily(), column.getQualifier(), parsedCounterValue.get(COUNTER_INCREMENT_KEY).asLong()); } else { throw new WebApplicationException(new IllegalArgumentException( "Counter increment could not be parsed " + "as long: " + parsedCounterValue + ". Provide a json node such as {\"incr\" : 123}."), Response.Status.BAD_REQUEST); } } else { // Could not parse parameter to a long. throw new WebApplicationException(new IllegalArgumentException( "Counter value could not be parsed as long: " + parsedCounterValue + ". Provide a long value to set the counter."), Response.Status.BAD_REQUEST); } } else { // Write the cell. String jsonValue = restCell.getValue().toString(); // TODO: This is ugly. Converting from Map to JSON to String. if (restCell.getValue() instanceof Map<?, ?>) { JsonNode node = BASIC_MAPPER.valueToTree(restCell.getValue()); jsonValue = node.toString(); } Schema actualWriter = restCell.getWriterSchema(schemaTable); if (actualWriter == null) { throw new IOException("Unrecognized schema " + restCell.getValue()); } putCell(writer, entityId, jsonValue, column, timestamp, actualWriter); } } } } } } finally { ResourceUtils.closeOrLog(writer); } }
From source file:org.apache.metron.enrichment.cli.LatencySummarizer.java
public static void updateStats(LatencyStats stats, Map<String, Object> doc) { Map<String, Long> latencyMap = new HashMap<>(); NavigableMap<Long, String> latencyInvMap = new TreeMap<>(); for (Map.Entry<String, Object> kv : doc.entrySet()) { if (kv.getKey().endsWith(".ts")) { String base = getBaseMetric(kv.getKey()); long latency = Long.parseLong(kv.getValue().toString()); latencyInvMap.put(latency, base); latencyMap.put(base, latency); }/*from w w w . j a va2 s. c o m*/ } List<String> metrics = new ArrayList<>(); for (Map.Entry<Long, String> kv : latencyInvMap.entrySet()) { metrics.add(kv.getValue()); } stats.updateMetrics(metrics); for (int i = 0; i < metrics.size(); ++i) { for (int j = i + 1; j < metrics.size(); ++j) { Pair p = new Pair(metrics.get(i), metrics.get(j)); long ms = latencyMap.get(metrics.get(j)) - latencyMap.get(metrics.get(i)); stats.put(j - i, p, ms); } } }
From source file:org.kiji.schema.tools.ToolUtils.java
/** * Prints cell data from the <code>row</code> for each column specified on the * <code>request</code>.//from w w w. j a v a2s. c om * * @param row The row to read from. * @param mapTypeFamilies The map type families to print. * @param groupTypeColumns The group type columns to print. * @param printStream The stream to print to. * @throws IOException if there is an error retrieving data from the KijiRowData. */ public static void printRow(KijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns, PrintStream printStream) 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())) { KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } // If this map family of counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { KijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } } } 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()); 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(), printStream); } } // 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); for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue(), printStream); } } } } } // 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 = KijiColumnName.create(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final KijiCell<Long> counter = row.getMostRecentCell(colName.getFamily(), colName.getQualifier()); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } else { for (Entry<Long, Object> timestampedCell : row .getValues(colName.getFamily(), colName.getQualifier()).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(), timestampedCell.getValue(), printStream); } } } } printStream.println(""); }
From source file:com.moz.fiji.schema.tools.ToolUtils.java
/** * Prints cell data from the <code>row</code> for each column specified on the * <code>request</code>.//from w w w .ja va 2s . 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. * @param printStream The stream to print to. * @throws IOException if there is an error retrieving data from the FijiRowData. */ public static void printRow(FijiRowData row, Map<FamilyLayout, List<String>> mapTypeFamilies, Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns, PrintStream printStream) 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())) { FijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } // If this map family of counters has been qualified, print only the given columns. } else { for (String key : entry.getValue()) { FijiCell<Long> counter = row.getMostRecentCell(family.getName(), key); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } } } 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()); 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(), printStream); } } // 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); for (Entry<Long, Object> timestampedCell : timeseriesMap.entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, family.getName(), key, timestampedCell.getValue(), printStream); } } } } } // 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 FijiColumnName colName = FijiColumnName.create(familyName, column.getName()); if (column.getDesc().getColumnSchema().getType() == SchemaType.COUNTER) { final FijiCell<Long> counter = row.getMostRecentCell(colName.getFamily(), colName.getQualifier()); if (null != counter) { printCell(row.getEntityId(), counter, printStream); } } else { for (Entry<Long, Object> timestampedCell : row .getValues(colName.getFamily(), colName.getQualifier()).entrySet()) { long timestamp = timestampedCell.getKey(); printCell(row.getEntityId(), timestamp, colName.getFamily(), colName.getQualifier(), timestampedCell.getValue(), printStream); } } } } printStream.println(""); }
From source file:org.trustedanalytics.examples.hbase.services.ConversionsService.java
private List<ColumnValue> constructColumnValues(NavigableMap<byte[], byte[]> map) { List<ColumnValue> result = null; result = map.entrySet().stream().map(i -> new ColumnValue(new String(i.getKey()), new String(i.getValue()))) .collect(Collectors.toList()); return result; }
From source file:org.trend.hgraph.util.MoveEntities.java
private static void moveEntities(String f, Configuration conf, String st, String dt) throws IOException { Reader fr = null;// ww w.j av a2s . c o m LineIterator it = null; String key = null; HTable sTable = null; HTable dTable = null; try { fr = new FileReader(f); } catch (FileNotFoundException e) { System.err.println("file:" + f + " does not exist"); e.printStackTrace(System.err); throw e; } try { it = IOUtils.lineIterator(fr); if (it.hasNext()) { sTable = new HTable(conf, st); dTable = new HTable(conf, dt); Get get = null; Put put = null; Result r = null; byte[] bKey = null; byte[] cf = null; byte[] cq = null; byte[] v = null; NavigableMap<byte[], NavigableMap<byte[], byte[]>> cfMap = null; NavigableMap<byte[], byte[]> cqMap = null; Entry<byte[], NavigableMap<byte[], byte[]>> cfEntry = null; Entry<byte[], byte[]> cqEntry = null; long cnt = 0L; while (it.hasNext()) { key = it.next(); bKey = Bytes.toBytes(key); get = new Get(bKey); r = sTable.get(get); if (r.isEmpty()) { String msg = "result is empty for key:" + key + " from table:" + sTable; System.err.println(msg); throw new IllegalStateException(msg); } // dump the values from r to p put = new Put(bKey); cfMap = r.getNoVersionMap(); for (Iterator<Entry<byte[], NavigableMap<byte[], byte[]>>> cfIt = cfMap.entrySet() .iterator(); cfIt.hasNext();) { cfEntry = cfIt.next(); cf = cfEntry.getKey(); cqMap = cfEntry.getValue(); for (Iterator<Entry<byte[], byte[]>> cqIt = cqMap.entrySet().iterator(); cqIt.hasNext();) { cqEntry = cqIt.next(); cq = cqEntry.getKey(); v = cqEntry.getValue(); put.add(cf, cq, v); } } dTable.put(put); cnt++; } System.out.println("put " + cnt + " row(s) into table:" + dt); } } catch (IOException e) { System.err.println("error occurs while doing HBase manipultations !!"); e.printStackTrace(System.err); throw e; } finally { LineIterator.closeQuietly(it); IOUtils.closeQuietly(fr); if (null != sTable) { sTable.close(); } if (null != dTable) { dTable.close(); } } }