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

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

Introduction

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

Prototype

@Override
public byte[] getBytes() 

Source Link

Document

Returns the raw bytes; however, only data up to #getLength() is valid.

Usage

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

License:Apache License

private static Text findInitialEnd(Scanner scanner) {
    Text end = new Text(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });

    scanner.setRange(new Range(end, null));

    while (scanner.iterator().hasNext()) {
        Text t = new Text();
        t.append(end.getBytes(), 0, end.getLength());
        t.append(end.getBytes(), 0, end.getLength());
        end = t;/*from   w ww.  j  av  a  2s  .  c  o  m*/
        scanner.setRange(new Range(end, null));
    }

    return end;
}

From source file:org.apache.accumulo.core.client.impl.TabletLocatorImpl.java

License:Apache License

private void lookupTabletLocation(ClientContext context, Text row, boolean retry, LockCheckerSession lcSession)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    Text metadataRow = new Text(tableId);
    metadataRow.append(new byte[] { ';' }, 0, 1);
    metadataRow.append(row.getBytes(), 0, row.getLength());
    TabletLocation ptl = parent.locateTablet(context, metadataRow, false, retry);

    if (ptl != null) {
        TabletLocations locations = locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow,
                parent);/*from  w w  w.  jav  a2 s .  co m*/
        while (locations != null && locations.getLocations().isEmpty()
                && locations.getLocationless().isEmpty()) {
            // try the next tablet, the current tablet does not have any tablets that overlap the row
            Text er = ptl.tablet_extent.getEndRow();
            if (er != null && er.compareTo(lastTabletRow) < 0) {
                // System.out.println("er "+er+"  ltr "+lastTabletRow);
                ptl = parent.locateTablet(context, er, true, retry);
                if (ptl != null)
                    locations = locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent);
                else
                    break;
            } else {
                break;
            }
        }

        if (locations == null)
            return;

        // cannot assume the list contains contiguous key extents... so it is probably
        // best to deal with each extent individually

        Text lastEndRow = null;
        for (TabletLocation tabletLocation : locations.getLocations()) {

            KeyExtent ke = tabletLocation.tablet_extent;
            TabletLocation locToCache;

            // create new location if current prevEndRow == endRow
            if ((lastEndRow != null) && (ke.getPrevEndRow() != null) && ke.getPrevEndRow().equals(lastEndRow)) {
                locToCache = new TabletLocation(new KeyExtent(ke.getTableId(), ke.getEndRow(), lastEndRow),
                        tabletLocation.tablet_location, tabletLocation.tablet_session);
            } else {
                locToCache = tabletLocation;
            }

            // save endRow for next iteration
            lastEndRow = locToCache.tablet_extent.getEndRow();

            updateCache(locToCache, lcSession);
        }
    }

}

From source file:org.apache.accumulo.core.client.mapreduce.impl.AccumuloInputSplit.java

License:Apache License

public long getRangeLength(Range range) throws IOException {
    Text startRow = range.isInfiniteStartKey() ? new Text(new byte[] { Byte.MIN_VALUE })
            : range.getStartKey().getRow();
    Text stopRow = range.isInfiniteStopKey() ? new Text(new byte[] { Byte.MAX_VALUE })
            : range.getEndKey().getRow();
    int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength()));
    long diff = 0;

    byte[] start = startRow.getBytes();
    byte[] stop = stopRow.getBytes();
    for (int i = 0; i < maxCommon; ++i) {
        diff |= 0xff & (start[i] ^ stop[i]);
        diff <<= Byte.SIZE;
    }// www . j av  a2s .co  m

    if (startRow.getLength() != stopRow.getLength())
        diff |= 0xff;

    return diff + 1;
}

From source file:org.apache.accumulo.core.client.mapreduce.impl.SplitUtils.java

License:Apache License

public static long getRangeLength(Range range) throws IOException {
    Text startRow = range.isInfiniteStartKey() ? new Text(new byte[] { Byte.MIN_VALUE })
            : range.getStartKey().getRow();
    Text stopRow = range.isInfiniteStopKey() ? new Text(new byte[] { Byte.MAX_VALUE })
            : range.getEndKey().getRow();
    int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength()));
    long diff = 0;

    byte[] start = startRow.getBytes();
    byte[] stop = stopRow.getBytes();
    for (int i = 0; i < maxCommon; ++i) {
        diff |= 0xff & (start[i] ^ stop[i]);
        diff <<= Byte.SIZE;
    }//  www  .j a v a 2s. c o m

    if (startRow.getLength() != stopRow.getLength())
        diff |= 0xff;

    return diff + 1;
}

From source file:org.apache.accumulo.core.clientImpl.mapreduce.SplitUtils.java

License:Apache License

