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());
}
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);
}
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);
}
}
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)));
}
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;
}
Aggregations