Search in sources :

Example 91 with NavigableSet

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

the class TreeSubSetTest method testCeiling.

/**
     * ceiling returns next element
     */
public void testCeiling() {
    NavigableSet q = set5();
    Object e1 = q.ceiling(three);
    assertEquals(three, e1);
    Object e2 = q.ceiling(zero);
    assertEquals(one, e2);
    Object e3 = q.ceiling(five);
    assertEquals(five, e3);
    Object e4 = q.ceiling(six);
    assertNull(e4);
}
Also used : NavigableSet(java.util.NavigableSet)

Example 92 with NavigableSet

use of java.util.NavigableSet in project hbase by apache.

the class ProtobufUtil method toGet.

/**
   * Create a protocol buffer Get based on a client Get.
   *
   * @param get the client Get
   * @return a protocol buffer Get
   * @throws IOException
   */
public static ClientProtos.Get toGet(final Get get) throws IOException {
    ClientProtos.Get.Builder builder = ClientProtos.Get.newBuilder();
    builder.setRow(ByteStringer.wrap(get.getRow()));
    builder.setCacheBlocks(get.getCacheBlocks());
    builder.setMaxVersions(get.getMaxVersions());
    if (get.getFilter() != null) {
        builder.setFilter(ProtobufUtil.toFilter(get.getFilter()));
    }
    for (Entry<byte[], TimeRange> cftr : get.getColumnFamilyTimeRange().entrySet()) {
        HBaseProtos.ColumnFamilyTimeRange.Builder b = HBaseProtos.ColumnFamilyTimeRange.newBuilder();
        b.setColumnFamily(ByteStringer.wrap(cftr.getKey()));
        b.setTimeRange(timeRangeToProto(cftr.getValue()));
        builder.addCfTimeRange(b);
    }
    TimeRange timeRange = get.getTimeRange();
    if (!timeRange.isAllTime()) {
        HBaseProtos.TimeRange.Builder timeRangeBuilder = HBaseProtos.TimeRange.newBuilder();
        timeRangeBuilder.setFrom(timeRange.getMin());
        timeRangeBuilder.setTo(timeRange.getMax());
        builder.setTimeRange(timeRangeBuilder.build());
    }
    Map<String, byte[]> attributes = get.getAttributesMap();
    if (!attributes.isEmpty()) {
        NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
        for (Map.Entry<String, byte[]> attribute : attributes.entrySet()) {
            attributeBuilder.setName(attribute.getKey());
            attributeBuilder.setValue(ByteStringer.wrap(attribute.getValue()));
            builder.addAttribute(attributeBuilder.build());
        }
    }
    if (get.hasFamilies()) {
        Column.Builder columnBuilder = Column.newBuilder();
        Map<byte[], NavigableSet<byte[]>> families = get.getFamilyMap();
        for (Map.Entry<byte[], NavigableSet<byte[]>> family : families.entrySet()) {
            NavigableSet<byte[]> qualifiers = family.getValue();
            columnBuilder.setFamily(ByteStringer.wrap(family.getKey()));
            columnBuilder.clearQualifier();
            if (qualifiers != null && qualifiers.size() > 0) {
                for (byte[] qualifier : qualifiers) {
                    columnBuilder.addQualifier(ByteStringer.wrap(qualifier));
                }
            }
            builder.addColumn(columnBuilder.build());
        }
    }
    if (get.getMaxResultsPerColumnFamily() >= 0) {
        builder.setStoreLimit(get.getMaxResultsPerColumnFamily());
    }
    if (get.getRowOffsetPerColumnFamily() > 0) {
        builder.setStoreOffset(get.getRowOffsetPerColumnFamily());
    }
    if (get.isCheckExistenceOnly()) {
        builder.setExistenceOnly(true);
    }
    if (get.getConsistency() != null && get.getConsistency() != Consistency.STRONG) {
        builder.setConsistency(toConsistency(get.getConsistency()));
    }
    Boolean loadColumnFamiliesOnDemand = get.getLoadColumnFamiliesOnDemandValue();
    if (loadColumnFamiliesOnDemand != null) {
        builder.setLoadColumnFamiliesOnDemand(loadColumnFamiliesOnDemand);
    }
    return builder.build();
}
Also used : NavigableSet(java.util.NavigableSet) ByteString(com.google.protobuf.ByteString) TimeRange(org.apache.hadoop.hbase.io.TimeRange) NameBytesPair(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair) Column(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Column) Get(org.apache.hadoop.hbase.client.Get) Map(java.util.Map) HashMap(java.util.HashMap)

