Java Code Examples for org.apache.hadoop.io.WritableComparator#compareBytes()

The following examples show how to use org.apache.hadoop.io.WritableComparator#compareBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GFKey.java    From gemfirexd-oss with Apache License 2.0 7 votes vote down vote up
@Override
public int compareTo(GFKey o) {
  try {
    byte[] b1 = BlobHelper.serializeToBlob(key);
    byte[] b2 = BlobHelper.serializeToBlob(o.key);
    return WritableComparator.compareBytes(b1, 0, b1.length, b2, 0, b2.length);
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  
  return 0;
}
 
Example 2
Source File: KVGenerator.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
private void fillKey(BytesWritable o) {
  int len = keyLenRNG.nextInt();
  if (len < MIN_KEY_LEN) len = MIN_KEY_LEN;
  o.setSize(len);
  int n = MIN_KEY_LEN;
  while (n < len) {
    byte[] word = dict[random.nextInt(dict.length)];
    int l = Math.min(word.length, len - n);
    System.arraycopy(word, 0, o.get(), n, l);
    n += l;
  }
  if (sorted
      && WritableComparator.compareBytes(lastKey.get(), MIN_KEY_LEN, lastKey
          .getSize()
          - MIN_KEY_LEN, o.get(), MIN_KEY_LEN, o.getSize() - MIN_KEY_LEN) > 0) {
    incrementPrefix();
  }

  System.arraycopy(prefix, 0, o.get(), 0, MIN_KEY_LEN);
  lastKey.set(o);
}
 
Example 3
Source File: BytesRefWritable.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int compareTo(BytesRefWritable other) {
  if (other == null) {
    throw new IllegalArgumentException("Argument can not be null.");
  }
  if (this == other) {
    return 0;
  }
  try {
    return WritableComparator.compareBytes(getData(), start, getLength(),
        other.getData(), other.start, other.getLength());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source File: Key.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public final int compareTo(Key k) {
  byte[] b1 = this.key;
  byte[] b2 = k.key;

  return WritableComparator.compareBytes(b1, 0, b1.length, b2, 0, b2.length);
}
 
Example 5
Source File: EdgeKeyDecoder.java    From datawave with Apache License 2.0 5 votes vote down vote up
public static EDGE_FORMAT determineEdgeFormat(Text colFam) {
    if (WritableComparator.compareBytes(colFam.getBytes(), 0, STATS_BYTES.length, STATS_BYTES, 0, STATS_BYTES.length) == 0) {
        return EDGE_FORMAT.STATS;
    } else {
        return EDGE_FORMAT.STANDARD;
    }
}
 
Example 6
Source File: TestGridmixRecord.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static void binSortTest(GridmixRecord x, GridmixRecord y, int min,
    int max, WritableComparator cmp) throws Exception {
  final Random r = new Random();
  final long s = r.nextLong();
  r.setSeed(s);
  LOG.info("sort: " + s);
  final DataOutputBuffer out1 = new DataOutputBuffer();
  final DataOutputBuffer out2 = new DataOutputBuffer();
  for (int i = min; i < max; ++i) {
    final long seed1 = r.nextLong();
    setSerialize(x, seed1, i, out1);
    assertEquals(0, x.compareSeed(seed1, Math.max(0, i - x.fixedBytes())));

    final long seed2 = r.nextLong();
    setSerialize(y, seed2, i, out2);
    assertEquals(0, y.compareSeed(seed2, Math.max(0, i - x.fixedBytes())));

    // for eq sized records, ensure byte cmp where req
    final int chk = WritableComparator.compareBytes(
        out1.getData(), 0, out1.getLength(),
        out2.getData(), 0, out2.getLength());
    assertEquals(Integer.signum(chk), Integer.signum(x.compareTo(y)));
    assertEquals(Integer.signum(chk), Integer.signum(cmp.compare(
          out1.getData(), 0, out1.getLength(),
          out2.getData(), 0, out2.getLength())));
    // write second copy, compare eq
    final int s1 = out1.getLength();
    x.write(out1);
    assertEquals(0, cmp.compare(out1.getData(), 0, s1,
          out1.getData(), s1, out1.getLength() - s1));
    final int s2 = out2.getLength();
    y.write(out2);
    assertEquals(0, cmp.compare(out2.getData(), 0, s2,
          out2.getData(), s2, out2.getLength() - s2));
    assertEquals(Integer.signum(chk), Integer.signum(cmp.compare(out1.getData(), 0, s1,
          out2.getData(), s2, out2.getLength() - s2)));
  }
}
 
Example 7
Source File: GeoWaveKey.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(final GeoWaveKey o) {
  final byte[] internalAdapterIdBytes = ByteArrayUtils.shortToByteArray(adapterId);
  return WritableComparator.compareBytes(
      internalAdapterIdBytes,
      0,
      internalAdapterIdBytes.length,
      ByteArrayUtils.shortToByteArray(o.adapterId),
      0,
      ByteArrayUtils.shortToByteArray(o.adapterId).length);
}
 
Example 8
Source File: DataByteArray.java    From spork with Apache License 2.0 4 votes vote down vote up
public static int compare(byte[] b1, byte[] b2) {
    return WritableComparator.compareBytes(b1, 0, b1.length,
                                           b2, 0, b2.length);
}
 
Example 9
Source File: TestTotalOrderPartitioner.java    From RDFS with Apache License 2.0 4 votes vote down vote up
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  int n1 = WritableUtils.decodeVIntSize(b1[s1]);
  int n2 = WritableUtils.decodeVIntSize(b2[s2]);
  return -1 * WritableComparator.compareBytes(b1, s1+n1, l1-n1,
                                              b2, s2+n2, l2-n2);
}
 
Example 10
Source File: SecondarySort.java    From RDFS with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8, 
                                         b2, s2, Integer.SIZE/8);
}
 
