Skip to content

Commit 8a5fd60

Browse files
authored
docs: fill in missing javadoc (#4233)
Now that the javadoc is on the website, I noticed it was pretty slim... This was mostly Claude Code, I skimmed most of the diff and fixed a few small nits myself. --------- Signed-off-by: Andrew Duffy <[email protected]>
1 parent df21f42 commit 8a5fd60

34 files changed

+1788
-21
lines changed

java/vortex-jni/src/main/java/dev/vortex/DateTimeUtil.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,42 @@
99
import java.time.ZoneOffset;
1010
import java.time.temporal.ChronoUnit;
1111

12-
// Helpful functions borrowed from Iceberg class with same name.
12+
/**
13+
* Utility class for date and time conversions in Vortex.
14+
*
15+
* <p>This class provides helper functions for converting Java date/time objects
16+
* to nanoseconds since the Unix epoch, which is the internal representation
17+
* used by Vortex for temporal data.</p>
18+
*
19+
* <p>Helpful functions borrowed from Iceberg class with same name.</p>
20+
*/
1321
public final class DateTimeUtil {
22+
/**
23+
* The Unix epoch as an OffsetDateTime (1970-01-01T00:00:00Z).
24+
*/
1425
public static final OffsetDateTime EPOCH = Instant.ofEpochSecond(0).atOffset(ZoneOffset.UTC);
1526

16-
// Just assume timestamp is already at UTC for conversion purposes.
17-
// When decoded back to LocalDateTime
27+
/**
28+
* Converts a LocalDateTime to nanoseconds since the Unix epoch.
29+
*
30+
* <p>The LocalDateTime is assumed to be in UTC timezone for conversion purposes.
31+
* When decoded back to LocalDateTime, the timezone information will not be preserved.</p>
32+
*
33+
* @param dateTime the LocalDateTime to convert
34+
* @return nanoseconds since the Unix epoch
35+
*/
1836
public static long nanosFromTimestamp(LocalDateTime dateTime) {
1937
return ChronoUnit.NANOS.between(EPOCH, dateTime.atOffset(ZoneOffset.UTC));
2038
}
2139

40+
/**
41+
* Converts an OffsetDateTime to nanoseconds since the Unix epoch.
42+
*
43+
* <p>The timezone information in the OffsetDateTime is preserved during conversion.</p>
44+
*
45+
* @param dateTime the OffsetDateTime to convert
46+
* @return nanoseconds since the Unix epoch
47+
*/
2248
public static long nanosFromTimestamptz(OffsetDateTime dateTime) {
2349
return ChronoUnit.NANOS.between(EPOCH, dateTime);
2450
}

java/vortex-jni/src/main/java/dev/vortex/api/Array.java

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,182 @@
88
import org.apache.arrow.vector.VectorSchemaRoot;
99

1010
public interface Array extends AutoCloseable {
11+
/**
12+
* Returns the number of elements in this array.
13+
*
14+
* @return the length of the array
15+
*/
1116
long getLen();
1217

18+
/**
19+
* Returns the total size in bytes of this array including all buffers.
20+
*
21+
* @return the size in bytes
22+
*/
1323
long nbytes();
1424

1525
/**
1626
* Export to an ArrowVector. The data will now be owned by the VectorSchemaRoot after this operation.
1727
*/
1828
VectorSchemaRoot exportToArrow(BufferAllocator allocator, VectorSchemaRoot reuse);
1929

30+
/**
31+
* Returns the data type of this array.
32+
*
33+
* @return the DType describing the logical type of this array
34+
*/
2035
DType getDataType();
2136

37+
/**
38+
* Returns a child array at the given field index.
39+
*
40+
* <p>This is used for accessing fields in struct arrays or elements in list arrays.</p>
41+
*
42+
* @param index the field index
43+
* @return the child array at the specified index
44+
* @throws IndexOutOfBoundsException if index is out of bounds
45+
*/
2246
Array getField(int index);
2347

48+
/**
49+
* Returns a slice of this array from start (inclusive) to stop (exclusive).
50+
*
51+
* @param start the starting index (inclusive)
52+
* @param stop the ending index (exclusive)
53+
* @return a new Array containing the sliced elements
54+
* @throws IndexOutOfBoundsException if start or stop are out of bounds
55+
*/
2456
Array slice(int start, int stop);
2557

58+
/**
59+
* Returns true if the value at the given index is null.
60+
*
61+
* @param index the element index
62+
* @return true if the value is null, false otherwise
63+
* @throws IndexOutOfBoundsException if index is out of bounds
64+
*/
2665
boolean getNull(int index);
2766

67+
/**
68+
* Returns the total number of null values in this array.
69+
*
70+
* @return the null count
71+
*/
2872
int getNullCount();
2973

74+
/**
75+
* Returns the byte value at the given index.
76+
*
77+
* @param index the element index
78+
* @return the byte value
79+
* @throws IndexOutOfBoundsException if index is out of bounds
80+
* @throws ClassCastException if the array type is not compatible with byte
81+
*/
3082
byte getByte(int index);
3183

84+
/**
85+
* Returns the short value at the given index.
86+
*
87+
* @param index the element index
88+
* @return the short value
89+
* @throws IndexOutOfBoundsException if index is out of bounds
90+
* @throws ClassCastException if the array type is not compatible with short
91+
*/
3292
short getShort(int index);
3393

94+
/**
95+
* Returns the int value at the given index.
96+
*
97+
* @param index the element index
98+
* @return the int value
99+
* @throws IndexOutOfBoundsException if index is out of bounds
100+
* @throws ClassCastException if the array type is not compatible with int
101+
*/
34102
int getInt(int index);
35103

104+
/**
105+
* Returns the long value at the given index.
106+
*
107+
* @param index the element index
108+
* @return the long value
109+
* @throws IndexOutOfBoundsException if index is out of bounds
110+
* @throws ClassCastException if the array type is not compatible with long
111+
*/
36112
long getLong(int index);
37113

114+
/**
115+
* Returns the boolean value at the given index.
116+
*
117+
* @param index the element index
118+
* @return the boolean value
119+
* @throws IndexOutOfBoundsException if index is out of bounds
120+
* @throws ClassCastException if the array type is not compatible with boolean
121+
*/
38122
boolean getBool(int index);
39123

124+
/**
125+
* Returns the float value at the given index.
126+
*
127+
* @param index the element index
128+
* @return the float value
129+
* @throws IndexOutOfBoundsException if index is out of bounds
130+
* @throws ClassCastException if the array type is not compatible with float
131+
*/
40132
float getFloat(int index);
41133

134+
/**
135+
* Returns the double value at the given index.
136+
*
137+
* @param index the element index
138+
* @return the double value
139+
* @throws IndexOutOfBoundsException if index is out of bounds
140+
* @throws ClassCastException if the array type is not compatible with double
141+
*/
42142
double getDouble(int index);
43143

144+
/**
145+
* Returns the BigDecimal value at the given index.
146+
*
147+
* @param index the element index
148+
* @return the BigDecimal value
149+
* @throws IndexOutOfBoundsException if index is out of bounds
150+
* @throws ClassCastException if the array type is not compatible with decimal
151+
*/
44152
BigDecimal getBigDecimal(int index);
45153

154+
/**
155+
* Returns the UTF-8 string value at the given index.
156+
*
157+
* @param index the element index
158+
* @return the string value
159+
* @throws IndexOutOfBoundsException if index is out of bounds
160+
* @throws ClassCastException if the array type is not compatible with string
161+
*/
46162
String getUTF8(int index);
47163

164+
/**
165+
* Returns the UTF-8 string value at the given index as a pointer and length.
166+
*
167+
* <p>This is a low-level method that provides direct access to the underlying
168+
* string data without copying. The pointer and length are written to the
169+
* provided arrays.</p>
170+
*
171+
* @param index the element index
172+
* @param ptr array to store the pointer (first element will be set)
173+
* @param len array to store the length (first element will be set)
174+
* @throws IndexOutOfBoundsException if index is out of bounds
175+
* @throws ClassCastException if the array type is not compatible with string
176+
*/
48177
void getUTF8_ptr_len(int index, long[] ptr, int[] len);
49178

179+
/**
180+
* Returns the binary value at the given index as a byte array.
181+
*
182+
* @param index the element index
183+
* @return the binary value as a byte array
184+
* @throws IndexOutOfBoundsException if index is out of bounds
185+
* @throws ClassCastException if the array type is not compatible with binary
186+
*/
50187
byte[] getBinary(int index);
51188

52189
@Override

java/vortex-jni/src/main/java/dev/vortex/api/ArrayIterator.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,65 @@
55

66
import java.util.Iterator;
77

8+
/**
9+
* An iterator interface for traversing Vortex arrays while providing type information
10+
* and resource management capabilities.
11+
*
12+
* <p>This interface extends both {@link Iterator} and {@link AutoCloseable}, allowing
13+
* for efficient iteration over array elements while ensuring proper cleanup of any
14+
* underlying resources. The iterator provides access to the data type of the arrays
15+
* being iterated over, which is useful for type-safe processing.</p>
16+
*
17+
* <p>Example usage:</p>
18+
* <pre>{@code
19+
* try (ArrayIterator iterator = array.getIterator()) {
20+
* DType dataType = iterator.getDataType();
21+
* while (iterator.hasNext()) {
22+
* Array element = iterator.next();
23+
* // Process element based on dataType
24+
* }
25+
* }
26+
* }</pre>
27+
*
28+
* @see Array
29+
* @see DType
30+
* @see Iterator
31+
* @see AutoCloseable
32+
*/
833
public interface ArrayIterator extends AutoCloseable, Iterator<Array> {
34+
/**
35+
* Returns the data type of the arrays that this iterator produces.
36+
*
37+
* <p>This method provides type information about the arrays that will be
38+
* returned by subsequent calls to {@link #next()}. The data type remains
39+
* constant throughout the lifetime of the iterator and can be used for
40+
* type-safe processing and validation.</p>
41+
*
42+
* @return the {@link DType} representing the data type of arrays produced by this iterator
43+
*/
944
DType getDataType();
1045

46+
/**
47+
* Closes this iterator and releases any underlying resources.
48+
*
49+
* <p>This method should be called when the iterator is no longer needed to
50+
* ensure proper cleanup of any native resources or memory allocations.
51+
* After calling this method, the iterator should not be used for further
52+
* operations.</p>
53+
*
54+
* <p>It is recommended to use this iterator within a try-with-resources
55+
* statement to ensure automatic cleanup:</p>
56+
* <pre>{@code
57+
* try (ArrayIterator iterator = array.getIterator()) {
58+
* // Use iterator
59+
* } // close() is called automatically
60+
* }</pre>
61+
*
62+
* <p>This method overrides {@link AutoCloseable#close()} and does not
63+
* throw any checked exceptions, making it safe to use in any context.</p>
64+
*
65+
* @see AutoCloseable#close()
66+
*/
1167
@Override
1268
void close();
1369
}

0 commit comments

Comments
 (0)