1818 */
1919#define BinaryView_MAX_INLINED_SIZE 12
2020
21+ /**
22+ * The variant tag for a Vortex data type.
23+ */
24+ typedef enum {
25+ /**
26+ * Null type.
27+ */
28+ DTYPE_NULL = 0 ,
29+ /**
30+ * Boolean type.
31+ */
32+ DTYPE_BOOL = 1 ,
33+ /**
34+ * Primitive types (e.g., u8, i16, f32, etc.).
35+ */
36+ DTYPE_PRIMITIVE = 2 ,
37+ /**
38+ * Variable-length UTF-8 string type.
39+ */
40+ DTYPE_UTF8 = 3 ,
41+ /**
42+ * Variable-length binary data type.
43+ */
44+ DTYPE_BINARY = 4 ,
45+ /**
46+ * Nested struct type.
47+ */
48+ DTYPE_STRUCT = 5 ,
49+ /**
50+ * Nested list type.
51+ */
52+ DTYPE_LIST = 6 ,
53+ /**
54+ * User-defined extension type.
55+ */
56+ DTYPE_EXTENSION = 7 ,
57+ /**
58+ * Decimal type with fixed precision and scale.
59+ */
60+ DTYPE_DECIMAL = 8 ,
61+ /**
62+ * Nested fixed-size list type.
63+ */
64+ DTYPE_FIXED_SIZE_LIST = 9 ,
65+ } vx_dtype_variant ;
66+
2167/**
2268 * Variant enum for Vortex primitive types.
2369 */
@@ -68,51 +114,12 @@ typedef enum {
68114 PTYPE_F64 = 10 ,
69115} vx_ptype ;
70116
71- /**
72- * The variant tag for a Vortex data type.
73- */
74117typedef enum {
75- /**
76- * Null type.
77- */
78- DTYPE_NULL = 0 ,
79- /**
80- * Boolean type.
81- */
82- DTYPE_BOOL = 1 ,
83- /**
84- * Primitive types (e.g., u8, i16, f32, etc.).
85- */
86- DTYPE_PRIMITIVE = 2 ,
87- /**
88- * Variable-length UTF-8 string type.
89- */
90- DTYPE_UTF8 = 3 ,
91- /**
92- * Variable-length binary data type.
93- */
94- DTYPE_BINARY = 4 ,
95- /**
96- * Nested struct type.
97- */
98- DTYPE_STRUCT = 5 ,
99- /**
100- * Nested list type.
101- */
102- DTYPE_LIST = 6 ,
103- /**
104- * User-defined extension type.
105- */
106- DTYPE_EXTENSION = 7 ,
107- /**
108- * Decimal type with fixed precision and scale.
109- */
110- DTYPE_DECIMAL = 8 ,
111- /**
112- * Nested fixed-size list type.
113- */
114- DTYPE_FIXED_SIZE_LIST = 9 ,
115- } vx_dtype_variant ;
118+ VX_VALIDITY_NON_NULLABLE = 0 ,
119+ VX_VALIDITY_ALL_VALID = 1 ,
120+ VX_VALIDITY_ALL_INVALID = 2 ,
121+ VX_VALIDITY_ARRAY = 3 ,
122+ } vx_validity_type ;
116123
117124/**
118125 * Log levels for the Vortex library.
@@ -237,14 +244,6 @@ typedef struct Primitive Primitive;
237244
238245/**
239246 * Base type for all Vortex arrays.
240- *
241- * All built-in Vortex array types can be safely cast to this type to pass into functions that
242- * expect a generic array type. e.g.
243- *
244- * ```cpp
245- * auto primitive_array = vx_array_primitive_new(...);
246- * vx_array_len((*vx_array) primitive_array));
247- * ```
248247 */
249248typedef struct vx_array vx_array ;
250249
@@ -322,6 +321,14 @@ typedef struct vx_struct_fields vx_struct_fields;
322321 */
323322typedef struct vx_struct_fields_builder vx_struct_fields_builder ;
324323
324+ typedef struct {
325+ vx_validity_type type ;
326+ /**
327+ * If type is VX_VALIDITY_ARRAY, this is set, NULL otherwise
328+ */
329+ const vx_array * array ;
330+ } vx_validity ;
331+
325332/**
326333 * Options supplied for opening a file.
327334 */
@@ -401,6 +408,20 @@ const vx_array *vx_array_clone(const vx_array *ptr);
401408 */
402409void vx_array_free (const vx_array * ptr );
403410
411+ bool vx_array_is_nullable (const vx_array * array );
412+
413+ bool vx_array_is (const vx_array * array , vx_dtype_variant variant );
414+
415+ bool vx_array_is_primitive (const vx_array * array , vx_ptype ptype );
416+
417+ /**
418+ * Return array's validity.
419+ * If validity.type is VX_VALIDITY_ARRAY, returns an owned vx_array in
420+ * validity.array which must be freed by the caller.
421+ * If validity.type is not VX_VALIDITY_ARRAY, validity.array is NULL.
422+ */
423+ void vx_array_get_validity (const vx_array * array , vx_validity * validity , vx_error * * error );
424+
404425/**
405426 * Get the length of the array.
406427 */
@@ -418,10 +439,30 @@ const vx_array *vx_array_get_field(const vx_array *array, uint32_t index, vx_err
418439
419440const vx_array * vx_array_slice (const vx_array * array , uint32_t start , uint32_t stop , vx_error * * error_out );
420441
421- bool vx_array_is_null (const vx_array * array , uint32_t index , vx_error * * _error_out );
442+ /**
443+ * Check whether array's element at index is null.
444+ * Sets error if index is out of bounds or underlying validity array is
445+ * corrupted.
446+ */
447+ bool vx_array_element_is_null (const vx_array * array , size_t index , vx_error * * error );
422448
423449uint32_t vx_array_null_count (const vx_array * array , vx_error * * error_out );
424450
451+ const vx_array * vx_array_new_null (size_t len );
452+
453+ /**
454+ * Create a new primitive array from an existing buffer.
455+ * It is caller's responsibility to ensure ptr points to a buffer of correct type.
456+ * Buffer contents are copied.
457+ * Takes ownership of validity.array if it is set.
458+ * validity can't be NULL.
459+ */
460+ const vx_array * vx_array_new_primitive (vx_ptype ptype ,
461+ const void * ptr ,
462+ size_t len ,
463+ const vx_validity * validity ,
464+ vx_error * * error );
465+
425466uint8_t vx_array_get_u8 (const vx_array * array , uint32_t index );
426467
427468uint8_t vx_array_get_storage_u8 (const vx_array * array , uint32_t index );
@@ -764,7 +805,8 @@ vx_array_sink *vx_array_sink_open_file(const vx_session *session,
764805 vx_error * * error_out );
765806
766807/**
767- * Pushed a single array chunk into a file sink.
808+ * Push an array into a file sink.
809+ * Does not take ownership of array
768810 */
769811void vx_array_sink_push (vx_array_sink * sink , const vx_array * array , vx_error * * error_out );
770812
0 commit comments