@@ -148,7 +148,7 @@ Java Component:
148
148
In the Java component, the MapValuesConsumer class receives data from the Python component through C Data.
149
149
It then updates the data and sends it back to the Python component.
150
150
151
- .. code-block :: java
151
+ .. testcode :: java
152
152
153
153
import org.apache.arrow.c.ArrowArray;
154
154
import org.apache.arrow.c.ArrowSchema;
@@ -164,6 +164,8 @@ Java Component:
164
164
private final static BufferAllocator allocator = new RootAllocator();
165
165
private final CDataDictionaryProvider provider;
166
166
private FieldVector vector;
167
+ private final static BigIntVector intVector = new BigIntVector("internal_test_vector", allocator);
168
+
167
169
168
170
public MapValuesConsumer(CDataDictionaryProvider provider) {
169
171
this.provider = provider;
@@ -184,13 +186,64 @@ Java Component:
184
186
this.doWorkInJava(vector);
185
187
}
186
188
189
+ public FieldVector updateFromJava(long c_array_ptr, long c_schema_ptr) {
190
+ ArrowArray arrow_array = ArrowArray.wrap(c_array_ptr);
191
+ ArrowSchema arrow_schema = ArrowSchema.wrap(c_schema_ptr);
192
+ vector = Data.importVector(allocator, arrow_array, arrow_schema, null);
193
+ this.doWorkInJava(vector);
194
+ return vector;
195
+ }
196
+
187
197
private void doWorkInJava(FieldVector vector) {
188
198
System.out.println("Doing work in Java");
189
199
BigIntVector bigIntVector = (BigIntVector)vector;
190
200
bigIntVector.setSafe(0, 2);
191
201
}
202
+
203
+ private static BigIntVector getIntVectorForJavaConsumers() {
204
+ intVector.allocateNew(3);
205
+ intVector.set(0, 1);
206
+ intVector.set(1, 7);
207
+ intVector.set(2, 93);
208
+ intVector.setValueCount(3);
209
+ return intVector;
210
+ }
211
+
212
+ public static void simulateAsAJavaConsumers() {
213
+ CDataDictionaryProvider provider = new CDataDictionaryProvider();
214
+ MapValueConsumerV2 mvc = new MapValueConsumerV2(provider);//FIXME! Use constructor with dictionary provider
215
+ try (
216
+ ArrowArray arrowArray = ArrowArray.allocateNew(allocator);
217
+ ArrowSchema arrowSchema = ArrowSchema.allocateNew(allocator)
218
+ ) {
219
+ Data.exportVector(allocator, getIntVectorForJavaConsumers(), provider, arrowArray, arrowSchema);
220
+ FieldVector updatedVector = mvc.updateFromJava(arrowArray.memoryAddress(), arrowSchema.memoryAddress());
221
+ try (ArrowArray usedArray = ArrowArray.allocateNew(allocator);
222
+ ArrowSchema usedSchema = ArrowSchema.allocateNew(allocator)) {
223
+ Data.exportVector(allocator, updatedVector, provider, usedArray, usedSchema);
224
+ try(FieldVector valueVectors = Data.importVector(allocator, usedArray, usedSchema, provider)) {
225
+ System.out.println(valueVectors);
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ public static void close() {
232
+ intVector.close();
233
+ }
234
+
235
+ public static void main(String[] args) {
236
+ simulateAsAJavaConsumers();
237
+ close();
238
+ }
192
239
}
193
240
241
+ .. testoutput ::
242
+
243
+ Doing work in Java
244
+ [2, 7, 93]
245
+
246
+
194
247
The Java component performs the following actions:
195
248
196
249
1. Receives data from the Python component.
0 commit comments