List of usage examples for org.apache.hadoop.io DataInputBuffer getPosition
public int getPosition()
From source file:org.apache.tez.engine.common.combine.CombineInput.java
License:Apache License
private boolean nextKeyValue() throws IOException, InterruptedException { if (!hasMore) { key = null;/*from ww w . ja v a2 s.c o m*/ value = null; return false; } firstValue = !nextKeyIsSame; DataInputBuffer nextKey = input.getKey(); currentRawKey.set(nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()); buffer.reset(currentRawKey.getBytes(), 0, currentRawKey.getLength()); key = keyDeserializer.deserialize(key); DataInputBuffer nextVal = input.getValue(); buffer.reset(nextVal.getData(), nextVal.getPosition(), nextVal.getLength()); value = valueDeserializer.deserialize(value); hasMore = input.next(); if (hasMore) { nextKey = input.getKey(); nextKeyIsSame = comparator.compare(currentRawKey.getBytes(), 0, currentRawKey.getLength(), nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()) == 0; } else { nextKeyIsSame = false; } inputValueCounter.increment(1); return true; }
From source file:org.apache.tez.engine.common.shuffle.impl.InMemoryWriter.java
License:Apache License
public void append(DataInputBuffer key, DataInputBuffer value) throws IOException { int keyLength = key.getLength() - key.getPosition(); if (keyLength < 0) { throw new IOException("Negative key-length not allowed: " + keyLength + " for " + key); }/* www . j ava 2s. co m*/ boolean sameKey = (key == IFile.REPEAT_KEY); int valueLength = value.getLength() - value.getPosition(); if (valueLength < 0) { throw new IOException("Negative value-length not allowed: " + valueLength + " for " + value); } if (sameKey) { WritableUtils.writeVInt(out, IFile.RLE_MARKER); WritableUtils.writeVInt(out, valueLength); out.write(value.getData(), value.getPosition(), valueLength); } else { if (LOG.isDebugEnabled()) { LOG.debug("InMemWriter.append" + " key.data=" + key.getData() + " key.pos=" + key.getPosition() + " key.len=" + key.getLength() + " val.data=" + value.getData() + " val.pos=" + value.getPosition() + " val.len=" + value.getLength()); } WritableUtils.writeVInt(out, keyLength); WritableUtils.writeVInt(out, valueLength); out.write(key.getData(), key.getPosition(), keyLength); out.write(value.getData(), value.getPosition(), valueLength); } }
From source file:org.apache.tez.engine.common.task.impl.ValuesIterator.java
License:Apache License
/** * read the next key //from w ww. j ava2 s . c o m */ private void readNextKey() throws IOException { more = in.next(); if (more) { DataInputBuffer nextKeyBytes = in.getKey(); keyIn.reset(nextKeyBytes.getData(), nextKeyBytes.getPosition(), nextKeyBytes.getLength()); nextKey = keyDeserializer.deserialize(nextKey); hasNext = key != null && (comparator.compare(key, nextKey) == 0); } else { hasNext = false; } }
From source file:org.apache.tez.engine.common.task.impl.ValuesIterator.java
License:Apache License
/** * Read the next value//from w ww .j a va 2s. c om * @throws IOException */ private void readNextValue() throws IOException { DataInputBuffer nextValueBytes = in.getValue(); valueIn.reset(nextValueBytes.getData(), nextValueBytes.getPosition(), nextValueBytes.getLength()); value = valDeserializer.deserialize(value); }
From source file:org.apache.tez.mapreduce.hadoop.mapreduce.ReduceContextImpl.java
License:Apache License
/** * Advance to the next key/value pair./* w ww. j av a 2 s. c o m*/ */ @Override public boolean nextKeyValue() throws IOException, InterruptedException { if (!hasMore) { key = null; value = null; return false; } firstValue = !nextKeyIsSame; DataInputBuffer nextKey = input.getKey(); currentRawKey.set(nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()); buffer.reset(currentRawKey.getBytes(), 0, currentRawKey.getLength()); key = keyDeserializer.deserialize(key); DataInputBuffer nextVal = input.getValue(); buffer.reset(nextVal.getData(), nextVal.getPosition(), nextVal.getLength()); value = valueDeserializer.deserialize(value); currentKeyLength = nextKey.getLength() - nextKey.getPosition(); currentValueLength = nextVal.getLength() - nextVal.getPosition(); if (isMarked) { backupStore.write(nextKey, nextVal); } hasMore = input.next(); if (hasMore) { nextKey = input.getKey(); nextKeyIsSame = comparator.compare(currentRawKey.getBytes(), 0, currentRawKey.getLength(), nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()) == 0; } else { nextKeyIsSame = false; } inputValueCounter.increment(1); return true; }
From source file:org.apache.tez.runtime.library.common.ValuesIterator.java
License:Apache License
/** * read the next key - which may be the same as the current key. *//*from www . j a va 2 s . c o m*/ private void readNextKey() throws IOException { more = in.next(); if (more) { DataInputBuffer nextKeyBytes = in.getKey(); if (!in.isSameKey()) { keyIn.reset(nextKeyBytes.getData(), nextKeyBytes.getPosition(), nextKeyBytes.getLength() - nextKeyBytes.getPosition()); nextKey = keyDeserializer.deserialize(nextKey); // TODO Is a counter increment required here ? hasMoreValues = key != null && (comparator.compare(key, nextKey) == 0); } else { hasMoreValues = in.isSameKey(); } } else { hasMoreValues = false; } }
From source file:org.apache.tez.runtime.library.common.ValuesIterator.java
License:Apache License
/** * Read the next value/*from w ww . java 2 s.c o m*/ * @throws IOException */ private void readNextValue() throws IOException { DataInputBuffer nextValueBytes = in.getValue(); valueIn.reset(nextValueBytes.getData(), nextValueBytes.getPosition(), nextValueBytes.getLength() - nextValueBytes.getPosition()); value = valDeserializer.deserialize(value); }
From source file:org.apache.tez.runtime.library.utils.BufferUtils.java
License:Apache License
public static int compare(DataInputBuffer buf1, DataInputBuffer buf2) { byte[] b1 = buf1.getData(); byte[] b2 = buf2.getData(); int s1 = buf1.getPosition(); int s2 = buf2.getPosition(); int l1 = buf1.getLength(); int l2 = buf2.getLength(); return FastByteComparisons.compareTo(b1, s1, l1, b2, s2, l2); }
From source file:org.apache.tez.runtime.library.utils.BufferUtils.java
License:Apache License
public static int compare(DataInputBuffer buf1, DataOutputBuffer buf2) { byte[] b1 = buf1.getData(); byte[] b2 = buf2.getData(); int s1 = buf1.getPosition(); int s2 = 0;/* ww w. ja v a 2 s . com*/ int l1 = buf1.getLength(); int l2 = buf2.getLength(); return FastByteComparisons.compareTo(b1, s1, (l1 - s1), b2, s2, l2); }
From source file:org.apache.tez.runtime.library.utils.BufferUtils.java
License:Apache License
public static void copy(DataInputBuffer src, DataOutputBuffer dst) throws IOException { byte[] b1 = src.getData(); int s1 = src.getPosition(); int l1 = src.getLength(); dst.reset();/*from w w w . ja va 2s. co m*/ dst.write(b1, s1, l1 - s1); }