public static long getRangeLength(Range range) {
    Text startRow = range.isInfiniteStartKey() ? new Text(new byte[] { Byte.MIN_VALUE })
            : range.getStartKey().getRow();
    Text stopRow = range.isInfiniteStopKey() ? new Text(new byte[] { Byte.MAX_VALUE })
            : range.getEndKey().getRow();
    int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength()));
    long diff = 0;

    byte[] start = startRow.getBytes();
    byte[] stop = stopRow.getBytes();
    for (int i = 0; i < maxCommon; ++i) {
        diff |= 0xff & (start[i] ^ stop[i]);
        diff <<= Byte.SIZE;
    }/*from  ww w . ja va2  s. c  o m*/

    if (startRow.getLength() != stopRow.getLength())
        diff |= 0xff;

    return diff + 1;
}

From source file:org.apache.accumulo.core.clientImpl.TabletLocatorImpl.java

License:Apache License

private void lookupTabletLocation(ClientContext context, Text row, boolean retry, LockCheckerSession lcSession)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    Text metadataRow = new Text(tableId.canonical());
    metadataRow.append(new byte[] { ';' }, 0, 1);
    metadataRow.append(row.getBytes(), 0, row.getLength());
    TabletLocation ptl = parent.locateTablet(context, metadataRow, false, retry);

    if (ptl != null) {
        TabletLocations locations = locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow,
                parent);// w ww.j  a v a 2s  . c om
        while (locations != null && locations.getLocations().isEmpty()
                && locations.getLocationless().isEmpty()) {
            // try the next tablet, the current tablet does not have any tablets that overlap the row
            Text er = ptl.tablet_extent.getEndRow();
            if (er != null && er.compareTo(lastTabletRow) < 0) {
                // System.out.println("er "+er+" ltr "+lastTabletRow);
                ptl = parent.locateTablet(context, er, true, retry);
                if (ptl != null)
                    locations = locationObtainer.lookupTablet(context, ptl, metadataRow, lastTabletRow, parent);
                else
                    break;
            } else {
                break;
            }
        }

        if (locations == null)
            return;

        // cannot assume the list contains contiguous key extents... so it is probably
        // best to deal with each extent individually

        Text lastEndRow = null;
        for (TabletLocation tabletLocation : locations.getLocations()) {

            KeyExtent ke = tabletLocation.tablet_extent;
            TabletLocation locToCache;

            // create new location if current prevEndRow == endRow
            if ((lastEndRow != null) && (ke.getPrevEndRow() != null) && ke.getPrevEndRow().equals(lastEndRow)) {
                locToCache = new TabletLocation(new KeyExtent(ke.getTableId(), ke.getEndRow(), lastEndRow),
                        tabletLocation.tablet_location, tabletLocation.tablet_session);
            } else {
                locToCache = tabletLocation;
            }

            // save endRow for next iteration
            lastEndRow = locToCache.tablet_extent.getEndRow();

            updateCache(locToCache, lcSession);
        }
    }

}

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

License:Apache License

/**
 * Creates a new condition. The initial column value and timestamp are null, and the initial column visibility is empty.
 *
 * @param cf/*from   w w  w . ja v a 2 s.  c o  m*/
 *          column family
 * @param cq
 *          column qualifier
 * @throws IllegalArgumentException
 *           if any argument is null
 */
public Condition(Text cf, Text cq) {
    checkArgument(cf != null, "cf is null");
    checkArgument(cq != null, "cq is null");
    this.cf = new ArrayByteSequence(cf.getBytes(), 0, cf.getLength());
    this.cq = new ArrayByteSequence(cq.getBytes(), 0, cq.getLength());
    this.cv = EMPTY;
}

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

License:Apache License

/**
 * This method sets the expected value of a column. In order for the condition to pass the column must exist and have this value. If a value is not set, then
 * the column must be absent for the condition to pass. See {@link #setValue(byte[])}.
 *
 * @param value/*w ww .  j av  a  2 s  .c om*/
 *          value
 * @return this condition
 * @throws IllegalArgumentException
 *           if value is null
 */
public Condition setValue(Text value) {
    checkArgument(value != null, "value is null");
    this.val = new ArrayByteSequence(value.getBytes(), 0, value.getLength());
    return this;
}

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

License:Apache License

public static Value encodePrevEndRow(Text per) {
    if (per == null)
        return new Value(new byte[] { 0 });
    byte[] b = new byte[per.getLength() + 1];
    b[0] = 1;/*from  w w w. j a  v  a2  s.c  o  m*/
    System.arraycopy(per.getBytes(), 0, b, 1, per.getLength());
    return new Value(b);
}

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

License:Apache License

/**
 * Populates the extent's fields based on a flatted extent
 *
 *///ww w. j a va  2  s.  co 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);
    }
}