Search in sources :

Example 6 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class ColumnFamilySkippingIteratorTest method test1.

public void test1() throws Exception {
    TreeMap<Key, Value> tm1 = new TreeMap<>();
    put(tm1, "r1", "cf1", "cq1", 5, "v1");
    put(tm1, "r1", "cf1", "cq3", 5, "v2");
    put(tm1, "r2", "cf1", "cq1", 5, "v3");
    put(tm1, "r2", "cf2", "cq4", 5, "v4");
    put(tm1, "r2", "cf2", "cq5", 5, "v5");
    put(tm1, "r3", "cf3", "cq6", 5, "v6");
    ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1));
    cfi.seek(new Range(), EMPTY_SET, true);
    assertFalse(cfi.hasTop());
    cfi.seek(new Range(), EMPTY_SET, false);
    assertTrue(cfi.hasTop());
    TreeMap<Key, Value> tm2 = new TreeMap<>();
    while (cfi.hasTop()) {
        tm2.put(cfi.getTopKey(), cfi.getTopValue());
        cfi.next();
    }
    assertEquals(tm1, tm2);
    HashSet<ByteSequence> colfams = new HashSet<>();
    colfams.add(new ArrayByteSequence("cf2"));
    cfi.seek(new Range(), colfams, true);
    testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
    testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
    assertFalse(cfi.hasTop());
    colfams.add(new ArrayByteSequence("cf3"));
    colfams.add(new ArrayByteSequence("cf4"));
    cfi.seek(new Range(), colfams, true);
    testAndCallnext(cfi, "r2", "cf2", "cq4", 5, "v4");
    testAndCallnext(cfi, "r2", "cf2", "cq5", 5, "v5");
    testAndCallnext(cfi, "r3", "cf3", "cq6", 5, "v6");
    assertFalse(cfi.hasTop());
    cfi.seek(new Range(), colfams, false);
    testAndCallnext(cfi, "r1", "cf1", "cq1", 5, "v1");
    testAndCallnext(cfi, "r1", "cf1", "cq3", 5, "v2");
    testAndCallnext(cfi, "r2", "cf1", "cq1", 5, "v3");
    assertFalse(cfi.hasTop());
}
Also used : Value(org.apache.accumulo.core.data.Value) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) TreeMap(java.util.TreeMap) SortedMapIterator(org.apache.accumulo.core.iterators.SortedMapIterator) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 7 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class TransformingIteratorTest method checkExpected.

private void checkExpected(TreeMap<Key, Value> expectedEntries, String... fa) throws IOException {
    HashSet<ByteSequence> families = new HashSet<>();
    for (String family : fa) {
        families.add(new ArrayByteSequence(family));
    }
    checkExpected(new Range(), families, expectedEntries);
}
Also used : ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Range(org.apache.accumulo.core.data.Range) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) HashSet(java.util.HashSet)

Example 8 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class ByteBufferUtilTest method assertEquals.

