Example usage for org.apache.hadoop.io Text getLength

List of usage examples for org.apache.hadoop.io Text getLength

Introduction

In this page you can find the example usage for org.apache.hadoop.io Text getLength.

Prototype

@Override
public int getLength() 

Source Link

Document

Returns the number of bytes in the byte array

Usage

From source file:org.apache.accumulo.core.data.Key.java

License:Apache License

/**
 * Compares this key's row ID with another.
 *
 * @param r//from   w ww.  j  a  va  2 s . c o  m
 *          row ID to compare
 * @return same as {@link #getRow()}.compareTo(r)
 */
public int compareRow(Text r) {
    return WritableComparator.compareBytes(row, 0, row.length, r.getBytes(), 0, r.getLength());
}

From source file:org.apache.accumulo.core.data.Key.java

License:Apache License

/**
 * Compares this key's column family with another.
 *
 * @param cf//from ww w .  j  a va 2 s  .co  m
 *          column family to compare
 * @return same as {@link #getColumnFamily()}.compareTo(cf)
 */

public int compareColumnFamily(Text cf) {
    return WritableComparator.compareBytes(colFamily, 0, colFamily.length, cf.getBytes(), 0, cf.getLength());
}

From source file:org.apache.accumulo.core.data.Key.java

License:Apache License

/**
 * Compares this key's column qualifier with another.
 *
 * @param cq//w ww .ja  v  a  2s.  co  m
 *          column qualifier to compare
 * @return same as {@link #getColumnQualifier()}.compareTo(cq)
 */
public int compareColumnQualifier(Text cq) {
    return WritableComparator.compareBytes(colQualifier, 0, colQualifier.length, cq.getBytes(), 0,
            cq.getLength());
}

From source file:org.apache.accumulo.core.data.KeyBuilderTest.java

License:Apache License

@Test
public void testKeyHeterogeneous() {
    Key keyBuilt = Key.builder().row(rowText).family(familyBytes).qualifier("foo").build();
    Text fooText = new Text("foo");
    Key keyExpected = new Key(rowText.getBytes(), 0, rowText.getLength(), familyBytes, 0, familyBytes.length,
            fooText.getBytes(), 0, fooText.getLength(), EMPTY_BYTES, 0, 0, Long.MAX_VALUE);
    assertEquals(keyExpected, keyBuilt);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

/**
 * Creates a new mutation. A defensive copy is made.
 *
 * @param row//from  ww w .  ja v  a2s  .c o  m
 *          row ID
 */
public Mutation(Text row) {
    this(row.getBytes(), 0, row.getLength());
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

/**
 * Creates a new mutation. A defensive copy is made.
 *
 * @param row//from  w w w . j a v a 2  s.c  o m
 *          row ID
 * @param initialBufferSize
 *          the initial size, in bytes, of the internal buffer for serializing
 * @since 1.7.0
 */
public Mutation(Text row, int initialBufferSize) {
    this(row.getBytes(), 0, row.getLength(), initialBufferSize);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {
    put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val, val.length);
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, Text val) {
    put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val.getBytes(),
            val.getLength());
}

From source file:org.apache.accumulo.core.data.MutationTest.java

License:Apache License

@Test
public void testNewSerialization() throws Exception {
    // write an old mutation
    OldMutation m2 = new OldMutation("r1");
    m2.put("cf1", "cq1", "v1");
    m2.put("cf2", "cq2", new ColumnVisibility("cv2"), "v2");
    m2.putDelete("cf3", "cq3");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    m2.write(dos);//from   w w  w  .j a  va 2s  .co m
    dos.close();
    long oldSize = dos.size();
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    DataInputStream dis = new DataInputStream(bis);
    m2.readFields(dis);
    dis.close();

    // check it
    assertEquals("r1", new String(m2.getRow()));
    assertEquals(3, m2.getUpdates().size());
    assertEquals(3, m2.size());
    verifyColumnUpdate(m2.getUpdates().get(0), "cf1", "cq1", "", 0l, false, false, "v1");
    verifyColumnUpdate(m2.getUpdates().get(1), "cf2", "cq2", "cv2", 0l, false, false, "v2");
    verifyColumnUpdate(m2.getUpdates().get(2), "cf3", "cq3", "", 0l, false, true, "");

    Mutation m1 = convert(m2);

    assertEquals("r1", new String(m1.getRow()));
    assertEquals(3, m1.getUpdates().size());
    assertEquals(3, m1.size());
    verifyColumnUpdate(m1.getUpdates().get(0), "cf1", "cq1", "", 0l, false, false, "v1");
    verifyColumnUpdate(m1.getUpdates().get(1), "cf2", "cq2", "cv2", 0l, false, false, "v2");
    verifyColumnUpdate(m1.getUpdates().get(2), "cf3", "cq3", "", 0l, false, true, "");

    Text exampleRow = new Text(" 123456789 123456789 123456789 123456789 123456789");
    int exampleLen = exampleRow.getLength();
    m1 = new Mutation(exampleRow);
    m1.put("", "", "");

    bos = new ByteArrayOutputStream();
    dos = new DataOutputStream(bos);
    m1.write(dos);
    dos.close();
    long newSize = dos.size();
    assertTrue(newSize < oldSize);
    assertEquals(10, newSize - exampleLen);
    assertEquals(68, oldSize - exampleLen);
    // I am converting to integer to avoid comparing floats which are inaccurate
    assertEquals(14705, (int) (((newSize - exampleLen) * 100. / (oldSize - exampleLen)) * 1000));
    StringBuilder sb = new StringBuilder();
    byte[] ba = bos.toByteArray();
    for (int i = 0; i < bos.size(); i += 4) {
        for (int j = i; j < bos.size() && j < i + 4; j++) {
            sb.append(String.format("%02x", ba[j]));
        }
        sb.append(" ");
    }
    assertEquals(
            "80322031 32333435 36373839 20313233 34353637 38392031 32333435 36373839 20313233 34353637 38392031 32333435 36373839 06000000 00000001 ",
            sb.toString());

}

From source file:org.apache.accumulo.core.data.OldMutation.java

License:Apache License

public OldMutation(Text row) {
    this.row = new byte[row.getLength()];
    System.arraycopy(row.getBytes(), 0, this.row, 0, row.getLength());
    buffer = new ByteBuffer();
}