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.client.impl.ConditionalWriterImpl.java

License:Apache License

private boolean isVisible(ByteSequence cv) {
    Text testVis = new Text(cv.toArray());
    if (testVis.getLength() == 0)
        return true;

    Boolean b = cache.get(testVis);
    if (b != null)
        return b;

    try {/*w  w w.  j a v  a 2  s .c o  m*/
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException e) {
        return false;
    } catch (BadArgumentException e) {
        return false;
    }
}

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  ww w  . j  a  v  a  2s  .com*/
        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;
    }/*from ww w  .  j  a  v  a 2  s . 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;
    }/*from  w ww. j a va2  s .  c  o  m*/

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

    return diff + 1;
}

From source file:org.apache.accumulo.core.client.mock.MockTableOperations.java

License:Apache License

@Override
public void deleteRows(String tableName, Text start, Text end)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    if (!exists(tableName))
        throw new TableNotFoundException(tableName, tableName, "");
    MockTable t = acu.tables.get(tableName);
    Text startText = start != null ? new Text(start) : new Text();
    if (startText.getLength() == 0 && end == null) {
        t.table.clear();//from w w w.ja v a  2 s . c  om
        return;
    }
    Text endText = end != null ? new Text(end) : new Text(t.table.lastKey().getRow().getBytes());
    startText.append(ZERO, 0, 1);
    endText.append(ZERO, 0, 1);
    Set<Key> keep = new TreeSet<>(t.table.subMap(new Key(startText), new Key(endText)).keySet());
    t.table.keySet().removeAll(keep);
}

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

License:Apache License

private boolean isVisible(ByteSequence cv) {
    Text testVis = new Text(cv.toArray());
    if (testVis.getLength() == 0)
        return true;

    Boolean b = cache.get(testVis);
    if (b != null)
        return b;

    try {/* w ww.java 2 s  .  co m*/
        boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException | BadArgumentException e) {
        return false;
    }
}

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;
    }/*w w  w  .  j  a v  a  2s .com*/

    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  w  w.j av a  2 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.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/*w ww  .j  a  va  2 s.co 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/*from   w w w  .j a v a 2  s.c o m*/
 *          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;
}