Search in sources :

Example 46 with NavigableMap

use of java.util.NavigableMap in project mapdb by jankotek.

the class TreeSubMapTest method testKeySetOrder.

/**
     * keySet is ordered
     */
public void testKeySetOrder() {
    NavigableMap map = map5();
    Set s = map.keySet();
    Iterator i = s.iterator();
    Integer last = (Integer) i.next();
    assertEquals(last, one);
    while (i.hasNext()) {
        Integer k = (Integer) i.next();
        assertTrue(last.compareTo(k) < 0);
        last = k;
    }
}
Also used : Set(java.util.Set) NavigableMap(java.util.NavigableMap) Iterator(java.util.Iterator)

Example 47 with NavigableMap

use of java.util.NavigableMap in project mapdb by jankotek.

the class TreeSubMapTest method testDescendingDescendingKeySetToArray.

/**
     * descendingkeySet.toArray returns contains all keys
     */
public void testDescendingDescendingKeySetToArray() {
    NavigableMap map = dmap5();
    Set s = map.descendingKeySet();
    Object[] ar = s.toArray();
    assertEquals(5, ar.length);
    assertTrue(s.containsAll(Arrays.asList(ar)));
    ar[0] = m10;
    assertFalse(s.containsAll(Arrays.asList(ar)));
}
Also used : Set(java.util.Set) NavigableMap(java.util.NavigableMap)

Example 48 with NavigableMap

use of java.util.NavigableMap in project mapdb by jankotek.

the class TreeSubMapTest method testDescendingGet_NullPointerException.

// Exception testDescendings
/**
     * get(null) of nonempty map throws NPE
     */
public void testDescendingGet_NullPointerException() {
    NavigableMap c = dmap5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : NavigableMap(java.util.NavigableMap)

Example 49 with NavigableMap

use of java.util.NavigableMap in project hadoop by apache.

the class TimelineEntityReader method readMetrics.

/**
   * Helper method for reading and deserializing {@link TimelineMetric} objects
   * using the specified column prefix. The timeline metrics then are added to
   * the given timeline entity.
   *
   * @param entity {@link TimelineEntity} object.
   * @param result {@link Result} object retrieved from backend.
   * @param columnPrefix Metric column prefix
   * @throws IOException if any exception is encountered while reading metrics.
   */
protected void readMetrics(TimelineEntity entity, Result result, ColumnPrefix<?> columnPrefix) throws IOException {
    NavigableMap<String, NavigableMap<Long, Number>> metricsResult = columnPrefix.readResultsWithTimestamps(result, stringKeyConverter);
    for (Map.Entry<String, NavigableMap<Long, Number>> metricResult : metricsResult.entrySet()) {
        TimelineMetric metric = new TimelineMetric();
        metric.setId(metricResult.getKey());
        // Simply assume that if the value set contains more than 1 elements, the
        // metric is a TIME_SERIES metric, otherwise, it's a SINGLE_VALUE metric
        TimelineMetric.Type metricType = metricResult.getValue().size() > 1 ? TimelineMetric.Type.TIME_SERIES : TimelineMetric.Type.SINGLE_VALUE;
        metric.setType(metricType);
        metric.addValues(metricResult.getValue());
        entity.addMetric(metric);
    }
}
Also used : TimelineMetric(org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap)

Example 50 with NavigableMap

use of java.util.NavigableMap in project hadoop by apache.

the class FlowRunCoprocessor method prePut.

/*
   * (non-Javadoc)
   *
   * This method adds the tags onto the cells in the Put. It is presumed that
   * all the cells in one Put have the same set of Tags. The existing cell
   * timestamp is overwritten for non-metric cells and each such cell gets a new
   * unique timestamp generated by {@link TimestampGenerator}
   *
   * @see
   * org.apache.hadoop.hbase.coprocessor.BaseRegionObserver#prePut(org.apache
   * .hadoop.hbase.coprocessor.ObserverContext,
   * org.apache.hadoop.hbase.client.Put,
   * org.apache.hadoop.hbase.regionserver.wal.WALEdit,
   * org.apache.hadoop.hbase.client.Durability)
   */
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException {
    Map<String, byte[]> attributes = put.getAttributesMap();
    if (!isFlowRunRegion) {
        return;
    }
    // Assumption is that all the cells in a put are the same operation.
    List<Tag> tags = new ArrayList<>();
    if ((attributes != null) && (attributes.size() > 0)) {
        for (Map.Entry<String, byte[]> attribute : attributes.entrySet()) {
            Tag t = HBaseTimelineStorageUtils.getTagFromAttribute(attribute);
            tags.add(t);
        }
        byte[] tagByteArray = Tag.fromList(tags);
        NavigableMap<byte[], List<Cell>> newFamilyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR);
        for (Map.Entry<byte[], List<Cell>> entry : put.getFamilyCellMap().entrySet()) {
            List<Cell> newCells = new ArrayList<>(entry.getValue().size());
            for (Cell cell : entry.getValue()) {
                // for each cell in the put add the tags
                // Assumption is that all the cells in
                // one put are the same operation
                // also, get a unique cell timestamp for non-metric cells
                // this way we don't inadvertently overwrite cell versions
                long cellTimestamp = getCellTimestamp(cell.getTimestamp(), tags);
                newCells.add(CellUtil.createCell(CellUtil.cloneRow(cell), CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell), cellTimestamp, KeyValue.Type.Put, CellUtil.cloneValue(cell), tagByteArray));
            }
            newFamilyMap.put(entry.getKey(), newCells);
        }
        // for each entry
        // Update the family map for the Put
        put.setFamilyCellMap(newFamilyMap);
    }
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ArrayList(java.util.ArrayList) List(java.util.List) Tag(org.apache.hadoop.hbase.Tag) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

NavigableMap (java.util.NavigableMap)173 Map (java.util.Map)85 TreeMap (java.util.TreeMap)62 SortedMap (java.util.SortedMap)35 ArrayList (java.util.ArrayList)34 List (java.util.List)27 HashMap (java.util.HashMap)21 Iterator (java.util.Iterator)21 Cell (org.apache.hadoop.hbase.Cell)20 Result (org.apache.hadoop.hbase.client.Result)19 Set (java.util.Set)14 Get (org.apache.hadoop.hbase.client.Get)14 IOException (java.io.IOException)12 KeyValue (org.apache.hadoop.hbase.KeyValue)11 Test (org.junit.Test)11 Put (org.apache.hadoop.hbase.client.Put)10 Entry (java.util.Map.Entry)9 Update (co.cask.cdap.data2.dataset2.lib.table.Update)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 TestSuite (junit.framework.TestSuite)7