Package org.apache.accumulo.core.data

Examples of org.apache.accumulo.core.data.Key


         
          for (int i = 0; i < getsPerThread; i++) {
            String row = String.format("r%08d", r.nextInt(mapSizePerThread));
            String val = row + "v";
           
            Value value = nm.get(new Key(new Text(row)));
            if (value == null || !value.toString().equals(val)) {
              log.error("nm.get(" + row + ") failed");
            }
          }
         
          opTimer.stop("Finished " + getsPerThread + " gets in %DURATION%");
         
          int scanned = 0;
         
          opTimer.start("Doing " + getsPerThread + " random iterations");
         
          for (int i = 0; i < getsPerThread; i++) {
            int startRow = r.nextInt(mapSizePerThread);
            String row = String.format("r%08d", startRow);
           
            Iterator<Entry<Key,Value>> iter = nm.iterator(new Key(new Text(row)));
           
            int count = 0;
           
            while (iter.hasNext() && count < 10) {
              String row2 = String.format("r%08d", startRow + count);
              String val2 = row2 + "v";
             
              Entry<Key,Value> entry = iter.next();
              if (!entry.getValue().toString().equals(val2) || !entry.getKey().equals(new Key(new Text(row2)))) {
                log.error("nm.iter(" + row2 + ") failed row = " + row + " count = " + count + " row2 = " + row + " val2 = " + val2);
              }
             
              count++;
            }
View Full Code Here


public class WholeRowIteratorTest {

  @Test(expected=IOException.class)
  public void testBadDecodeRow() throws IOException {
    Key k = new Key(new Text("r1"), new Text("cf1234567890"));
    Value v = new Value("v1".getBytes());
    Value encoded = WholeRowIterator.encodeRow(ImmutableList.of(k), ImmutableList.of(v));
    encoded.set(Arrays.copyOfRange(encoded.get(), 0, 10)); // truncate to 10 bytes only
    WholeRowIterator.decodeRow(k, encoded);
  }
View Full Code Here

  @Test
  public void testEmptyStuff() throws IOException {
    SortedMap<Key,Value> map = new TreeMap<Key,Value>();
    SortedMap<Key,Value> map2 = new TreeMap<Key,Value>();
    final Map<Text,Boolean> toInclude = new HashMap<Text,Boolean>();
    map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 1l), new Value("val1".getBytes()));
    map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2l), new Value("val2".getBytes()));
    map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3l), new Value("val3".getBytes()));
    map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4l), new Value("val4".getBytes()));
    map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5l), new Value("val4".getBytes()));
    map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6l), new Value("val4".getBytes()));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7l), new Value("".getBytes()));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8l), new Value("val1".getBytes()));
    map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9l), new Value("val1".getBytes()));
    map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10l), new Value("val1".getBytes()));
    map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11l), new Value("val1".getBytes()));
    boolean b = true;
    int trueCount = 0;
    for (Key k : map.keySet()) {
      if (toInclude.containsKey(k.getRow())) {
        if (toInclude.get(k.getRow())) {
          map2.put(k, map.get(k));
        }
        continue;
      }
      b = !b;
      toInclude.put(k.getRow(), b);
      if (b) {
        trueCount++;
        map2.put(k, map.get(k));
      }
    }
    SortedMapIterator source = new SortedMapIterator(map);
    WholeRowIterator iter = new WholeRowIterator(source);
    SortedMap<Key,Value> resultMap = new TreeMap<Key,Value>();
    iter.seek(new Range(), new ArrayList<ByteSequence>(), false);
    int numRows = 0;
    while (iter.hasTop()) {
      numRows++;
      Key rowKey = iter.getTopKey();
      Value rowValue = iter.getTopValue();
      resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
      iter.next();
    }
    assertTrue(numRows == 5);
    assertEquals(resultMap, map);
   
    WholeRowIterator iter2 = new WholeRowIterator(source) {
      @Override
      public boolean filter(Text row, List<Key> keys, List<Value> values) {
        return toInclude.get(row);
      }
    };
    resultMap.clear();
    iter2.seek(new Range(), new ArrayList<ByteSequence>(), false);
    numRows = 0;
    while (iter2.hasTop()) {
      numRows++;
      Key rowKey = iter2.getTopKey();
      Value rowValue = iter2.getTopValue();
      resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
      iter2.next();
    }
    assertTrue(numRows == trueCount);
View Full Code Here

    assertTrue(numRows == trueCount);
    assertEquals(resultMap, map2);
  }
 
  private void pkv(SortedMap<Key,Value> map, String row, String cf, String cq, String cv, long ts, String val) {
    map.put(new Key(new Text(row), new Text(cf), new Text(cq), new Text(cv), ts), new Value(val.getBytes()));
  }
View Full Code Here

    } else {
      entries = new TreeMap<Key,Value>();
      Text rowName = extent.getMetadataEntry();
      for (Entry<Key,Value> entry : tabletsKeyValues.entrySet()) {
        if (entry.getKey().compareRow(rowName) == 0 && Constants.METADATA_TIME_COLUMN.hasColumns(entry.getKey())) {
          entries.put(new Key(entry.getKey()), new Value(entry.getValue()));
        }
      }
    }
   
    // log.debug("extent : "+extent+"   entries : "+entries);
View Full Code Here

       
        if (entry.getKey().compareRow(rowName) != 0) {
          break;
        }
       
        datafilesMetadata.put(new Key(entry.getKey()), new Value(entry.getValue()));
      }
     
      Iterator<Entry<Key,Value>> dfmdIter = datafilesMetadata.entrySet().iterator();
     
      while (dfmdIter.hasNext()) {
View Full Code Here

      }
    } else {
      log.debug("Looking at metadata " + tabletsKeyValues);
      Text row = ke.getMetadataEntry();
      for (Entry<Key,Value> entry : tabletsKeyValues.entrySet()) {
        Key key = entry.getKey();
        if (key.getRow().equals(row)) {
          if (key.getColumnFamily().equals(Constants.METADATA_LOG_COLUMN_FAMILY)) {
            logEntries.add(MetadataTable.entryFromKeyValue(key, entry.getValue()));
          }
        }
      }
    }
View Full Code Here

    imm.mutate(Collections.singletonList(m));
  }
 
  static Key nk(String row, String column, long ts) {
    String[] sa = column.split(":");
    Key k = new Key(new Text(row), new Text(sa[0]), new Text(sa[1]), ts);
    return k;
  }
View Full Code Here

public class RangeInputSplitTest {

  @Test
  public void testSimpleWritable() throws IOException {
    RangeInputSplit split = new RangeInputSplit(new Range(new Key("a"), new Key("b")), new String[]{"localhost"});
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    split.write(dos);
   
View Full Code Here

    Assert.assertTrue(Arrays.equals(split.getLocations(), newSplit.getLocations()));
  }

  @Test
  public void testAllFieldsWritable() throws IOException {
    RangeInputSplit split = new RangeInputSplit(new Range(new Key("a"), new Key("b")), new String[]{"localhost"});
   
    Set<Pair<Text,Text>> fetchedColumns = new HashSet<Pair<Text,Text>>();
   
    fetchedColumns.add(new Pair<Text,Text>(new Text("colf1"), new Text("colq1")));
    fetchedColumns.add(new Pair<Text,Text>(new Text("colf2"), new Text("colq2")));
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.data.Key

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.