Example 11
Source File: TestTFileJClassComparatorByteArrays.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
}
 
Example 12
Source File: SecondarySort.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8, 
                                         b2, s2, Integer.SIZE/8);
}
 
Example 13
Source File: TestTotalOrderPartitioner.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  int n1 = WritableUtils.decodeVIntSize(b1[s1]);
  int n2 = WritableUtils.decodeVIntSize(b2[s2]);
  return -1 * WritableComparator.compareBytes(b1, s1+n1, l1-n1,
                                              b2, s2+n2, l2-n2);
}
 
Example 14
Source File: TripleIndexes.java    From systemds with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1,
              byte[] b2, int s2, int l2)
{
	return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
}
 
Example 15
Source File: TestTFileJClassComparatorByteArrays.java    From RDFS with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, l1, b2, s2, l2);
}
 
Example 16
Source File: SecondarySort.java    From incubator-tez with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8, 
                                         b2, s2, Integer.SIZE/8);
}
 
Example 17
Source File: SecondarySort.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8, 
                                         b2, s2, Integer.SIZE/8);
}
 
Example 18
Source File: StatsLinksEdgeCombiner.java    From datawave with Apache License 2.0 4 votes vote down vote up
private static boolean startsWith(final Text workColumnFamily2, final Text statsLinks) {
    return (WritableComparator.compareBytes(workColumnFamily2.getBytes(), 0, statsLinks.getLength(), statsLinks.getBytes(), 0, statsLinks.getLength()) == 0);
}
 
Example 19
Source File: SecondarySort.java    From hadoop-gpu with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
  return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8, 
                                         b2, s2, Integer.SIZE/8);
}
 
Example 20
Source File: ImmutableBytesWritable.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Compares the bytes in this object to the specified byte array
 * @param that
 * @return Positive if left is bigger than right, 0 if they are equal, and
 *         negative if left is smaller than right.
 */
public int compareTo(final byte [] that) {
  return WritableComparator.compareBytes(
    this.bytes, this.offset, this.length,
    that, 0, that.length);
}