Example 93 with NavigableSet

use of java.util.NavigableSet in project hbase by apache.

the class TestSerialization method testGet.

/*
   * TODO
  @Test public void testPut() throws Exception{
    byte[] row = "row".getBytes();
    byte[] fam = "fam".getBytes();
    byte[] qf1 = "qf1".getBytes();
    byte[] qf2 = "qf2".getBytes();
    byte[] qf3 = "qf3".getBytes();
    byte[] qf4 = "qf4".getBytes();
    byte[] qf5 = "qf5".getBytes();
    byte[] qf6 = "qf6".getBytes();
    byte[] qf7 = "qf7".getBytes();
    byte[] qf8 = "qf8".getBytes();

    long ts = System.currentTimeMillis();
    byte[] val = "val".getBytes();

    Put put = new Put(row);
    put.setWriteToWAL(false);
    put.add(fam, qf1, ts, val);
    put.add(fam, qf2, ts, val);
    put.add(fam, qf3, ts, val);
    put.add(fam, qf4, ts, val);
    put.add(fam, qf5, ts, val);
    put.add(fam, qf6, ts, val);
    put.add(fam, qf7, ts, val);
    put.add(fam, qf8, ts, val);

    byte[] sb = Writables.getBytes(put);
    Put desPut = (Put)Writables.getWritable(sb, new Put());

    //Timing test
//    long start = System.nanoTime();
//    desPut = (Put)Writables.getWritable(sb, new Put());
//    long stop = System.nanoTime();
//    System.out.println("timer " +(stop-start));

    assertTrue(Bytes.equals(put.getRow(), desPut.getRow()));
    List<KeyValue> list = null;
    List<KeyValue> desList = null;
    for(Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()){
      assertTrue(desPut.getFamilyMap().containsKey(entry.getKey()));
      list = entry.getValue();
      desList = desPut.getFamilyMap().get(entry.getKey());
      for(int i=0; i<list.size(); i++){
        assertTrue(list.get(i).equals(desList.get(i)));
      }
    }
  }


  @Test public void testPut2() throws Exception{
    byte[] row = "testAbort,,1243116656250".getBytes();
    byte[] fam = "historian".getBytes();
    byte[] qf1 = "creation".getBytes();

    long ts = 9223372036854775807L;
    byte[] val = "dont-care".getBytes();

    Put put = new Put(row);
    put.add(fam, qf1, ts, val);

    byte[] sb = Writables.getBytes(put);
    Put desPut = (Put)Writables.getWritable(sb, new Put());

    assertTrue(Bytes.equals(put.getRow(), desPut.getRow()));
    List<KeyValue> list = null;
    List<KeyValue> desList = null;
    for(Map.Entry<byte[], List<KeyValue>> entry : put.getFamilyMap().entrySet()){
      assertTrue(desPut.getFamilyMap().containsKey(entry.getKey()));
      list = entry.getValue();
      desList = desPut.getFamilyMap().get(entry.getKey());
      for(int i=0; i<list.size(); i++){
        assertTrue(list.get(i).equals(desList.get(i)));
      }
    }
  }


  @Test public void testDelete() throws Exception{
    byte[] row = "row".getBytes();
    byte[] fam = "fam".getBytes();
    byte[] qf1 = "qf1".getBytes();

    long ts = System.currentTimeMillis();

    Delete delete = new Delete(row);
    delete.deleteColumn(fam, qf1, ts);

    byte[] sb = Writables.getBytes(delete);
    Delete desDelete = (Delete)Writables.getWritable(sb, new Delete());

    assertTrue(Bytes.equals(delete.getRow(), desDelete.getRow()));
    List<KeyValue> list = null;
    List<KeyValue> desList = null;
    for(Map.Entry<byte[], List<KeyValue>> entry :
        delete.getFamilyMap().entrySet()){
      assertTrue(desDelete.getFamilyMap().containsKey(entry.getKey()));
      list = entry.getValue();
      desList = desDelete.getFamilyMap().get(entry.getKey());
      for(int i=0; i<list.size(); i++){
        assertTrue(list.get(i).equals(desList.get(i)));
      }
    }
  }
  */
