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.impl.KeyExtent.java

License:Apache License

/**
 * Empty start or end rows tell the method there are no start or end rows, and to use all the keyextents that are before the end row if no start row etc.
 *
 * @deprecated this method not intended for public use and is likely to be removed in a future version.
 * @return all the key extents that the rows cover
 *//*from  ww  w.j a va 2 s  . c o  m*/
@Deprecated
public static Collection<KeyExtent> getKeyExtentsForRange(Text startRow, Text endRow, Set<KeyExtent> kes) {
    if (kes == null)
        return Collections.emptyList();
    if (startRow == null)
        startRow = new Text();
    if (endRow == null)
        endRow = new Text();
    Collection<KeyExtent> keys = new ArrayList<>();
    for (KeyExtent ckes : kes) {
        if (ckes.getPrevEndRow() == null) {
            if (ckes.getEndRow() == null) {
                // only tablet
                keys.add(ckes);
            } else {
                // first tablet
                // if start row = '' then we want everything up to the endRow which will always include the first tablet
                if (startRow.getLength() == 0) {
                    keys.add(ckes);
                } else if (ckes.getEndRow().compareTo(startRow) >= 0) {
                    keys.add(ckes);
                }
            }
        } else {
            if (ckes.getEndRow() == null) {
                // last tablet
                // if endRow = '' and we're at the last tablet, add it
                if (endRow.getLength() == 0) {
                    keys.add(ckes);
                }
                if (ckes.getPrevEndRow().compareTo(endRow) < 0) {
                    keys.add(ckes);
                }
            } else {
                // tablet in the middle
                if (startRow.getLength() == 0) {
                    // no start row

                    if (endRow.getLength() == 0) {
                        // no start & end row
                        keys.add(ckes);
                    } else {
                        // just no start row
                        if (ckes.getPrevEndRow().compareTo(endRow) < 0) {
                            keys.add(ckes);
                        }
                    }
                } else if (endRow.getLength() == 0) {
                    // no end row
                    if (ckes.getEndRow().compareTo(startRow) >= 0) {
                        keys.add(ckes);
                    }
                } else {
                    // no null prevend or endrows and no empty string start or end rows
                    if (ckes.getPrevEndRow().compareTo(endRow) < 0
                            && ckes.getEndRow().compareTo(startRow) >= 0) {
                        keys.add(ckes);
                    }
                }

            }
        }
    }
    return keys;
}

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;//w  w w.ja  v  a  2  s  .  co 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
 *
 *//*  www  .  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);
    }
}

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

License:Apache License

/**
 * Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, timestamp {@link Long#MAX_VALUE}, and delete
 * marker false./*from  w  ww .j av a2 s.  c  om*/
 *
 * @param row
 *          row ID
 */
public Key(Text row) {
    init(row.getBytes(), 0, row.getLength(), EMPTY_BYTES, 0, 0, EMPTY_BYTES, 0, 0, EMPTY_BYTES, 0, 0,
            Long.MAX_VALUE, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, empty column qualifier, empty column visibility, timestamp {@link Long#MAX_VALUE}, and
 * delete marker false./*from  w  ww .j  ava 2  s. com*/
 */
public Key(Text row, Text cf) {
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), EMPTY_BYTES, 0, 0, EMPTY_BYTES,
            0, 0, Long.MAX_VALUE, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, timestamp
 * {@link Long#MAX_VALUE}, and delete marker false.
 *///from w w w  .j  a v a2s  .  c o  m
public Key(Text row, Text cf, Text cq) {
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(),
            EMPTY_BYTES, 0, 0, Long.MAX_VALUE, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, timestamp
 * {@link Long#MAX_VALUE}, and delete marker false.
 *//*from   ww  w. j  a va 2 s .c  om*/
public Key(Text row, Text cf, Text cq, Text cv) {
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(),
            cv.getBytes(), 0, cv.getLength(), Long.MAX_VALUE, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and
 * delete marker false./*from w ww. j  a va  2  s .  co  m*/
 */
public Key(Text row, Text cf, Text cq, long ts) {
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(),
            EMPTY_BYTES, 0, 0, ts, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified
 * timestamp, and delete marker false.//from  w  ww  .  j  av a 2 s. c om
 */
public Key(Text row, Text cf, Text cq, Text cv, long ts) {
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(),
            cv.getBytes(), 0, cv.getLength(), ts, false, true);
}

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

License:Apache License

/**
 * Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified
 * timestamp, and delete marker false./* ww w . j  a  v a2 s . c  o m*/
 */
public Key(Text row, Text cf, Text cq, ColumnVisibility cv, long ts) {
    byte[] expr = cv.getExpression();
    init(row.getBytes(), 0, row.getLength(), cf.getBytes(), 0, cf.getLength(), cq.getBytes(), 0, cq.getLength(),
            expr, 0, expr.length, ts, false, true);
}