1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Arrow interoperability for Vortex extension types.
//!
//! Implement [`ArrowExtVTable`] and register it with [`ArrowSession::register_extension`] to enable
//! Arrow import and export. Registration wraps the callbacks in an adapter that handles Vortex
//! metadata, while the session validates schema round trips. Plugins only implement conversions.
//!
//! A Vortex extension does not need an equivalent standard Arrow type. It can use a custom Arrow
//! extension name, or decline native export so the session exports storage with the Vortex ID and
//! metadata. When a plugin supplies an Arrow representation, its metadata may not describe the full
//! Vortex dtype. Handling that gap in the adapter prevents plugins from silently losing metadata.
//!
//! Declare an [`ArrowMetadataPolicy`] in [`ArrowExtVTable::metadata_policy`] based on whether the
//! Arrow representation preserves the full Vortex dtype on its own. Callbacks leave transport to
//! the adapter and import arrays with the restored dtype they receive. Plugins remain responsible
//! for preserving values and lengths.
use ArrayRef as ArrowArrayRef;
use Field;
use ArrayRef;
use ExecutionCtx;
use ExtDType;
use ExtVTable;
use VortexResult;
use Id;
use crateArrowExport;
use crateArrowExportOptions;
use crateArrowImport;
use crateArrowSession;
/// Whether an Arrow representation needs separate Vortex metadata or not to restore the full dtype.
///
/// On schema export, the session imports the generated field and checks that it reproduces the
/// original dtype, including metadata, storage, and nullability. On successful array import, the
/// session checks that the returned array has the dtype inferred from the field.
/// Native Arrow conversion callbacks for one Vortex extension type.
///
/// The array callbacks must follow the value contracts of [`crate::ArrowExportVTable`] and
/// [`crate::ArrowImportVTable`]. The adapter carries Vortex metadata so that importing with the
/// inferred Arrow field can recover the original dtype.
///
/// Register through [`ArrowSession::register_extension`], and use the session's conversion APIs.
/// Calling these callbacks directly bypasses metadata transport and schema validation. Callbacks
/// **must** describe only the native Arrow representation, leaving Vortex metadata transport to the
/// adapter. Register the owning dtype in the Vortex session as well to enable its Vortex ID path.
///
/// Register the dtype and its Arrow conversions in the same session:
///
/// ```
/// use vortex_array::dtype::session::DTypeSessionExt;
/// use vortex_arrow::{ArrowExtVTable, ArrowSessionExt};
/// use vortex_session::VortexSession;
///
/// fn register<V: ArrowExtVTable>(session: &VortexSession, vtable: V) {
/// session.dtypes().register(vtable.clone());
/// session.arrow().register_extension(vtable);
/// }
/// ```