private static void assertEquals(String expected, ByteBuffer bb) {
    Assert.assertEquals(new Text(expected), ByteBufferUtil.toText(bb));
    Assert.assertEquals(expected, new String(ByteBufferUtil.toBytes(bb), UTF_8));
    Assert.assertEquals(expected, ByteBufferUtil.toString(bb));
    List<byte[]> bal = ByteBufferUtil.toBytesList(Collections.singletonList(bb));
    Assert.assertEquals(1, bal.size());
    Assert.assertEquals(expected, new String(bal.get(0), UTF_8));
    Assert.assertEquals(new ArrayByteSequence(expected), new ArrayByteSequence(bb));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    try {
        ByteBufferUtil.write(dos, bb);
        dos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Assert.assertEquals(expected, new String(baos.toByteArray(), UTF_8));
    ByteArrayInputStream bais = ByteBufferUtil.toByteArrayInputStream(bb);
    byte[] buffer = new byte[expected.length()];
    try {
        bais.read(buffer);
        Assert.assertEquals(expected, new String(buffer, UTF_8));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Text(org.apache.hadoop.io.Text) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 9 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class PartitionerTest method test1.

@Test
public void test1() {
    PreAllocatedArray<Map<ByteSequence, MutableLong>> groups = new PreAllocatedArray<>(2);
    groups.set(0, new HashMap<>());
    groups.get(0).put(new ArrayByteSequence("cf1"), new MutableLong(1));
    groups.get(0).put(new ArrayByteSequence("cf2"), new MutableLong(1));
    groups.set(1, new HashMap<>());
    groups.get(1).put(new ArrayByteSequence("cf3"), new MutableLong(1));
    Partitioner p1 = new Partitioner(groups);
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", "v1");
    Mutation m2 = new Mutation("r2");
    m2.put("cf1", "cq1", "v2");
    m2.put("cf2", "cq2", "v3");
    Mutation m3 = new Mutation("r3");
    m3.put("cf1", "cq1", "v4");
    m3.put("cf3", "cq2", "v5");
    Mutation m4 = new Mutation("r4");
    m4.put("cf1", "cq1", "v6");
    m4.put("cf3", "cq2", "v7");
    m4.put("cf5", "cq3", "v8");
    Mutation m5 = new Mutation("r5");
    m5.put("cf5", "cq3", "v9");
    List<Mutation> mutations = Arrays.asList(m1, m2, m3, m4, m5);
    PreAllocatedArray<List<Mutation>> partitioned = new PreAllocatedArray<>(3);
    for (int i = 0; i < partitioned.length; i++) {
        partitioned.set(i, new ArrayList<>());
    }
    p1.partition(mutations, partitioned);
    m1 = new Mutation("r1");
    m1.put("cf1", "cq1", "v1");
    m2 = new Mutation("r2");
    m2.put("cf1", "cq1", "v2");
    m2.put("cf2", "cq2", "v3");
    m3 = new Mutation("r3");
    m3.put("cf1", "cq1", "v4");
    m4 = new Mutation("r4");
    m4.put("cf1", "cq1", "v6");
    Assert.assertEquals(toKeySet(m1, m2, m3, m4), toKeySet(partitioned.get(0)));
    m3 = new Mutation("r3");
    m3.put("cf3", "cq2", "v5");
    m4 = new Mutation("r4");
    m4.put("cf3", "cq2", "v7");
    Assert.assertEquals(toKeySet(m3, m4), toKeySet(partitioned.get(1)));
    m4 = new Mutation("r4");
    m4.put("cf5", "cq3", "v8");
    Assert.assertEquals(toKeySet(m4, m5), toKeySet(partitioned.get(2)));
}
Also used : MutableLong(org.apache.commons.lang.mutable.MutableLong) ArrayList(java.util.ArrayList) List(java.util.List) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Mutation(org.apache.accumulo.core.data.Mutation) HashMap(java.util.HashMap) Map(java.util.Map) Partitioner(org.apache.accumulo.core.util.LocalityGroupUtil.Partitioner) Test(org.junit.Test)

Example 10 with ArrayByteSequence

use of org.apache.accumulo.core.data.ArrayByteSequence in project accumulo by apache.

the class IndexedDocIterator method buildDocKey.

protected Key buildDocKey() {
    if (log.isTraceEnabled())
        log.trace("building doc key for {} {}", currentPartition, currentDocID);
    int zeroIndex = currentDocID.find("\0");
    if (zeroIndex < 0)
        throw new IllegalArgumentException("bad current docID");
    Text colf = new Text(docColf);
    colf.append(nullByte, 0, 1);
    colf.append(currentDocID.getBytes(), 0, zeroIndex);
    docColfSet = Collections.singleton(new ArrayByteSequence(colf.getBytes(), 0, colf.getLength()));
    if (log.isTraceEnabled())
        log.trace("{} {}", zeroIndex, currentDocID.getLength());
    Text colq = new Text();
    colq.set(currentDocID.getBytes(), zeroIndex + 1, currentDocID.getLength() - zeroIndex - 1);
    Key k = new Key(currentPartition, colf, colq);
    if (log.isTraceEnabled())
        log.trace("built doc key for seek: {}", k.toString());
    return k;
}
Also used : Text(org.apache.hadoop.io.Text) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)39 ByteSequence (org.apache.accumulo.core.data.ByteSequence)26 HashSet (java.util.HashSet)20 Test (org.junit.Test)18 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)9 Range (org.apache.accumulo.core.data.Range)8 ArrayList (java.util.ArrayList)7 TreeMap (java.util.TreeMap)6 SortedMapIterator (org.apache.accumulo.core.iterators.SortedMapIterator)5 Text (org.apache.hadoop.io.Text)5 HashMap (java.util.HashMap)4 ColumnFamilySkippingIterator (org.apache.accumulo.core.iterators.system.ColumnFamilySkippingIterator)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Scanner (org.apache.accumulo.core.client.Scanner)2 Mutation (org.apache.accumulo.core.data.Mutation)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 IterInfo (org.apache.accumulo.core.data.thrift.IterInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1