@Test
public void testGet() throws Exception {
    byte[] row = "row".getBytes();
    byte[] fam = "fam".getBytes();
    byte[] qf1 = "qf1".getBytes();
    long ts = System.currentTimeMillis();
    int maxVersions = 2;
    Get get = new Get(row);
    get.addColumn(fam, qf1);
    get.setTimeRange(ts, ts + 1);
    get.setMaxVersions(maxVersions);
    ClientProtos.Get getProto = ProtobufUtil.toGet(get);
    Get desGet = ProtobufUtil.toGet(getProto);
    assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
    Set<byte[]> set = null;
    Set<byte[]> desSet = null;
    for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap().entrySet()) {
        assertTrue(desGet.getFamilyMap().containsKey(entry.getKey()));
        set = entry.getValue();
        desSet = desGet.getFamilyMap().get(entry.getKey());
        for (byte[] qualifier : set) {
            assertTrue(desSet.contains(qualifier));
        }
    }
    assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
    TimeRange tr = get.getTimeRange();
    TimeRange desTr = desGet.getTimeRange();
    assertEquals(tr.getMax(), desTr.getMax());
    assertEquals(tr.getMin(), desTr.getMin());
}
Also used : TimeRange(org.apache.hadoop.hbase.io.TimeRange) NavigableSet(java.util.NavigableSet) Get(org.apache.hadoop.hbase.client.Get) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) Map(java.util.Map) Test(org.junit.Test)

Example 94 with NavigableSet

use of java.util.NavigableSet in project voltdb by VoltDB.

the class PrepareShutdown method executePlanFragment.

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
    if (fragmentId == PF_prepareShutdown) {
        super.run(context);
        VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
        if (context.isLowestSiteId()) {
            VoltDB.instance().setShuttingdown(true);
            t.addRow(m_stat.getMzxid());
            if (LOG.isDebugEnabled()) {
                LOG.debug("@PrepareShutdown returning sigil " + ll(m_stat.getMzxid()));
            }
        }
        return new DependencyPair.TableDependencyPair(DEP_prepareShutdown, t);
    } else if (fragmentId == PF_prepareShutdownAggregate) {
        NavigableSet<Long> uniqueTxnIds = new TreeSet<>();
        for (VoltTable t : dependencies.get(DEP_prepareShutdown)) {
            while (t.advanceRow()) {
                uniqueTxnIds.add(t.getLong(0));
            }
        }
        VoltTable t = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
        for (long zktxnid : uniqueTxnIds) {
            t.addRow(zktxnid);
        }
        return new DependencyPair.TableDependencyPair(DEP_prepareShutdonwAggregate, t);
    } else {
        VoltDB.crashLocalVoltDB("Received unrecognized plan fragment id " + fragmentId + " in PrepareShutdown", false, null);
    }
    throw new RuntimeException("Should not reach this code");
}
Also used : NavigableSet(java.util.NavigableSet) VoltTable(org.voltdb.VoltTable) DependencyPair(org.voltdb.DependencyPair)

Example 95 with NavigableSet

use of java.util.NavigableSet in project voltdb by VoltDB.

the class TestCOWSortedMap method testKeySetDescendingIteratorOrder.

/**
     * descending iterator of key set is inverse ordered
     */
public void testKeySetDescendingIteratorOrder() {
    COWSortedMap map = map5();
    NavigableSet s = map.navigableKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer) i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer) i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator)

Aggregations

NavigableSet (java.util.NavigableSet)197 Iterator (java.util.Iterator)36 SortedSet (java.util.SortedSet)26 Map (java.util.Map)12 TreeSet (java.util.TreeSet)11 HashMap (java.util.HashMap)7 Set (java.util.Set)6 TimeRange (org.apache.hadoop.hbase.io.TimeRange)6 List (java.util.List)5 TestSuite (junit.framework.TestSuite)5 Scan (org.apache.hadoop.hbase.client.Scan)5 Test (org.testng.annotations.Test)5 ArrayList (java.util.ArrayList)4 TreeMap (java.util.TreeMap)4 HashSet (java.util.HashSet)3 Get (org.apache.hadoop.hbase.client.Get)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)2 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)2 ByteString (com.google.protobuf.ByteString)2