|
1 | | -# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 | 3 | # |
4 | 4 | # The Universal Permissive License (UPL), Version 1.0 |
|
48 | 48 |
|
49 | 49 | if not __graalpython__.host_import_enabled: |
50 | 50 | raise NotImplementedError("Host lookup is not allowed. You can allow it while building python context.") |
51 | | -else: |
52 | | - class TinyIntVector: |
53 | 51 |
|
54 | | - def __len__(self): |
55 | | - return self.getValueCount() |
56 | 52 |
|
57 | | - def __arrow_c_array__(self, requested_schema=None): |
58 | | - return __graalpython__.export_arrow_vector(self) |
| 53 | +class TinyIntVector: |
59 | 54 |
|
| 55 | + def __len__(self): |
| 56 | + return self.getValueCount() |
60 | 57 |
|
61 | | - class SmallIntVector: |
| 58 | + def __arrow_c_array__(self, requested_schema=None): |
| 59 | + return __graalpython__.export_arrow_vector(self) |
62 | 60 |
|
63 | | - def __len__(self): |
64 | | - return self.getValueCount() |
65 | 61 |
|
66 | | - def __arrow_c_array__(self, requested_schema=None): |
67 | | - return __graalpython__.export_arrow_vector(self) |
| 62 | +class SmallIntVector: |
68 | 63 |
|
| 64 | + def __len__(self): |
| 65 | + return self.getValueCount() |
69 | 66 |
|
70 | | - class IntVector: |
| 67 | + def __arrow_c_array__(self, requested_schema=None): |
| 68 | + return __graalpython__.export_arrow_vector(self) |
71 | 69 |
|
72 | | - def __len__(self): |
73 | | - return self.getValueCount() |
74 | 70 |
|
75 | | - def __arrow_c_array__(self, requested_schema=None): |
76 | | - return __graalpython__.export_arrow_vector(self) |
| 71 | +class IntVector: |
77 | 72 |
|
| 73 | + def __len__(self): |
| 74 | + return self.getValueCount() |
78 | 75 |
|
79 | | - class BigIntVector: |
| 76 | + def __arrow_c_array__(self, requested_schema=None): |
| 77 | + return __graalpython__.export_arrow_vector(self) |
80 | 78 |
|
81 | | - def __len__(self): |
82 | | - return self.getValueCount() |
83 | 79 |
|
84 | | - def __arrow_c_array__(self, requested_schema=None): |
85 | | - return __graalpython__.export_arrow_vector(self) |
| 80 | +class BigIntVector: |
86 | 81 |
|
| 82 | + def __len__(self): |
| 83 | + return self.getValueCount() |
87 | 84 |
|
88 | | - class BitVector: |
| 85 | + def __arrow_c_array__(self, requested_schema=None): |
| 86 | + return __graalpython__.export_arrow_vector(self) |
89 | 87 |
|
90 | | - def __len__(self): |
91 | | - return self.getValueCount() |
92 | 88 |
|
93 | | - def __arrow_c_array__(self, requested_schema=None): |
94 | | - return __graalpython__.export_arrow_vector(self) |
| 89 | +class BitVector: |
95 | 90 |
|
| 91 | + def __len__(self): |
| 92 | + return self.getValueCount() |
96 | 93 |
|
97 | | - class Float2Vector: |
| 94 | + def __arrow_c_array__(self, requested_schema=None): |
| 95 | + return __graalpython__.export_arrow_vector(self) |
98 | 96 |
|
99 | | - def __len__(self): |
100 | | - return self.getValueCount() |
101 | 97 |
|
102 | | - def __arrow_c_array__(self, requested_schema=None): |
103 | | - return __graalpython__.export_arrow_vector(self) |
| 98 | +class Float2Vector: |
104 | 99 |
|
| 100 | + def __len__(self): |
| 101 | + return self.getValueCount() |
105 | 102 |
|
106 | | - class Float4Vector: |
| 103 | + def __arrow_c_array__(self, requested_schema=None): |
| 104 | + return __graalpython__.export_arrow_vector(self) |
107 | 105 |
|
108 | | - def __len__(self): |
109 | | - return self.getValueCount() |
110 | 106 |
|
111 | | - def __arrow_c_array__(self, requested_schema=None): |
112 | | - return __graalpython__.export_arrow_vector(self) |
| 107 | +class Float4Vector: |
113 | 108 |
|
| 109 | + def __len__(self): |
| 110 | + return self.getValueCount() |
114 | 111 |
|
115 | | - class Float8Vector: |
| 112 | + def __arrow_c_array__(self, requested_schema=None): |
| 113 | + return __graalpython__.export_arrow_vector(self) |
116 | 114 |
|
117 | | - def __len__(self): |
118 | | - return self.getValueCount() |
119 | 115 |
|
120 | | - def __arrow_c_array__(self, requested_schema=None): |
121 | | - return __graalpython__.export_arrow_vector(self) |
| 116 | +class Float8Vector: |
| 117 | + |
| 118 | + def __len__(self): |
| 119 | + return self.getValueCount() |
| 120 | + |
| 121 | + def __arrow_c_array__(self, requested_schema=None): |
| 122 | + return __graalpython__.export_arrow_vector(self) |
| 123 | + |
| 124 | + |
| 125 | +__interop_registered = False |
122 | 126 |
|
123 | 127 |
|
124 | 128 | def register_interop_behavior(): |
125 | | - # Ints |
126 | | - int8_vector_class_path = java.type("org.apache.arrow.vector.TinyIntVector") |
127 | | - int16_vector_class_path = java.type("org.apache.arrow.vector.SmallIntVector") |
128 | | - int32_vector_class_path = java.type("org.apache.arrow.vector.IntVector") |
129 | | - int64_vector_class_path = java.type("org.apache.arrow.vector.BigIntVector") |
130 | | - # Boolean |
131 | | - boolean_vector_class_path = java.type("org.apache.arrow.vector.BitVector") |
132 | | - # Floats |
133 | | - float2_vector_class_path = java.type("org.apache.arrow.vector.Float2Vector") |
134 | | - float4_vector_class_path = java.type("org.apache.arrow.vector.Float4Vector") |
135 | | - float8_vector_class_path = java.type("org.apache.arrow.vector.Float8Vector") |
136 | | - |
137 | | - polyglot.register_interop_type(int8_vector_class_path, TinyIntVector) |
138 | | - polyglot.register_interop_type(int16_vector_class_path, SmallIntVector) |
139 | | - polyglot.register_interop_type(int32_vector_class_path, IntVector) |
140 | | - polyglot.register_interop_type(int64_vector_class_path, BigIntVector) |
141 | | - |
142 | | - polyglot.register_interop_type(boolean_vector_class_path, BitVector) |
143 | | - |
144 | | - polyglot.register_interop_type(float2_vector_class_path, Float2Vector) |
145 | | - polyglot.register_interop_type(float4_vector_class_path, Float4Vector) |
146 | | - polyglot.register_interop_type(float8_vector_class_path, Float8Vector) |
| 129 | + global __interop_registered |
| 130 | + if not __interop_registered: |
| 131 | + __interop_registered = True |
| 132 | + # Ints |
| 133 | + int8_vector_class_path = java.type("org.apache.arrow.vector.TinyIntVector") |
| 134 | + int16_vector_class_path = java.type("org.apache.arrow.vector.SmallIntVector") |
| 135 | + int32_vector_class_path = java.type("org.apache.arrow.vector.IntVector") |
| 136 | + int64_vector_class_path = java.type("org.apache.arrow.vector.BigIntVector") |
| 137 | + # Boolean |
| 138 | + boolean_vector_class_path = java.type("org.apache.arrow.vector.BitVector") |
| 139 | + # Floats |
| 140 | + float2_vector_class_path = java.type("org.apache.arrow.vector.Float2Vector") |
| 141 | + float4_vector_class_path = java.type("org.apache.arrow.vector.Float4Vector") |
| 142 | + float8_vector_class_path = java.type("org.apache.arrow.vector.Float8Vector") |
| 143 | + |
| 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) |
0 commit comments