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

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

Introduction

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

Prototype

public void set(byte[] utf8, int start, int len) 

Source Link

Document

Set the Text to range of bytes

Usage

From source file:mvm.rya.indexing.accumulo.freetext.ColumnPrefixes.java

License:Apache License

public static Text removePrefix(Text termWithPrefix) {
    Text temp = new Text();
    temp.set(termWithPrefix.getBytes(), 2, termWithPrefix.getLength() - 2);
    return temp;//from w w w  .ja  v  a2s  . c  o m
}

From source file:net.iponweb.hadoop.streaming.avro.AvroAsTextRecordReaderCopy.java

License:Apache License

public boolean next(Text key, Text ignore) throws IOException {
    if (!reader.hasNext() || reader.pastSync(end))
        return false;
    datum = reader.next(datum);// w  ww  . j a  v a 2 s.com
    if (datum instanceof ByteBuffer) {
        ByteBuffer b = (ByteBuffer) datum;
        if (b.hasArray()) {
            int offset = b.arrayOffset();
            int start = b.position();
            int length = b.remaining();
            key.set(b.array(), offset + start, offset + start + length);
        } else {
            byte[] bytes = new byte[b.remaining()];
            b.duplicate().get(bytes);
            key.set(bytes);
        }
    } else {
        key.set(GenericData0.INSTANCE.toString(datum));
    }
    return true;
}

From source file:org.apache.accumulo.core.client.admin.FindMax.java

License:Apache License

private static Text findMidPoint(Text minBS, Text maxBS) {
    ByteArrayOutputStream startOS = new ByteArrayOutputStream();
    startOS.write(0); // add a leading zero so bigint does not think its negative
    startOS.write(minBS.getBytes(), 0, minBS.getLength());

    ByteArrayOutputStream endOS = new ByteArrayOutputStream();
    endOS.write(0);// add a leading zero so bigint does not think its negative
    endOS.write(maxBS.getBytes(), 0, maxBS.getLength());

    // make the numbers of the same magnitude
    if (startOS.size() < endOS.size())
        appendZeros(startOS, endOS.size() - startOS.size());
    else if (endOS.size() < startOS.size())
        appendZeros(endOS, startOS.size() - endOS.size());

    BigInteger min = new BigInteger(startOS.toByteArray());
    BigInteger max = new BigInteger(endOS.toByteArray());

    BigInteger mid = max.subtract(min).divide(BigInteger.valueOf(2)).add(min);

    byte[] ba = mid.toByteArray();

    Text ret = new Text();

    if (ba.length == startOS.size()) {
        if (ba[0] != 0)
            throw new RuntimeException();

        // big int added a zero so it would not be negative, drop it
        ret.set(ba, 1, ba.length - 1);
    } else {/*  w  w w.  ja  v a2  s. c  o m*/
        int expLen = Math.max(minBS.getLength(), maxBS.getLength());
        // big int will drop leading 0x0 bytes
        for (int i = ba.length; i < expLen; i++) {
            ret.append(new byte[] { 0 }, 0, 1);
        }

        ret.append(ba, 0, ba.length);
    }

    // remove trailing 0x0 bytes
    while (ret.getLength() > 0 && ret.getBytes()[ret.getLength() - 1] == 0 && ret.compareTo(minBS) > 0) {
        Text t = new Text();
        t.set(ret.getBytes(), 0, ret.getLength() - 1);
        ret = t;
    }

    return ret;
}

From source file:org.apache.accumulo.core.client.lexicoder.TextLexicoder.java

License:Apache License

@Override
protected Text decodeUnchecked(byte[] data, int offset, int len) {
    Text text = new Text();
    text.set(data, offset, len);
    return text;/*from  w  ww. j  av a  2  s  .com*/
}

From source file:org.apache.accumulo.core.data.impl.KeyExtent.java

License:Apache License

public static Text decodePrevEndRow(Value ibw) {
    Text per = null;

    if (ibw.get()[0] != 0) {
        per = new Text();
        per.set(ibw.get(), 1, ibw.get().length - 1);
    }/*from  w  ww  . j av  a2  s.  co  m*/

    return per;
}

From source file:org.apache.accumulo.core.data.impl.KeyExtent.java

License:Apache License

/**
 * Populates the extent's fields based on a flatted extent
 *
 *///from w w  w.  j a  v a2  s .  c o m
private void decodeMetadataRow(Text flattenedExtent) {
    int semiPos = -1;
    int ltPos = -1;

    for (int i = 0; i < flattenedExtent.getLength(); i++) {
        if (flattenedExtent.getBytes()[i] == ';' && semiPos < 0) {
            // want the position of the first semicolon
            semiPos = i;
        }

        if (flattenedExtent.getBytes()[i] == '<') {
            ltPos = i;
        }
    }

    if (semiPos < 0 && ltPos < 0) {
        throw new IllegalArgumentException("Metadata row does not contain ; or <  " + flattenedExtent);
    }

    if (semiPos < 0) {

        if (ltPos != flattenedExtent.getLength() - 1) {
            throw new IllegalArgumentException("< must come at end of Metadata row  " + flattenedExtent);
        }

        String tableId = new String(flattenedExtent.getBytes(), 0, flattenedExtent.getLength() - 1, UTF_8);
        this.setTableId(tableId);
        this.setEndRow(null, false, false);
    } else {

        String tableId = new String(flattenedExtent.getBytes(), 0, semiPos, UTF_8);

        Text endRow = new Text();
        endRow.set(flattenedExtent.getBytes(), semiPos + 1, flattenedExtent.getLength() - (semiPos + 1));

        this.setTableId(tableId);

        this.setEndRow(endRow, false, false);
    }
}

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

License:Apache License

/**
 * Writes the row ID into the given <code>Text</code>. This method gives users control over allocation of Text objects by copying into the passed in text.
 *
 * @param r//w  w  w.java  2s . c om
 *          <code>Text</code> object to copy into
 * @return the <code>Text</code> that was passed in
 */
public Text getRow(Text r) {
    r.set(row, 0, row.length);
    return r;
}

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

License:Apache License

/**
 * Writes the column family into the given <code>Text</code>. This method gives users control over allocation of Text objects by copying into the passed in
 * text./*w w w .j av  a  2 s. c  o m*/
 *
 * @param cf
 *          <code>Text</code> object to copy into
 * @return the <code>Text</code> that was passed in
 */
public Text getColumnFamily(Text cf) {
    cf.set(colFamily, 0, colFamily.length);
    return cf;
}

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

License:Apache License

/**
 * Writes the column qualifier into the given <code>Text</code>. This method gives users control over allocation of Text objects by copying into the passed in
 * text./*from   w ww .  j av a2  s  . c  o m*/
 *
 * @param cq
 *          <code>Text</code> object to copy into
 * @return the <code>Text</code> that was passed in
 */
public Text getColumnQualifier(Text cq) {
    cq.set(colQualifier, 0, colQualifier.length);
    return cq;
}

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

License:Apache License

/**
 * Writes the column visibvility into the given <code>Text</code>. This method gives users control over allocation of Text objects by copying into the passed
 * in text./*w ww.ja  v a 2  s .c o m*/
 *
 * @param cv
 *          <code>Text</code> object to copy into
 * @return the <code>Text</code> that was passed in
 */
public final Text getColumnVisibility(Text cv) {
    cv.set(colVisibility, 0, colVisibility.length);
    return cv;
}