@@ -122,13 +122,20 @@ def __arrow_c_array__(self, requested_schema=None):
122
122
return __graalpython__ .export_arrow_vector (self )
123
123
124
124
125
- __interop_registered = False
125
+ __enabled_java_integration = False
126
126
127
127
128
- def register_interop_behavior ():
129
- global __interop_registered
130
- if not __interop_registered :
131
- __interop_registered = True
128
+ def enable_java_integration (allow_method_overwrites : bool = False ):
129
+ """
130
+ This method enables passing Java Apache Arrow vector classes directly to Python code without copying any memory.
131
+ It basically calls `polyglot.register_interop_type` on every vector class defined in the library.
132
+ Calling the method more than once has no effect.
133
+
134
+ If allow_method_overwrites=True, defining the same method is explicitly allowed.
135
+ """
136
+ global __enabled_java_integration
137
+ if not __enabled_java_integration :
138
+ __enabled_java_integration = True
132
139
# Ints
133
140
int8_vector_class_path = java .type ("org.apache.arrow.vector.TinyIntVector" )
134
141
int16_vector_class_path = java .type ("org.apache.arrow.vector.SmallIntVector" )
@@ -141,13 +148,19 @@ def register_interop_behavior():
141
148
float4_vector_class_path = java .type ("org.apache.arrow.vector.Float4Vector" )
142
149
float8_vector_class_path = java .type ("org.apache.arrow.vector.Float8Vector" )
143
150
144
- polyglot .register_interop_type (int8_vector_class_path , TinyIntVector )
145
- polyglot .register_interop_type (int16_vector_class_path , SmallIntVector )
146
- polyglot .register_interop_type (int32_vector_class_path , IntVector )
147
- polyglot .register_interop_type (int64_vector_class_path , BigIntVector )
148
-
149
- polyglot .register_interop_type (boolean_vector_class_path , BitVector )
150
-
151
- polyglot .register_interop_type (float2_vector_class_path , Float2Vector )
152
- polyglot .register_interop_type (float4_vector_class_path , Float4Vector )
153
- polyglot .register_interop_type (float8_vector_class_path , Float8Vector )
151
+ polyglot .register_interop_type (int8_vector_class_path , TinyIntVector ,
152
+ allow_method_overwrites = allow_method_overwrites )
153
+ polyglot .register_interop_type (int16_vector_class_path , SmallIntVector ,
154
+ allow_method_overwrites = allow_method_overwrites )
155
+ polyglot .register_interop_type (int32_vector_class_path , IntVector ,
156
+ allow_method_overwrites = allow_method_overwrites )
157
+ polyglot .register_interop_type (int64_vector_class_path , BigIntVector ,
158
+ allow_method_overwrites = allow_method_overwrites )
159
+ polyglot .register_interop_type (boolean_vector_class_path , BitVector ,
160
+ allow_method_overwrites = allow_method_overwrites )
161
+ polyglot .register_interop_type (float2_vector_class_path , Float2Vector ,
162
+ allow_method_overwrites = allow_method_overwrites )
163
+ polyglot .register_interop_type (float4_vector_class_path , Float4Vector ,
164
+ allow_method_overwrites = allow_method_overwrites )
165
+ polyglot .register_interop_type (float8_vector_class_path , Float8Vector ,
166
+ allow_method_overwrites = allow_method_overwrites )
0 commit comments