Skip to content

Commit 8c26459

Browse files
elharorschlussel
authored andcommitted
Expand block documentation
1 parent 8a026e5 commit 8c26459

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

presto-common/src/main/java/com/facebook/presto/common/block/Block.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* A block packs positionCount values into a chunk of memory. How the values are packed,
2727
* whether compression is used, endianness, and other implementation details are up to the subclasses.
28-
* However, for purposes of API, you can think of a Block as a sequence of values that
28+
* However, for purposes of API, you can think of a Block as a sequence of zero-indexed values that
2929
* can be read by calling the getter methods in this interface. For instance,
3030
* you can read positionCount bytes by calling
3131
* block.getByte(0), block.getByte(1), ... block.getByte(positionCount - 1).
@@ -51,6 +51,8 @@ default int getSliceLength(int position)
5151

5252
/**
5353
* Gets a byte in the value at {@code position}.
54+
*
55+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
5456
*/
5557
default byte getByte(int position)
5658
{
@@ -59,6 +61,8 @@ default byte getByte(int position)
5961

6062
/**
6163
* Gets a short in the value at {@code position}.
64+
*
65+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
6266
*/
6367
default short getShort(int position)
6468
{
@@ -67,6 +71,8 @@ default short getShort(int position)
6771

6872
/**
6973
* Gets an int in the value at {@code position}.
74+
*
75+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
7076
*/
7177
default int getInt(int position)
7278
{
@@ -75,6 +81,8 @@ default int getInt(int position)
7581

7682
/**
7783
* Gets a long in the value at {@code position}.
84+
*
85+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
7886
*/
7987
default long getLong(int position)
8088
{
@@ -99,15 +107,16 @@ default Slice getSlice(int position, int offset, int length)
99107

100108
/**
101109
* Gets a block in the value at {@code position}.
102-
* @return
110+
*
111+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
103112
*/
104113
default Block getBlock(int position)
105114
{
106115
throw new UnsupportedOperationException(getClass().getName());
107116
}
108117

109118
/**
110-
* Is the byte sequences at {@code offset} in the value at {@code position} equal
119+
* Is the byte sequence at {@code offset} in the value at {@code position} equal
111120
* to the byte sequence at {@code otherOffset} in {@code otherSlice}.
112121
* This method must be implemented if @{code getSlice} is implemented.
113122
*/
@@ -147,7 +156,7 @@ default void writeBytesTo(int position, int offset, int length, SliceOutput slic
147156
}
148157

149158
/**
150-
* Appends the value at {@code position} to {@code blockBuilder} and close the entry.
159+
* Appends the value at {@code position} to {@code blockBuilder} and closes the entry.
151160
*/
152161
void writePositionTo(int position, BlockBuilder blockBuilder);
153162

@@ -378,12 +387,14 @@ default Block getLoadedBlock()
378387
Block appendNull();
379388

380389
/**
381-
* Returns the converted long value at {@code position} if the value ar {@code position} can be converted to long.
382-
* @throws UnsupportedOperationException if value at {@code position} is not compatible to be converted to long.
390+
* Returns the converted long value at {@code position} if the value at {@code position} can be converted to long.
383391
*
384392
* Difference between toLong() and getLong() is:
385393
* getLong() would only return value when the block is LongArrayBlock, otherwise it would throw exception.
386394
* toLong() would return value for compatible types: LongArrayBlock, IntArrayBlock, ByteArrayBlock and ShortArrayBlock.
395+
*
396+
* @throws UnsupportedOperationException if value at {@code position} is not able to be converted to long.
397+
* @throws IllegalArgumentException if position is negative or greater than or equal to the positionCount
387398
*/
388399
default long toLong(int position)
389400
{

presto-common/src/main/java/com/facebook/presto/common/block/DictionaryBlock.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
import static java.lang.String.format;
3737
import static java.util.Objects.requireNonNull;
3838

39+
/**
40+
* A dictionary holds positionCount values of arbitrary types. Usually some of these values are repeated,
41+
* and the block wraps an underlying delegate block with fewer or no repeated values.
42+
* This delegate block is called the "dictionary".
43+
* The ids array contains positionCount indexes into the underlying delegate block.
44+
* When value N is requested from this block instead of returning the value directly,
45+
* it looks up the index of value N at ids[N]; then it returns the value in dictionary[ids[N]].
46+
* This compresses data when the same value repeats at multiple locations.
47+
*
48+
* Not every id in the ids array is a valid position in the block.
49+
* Specify an offset in the ids array to indicate that IDs are only stored from that position forward.
50+
* If the ids array is longer than offset+positionCount, then extra values to the right are not valid.
51+
* That is, IDs are stored in a range of the array from offset to offset+positionCount-1 (inclusive).
52+
*/
3953
public class DictionaryBlock
4054
implements Block
4155
{
@@ -509,6 +523,10 @@ int[] getRawIds()
509523
return ids;
510524
}
511525

526+
/**
527+
* @param position the position of the desired value in this block
528+
* @return the position of the desired value in the underlying block this block wraps
529+
*/
512530
public int getId(int position)
513531
{
514532
checkValidPosition(position, positionCount);

0 commit comments

Comments
 (0)