46
46
import org .apache .arrow .vector .complex .reader .FieldReader ;
47
47
import org .apache .arrow .vector .ipc .ArrowReader ;
48
48
import org .apache .arrow .vector .ipc .ArrowStreamReader ;
49
- import org .apache .arrow .vector .types .Types ;
49
+ import org .apache .arrow .vector .types .Types . MinorType ;
50
50
import org .apache .doris .flink .exception .DorisException ;
51
51
import org .apache .doris .flink .exception .DorisRuntimeException ;
52
52
import org .apache .doris .flink .rest .models .Schema ;
@@ -177,7 +177,7 @@ public RowBatch readArrow() {
177
177
throw new DorisException (
178
178
"Load Doris data failed, schema size of fetch data is wrong." );
179
179
}
180
- if (fieldVectors .size () == 0 || root .getRowCount () == 0 ) {
180
+ if (fieldVectors .isEmpty () || root .getRowCount () == 0 ) {
181
181
logger .debug ("One batch in arrow has no data." );
182
182
continue ;
183
183
}
@@ -217,12 +217,12 @@ public void convertArrowToRowBatch() throws DorisException {
217
217
try {
218
218
for (int col = 0 ; col < fieldVectors .size (); col ++) {
219
219
FieldVector fieldVector = fieldVectors .get (col );
220
- Types . MinorType minorType = fieldVector .getMinorType ();
220
+ MinorType minorType = fieldVector .getMinorType ();
221
221
final String currentType = schema .get (col ).getType ();
222
222
for (int rowIndex = 0 ; rowIndex < rowCountInOneBatch ; rowIndex ++) {
223
223
boolean passed = doConvert (col , rowIndex , minorType , currentType , fieldVector );
224
224
if (!passed ) {
225
- throw new java . lang . IllegalArgumentException (
225
+ throw new IllegalArgumentException (
226
226
"FLINK type is "
227
227
+ currentType
228
228
+ ", but arrow type is "
@@ -239,17 +239,13 @@ public void convertArrowToRowBatch() throws DorisException {
239
239
240
240
@ VisibleForTesting
241
241
public boolean doConvert (
242
- int col ,
243
- int rowIndex ,
244
- Types .MinorType minorType ,
245
- String currentType ,
246
- FieldVector fieldVector )
242
+ int col , int rowIndex , MinorType minorType , String currentType , FieldVector fieldVector )
247
243
throws DorisException {
248
244
switch (currentType ) {
249
245
case "NULL_TYPE" :
250
246
break ;
251
247
case "BOOLEAN" :
252
- if (!minorType .equals (Types . MinorType .BIT )) {
248
+ if (!minorType .equals (MinorType .BIT )) {
253
249
return false ;
254
250
}
255
251
BitVector bitVector = (BitVector ) fieldVector ;
@@ -258,57 +254,71 @@ public boolean doConvert(
258
254
addValueToRow (rowIndex , fieldValue );
259
255
break ;
260
256
case "TINYINT" :
261
- if (!minorType .equals (Types . MinorType .TINYINT )) {
257
+ if (!minorType .equals (MinorType .TINYINT )) {
262
258
return false ;
263
259
}
264
260
TinyIntVector tinyIntVector = (TinyIntVector ) fieldVector ;
265
261
fieldValue = tinyIntVector .isNull (rowIndex ) ? null : tinyIntVector .get (rowIndex );
266
262
addValueToRow (rowIndex , fieldValue );
267
263
break ;
268
264
case "SMALLINT" :
269
- if (!minorType .equals (Types . MinorType .SMALLINT )) {
265
+ if (!minorType .equals (MinorType .SMALLINT )) {
270
266
return false ;
271
267
}
272
268
SmallIntVector smallIntVector = (SmallIntVector ) fieldVector ;
273
269
fieldValue = smallIntVector .isNull (rowIndex ) ? null : smallIntVector .get (rowIndex );
274
270
addValueToRow (rowIndex , fieldValue );
275
271
break ;
276
272
case "INT" :
277
- if (!minorType .equals (Types . MinorType .INT )) {
273
+ if (!minorType .equals (MinorType .INT )) {
278
274
return false ;
279
275
}
280
276
IntVector intVector = (IntVector ) fieldVector ;
281
277
fieldValue = intVector .isNull (rowIndex ) ? null : intVector .get (rowIndex );
282
278
addValueToRow (rowIndex , fieldValue );
283
279
break ;
284
280
case "IPV4" :
285
- if (!minorType .equals (Types .MinorType .UINT4 )
286
- && !minorType .equals (Types .MinorType .INT )) {
281
+ if (!minorType .equals (MinorType .UINT4 )
282
+ && !minorType .equals (MinorType .INT )
283
+ && !minorType .equals (MinorType .VARCHAR )) {
287
284
return false ;
288
285
}
289
- BaseIntVector ipv4Vector ;
290
- if (minorType .equals (Types .MinorType .INT )) {
291
- ipv4Vector = (IntVector ) fieldVector ;
292
286
287
+ if (fieldVector .isNull (rowIndex )) {
288
+ addValueToRow (rowIndex , null );
289
+ break ;
290
+ }
291
+
292
+ if (minorType .equals (MinorType .VARCHAR )) {
293
+ VarCharVector ipv4VarcharVector = (VarCharVector ) fieldVector ;
294
+ String ipv4Str =
295
+ new String (ipv4VarcharVector .get (rowIndex ), StandardCharsets .UTF_8 );
296
+ addValueToRow (rowIndex , ipv4Str );
293
297
} else {
294
- ipv4Vector = (UInt4Vector ) fieldVector ;
298
+ BaseIntVector ipv4Vector ;
299
+ if (minorType .equals (MinorType .INT )) {
300
+ ipv4Vector = (IntVector ) fieldVector ;
301
+
302
+ } else {
303
+ ipv4Vector = (UInt4Vector ) fieldVector ;
304
+ }
305
+ fieldValue =
306
+ ipv4Vector .isNull (rowIndex )
307
+ ? null
308
+ : convertLongToIPv4Address (ipv4Vector .getValueAsLong (rowIndex ));
309
+ addValueToRow (rowIndex , fieldValue );
295
310
}
296
- fieldValue =
297
- ipv4Vector .isNull (rowIndex )
298
- ? null
299
- : convertLongToIPv4Address (ipv4Vector .getValueAsLong (rowIndex ));
300
- addValueToRow (rowIndex , fieldValue );
301
311
break ;
302
312
case "BIGINT" :
303
- if (!minorType .equals (Types . MinorType .BIGINT )) {
313
+ if (!minorType .equals (MinorType .BIGINT )) {
304
314
return false ;
305
315
}
306
316
BigIntVector bigIntVector = (BigIntVector ) fieldVector ;
307
317
fieldValue = bigIntVector .isNull (rowIndex ) ? null : bigIntVector .get (rowIndex );
308
318
addValueToRow (rowIndex , fieldValue );
309
319
break ;
310
320
case "FLOAT" :
311
- if (!minorType .equals (Types . MinorType .FLOAT4 )) {
321
+ if (!minorType .equals (MinorType .FLOAT4 )) {
312
322
return false ;
313
323
}
314
324
Float4Vector float4Vector = (Float4Vector ) fieldVector ;
@@ -317,15 +327,15 @@ public boolean doConvert(
317
327
break ;
318
328
case "TIME" :
319
329
case "DOUBLE" :
320
- if (!minorType .equals (Types . MinorType .FLOAT8 )) {
330
+ if (!minorType .equals (MinorType .FLOAT8 )) {
321
331
return false ;
322
332
}
323
333
Float8Vector float8Vector = (Float8Vector ) fieldVector ;
324
334
fieldValue = float8Vector .isNull (rowIndex ) ? null : float8Vector .get (rowIndex );
325
335
addValueToRow (rowIndex , fieldValue );
326
336
break ;
327
337
case "BINARY" :
328
- if (!minorType .equals (Types . MinorType .VARBINARY )) {
338
+ if (!minorType .equals (MinorType .VARBINARY )) {
329
339
return false ;
330
340
}
331
341
VarBinaryVector varBinaryVector = (VarBinaryVector ) fieldVector ;
@@ -339,7 +349,7 @@ public boolean doConvert(
339
349
case "DECIMAL64" :
340
350
case "DECIMAL128I" :
341
351
case "DECIMAL128" :
342
- if (!minorType .equals (Types . MinorType .DECIMAL )) {
352
+ if (!minorType .equals (MinorType .DECIMAL )) {
343
353
return false ;
344
354
}
345
355
DecimalVector decimalVector = (DecimalVector ) fieldVector ;
@@ -352,11 +362,10 @@ public boolean doConvert(
352
362
break ;
353
363
case "DATE" :
354
364
case "DATEV2" :
355
- if (!minorType .equals (Types .MinorType .DATEDAY )
356
- && !minorType .equals (Types .MinorType .VARCHAR )) {
365
+ if (!minorType .equals (MinorType .DATEDAY ) && !minorType .equals (MinorType .VARCHAR )) {
357
366
return false ;
358
367
}
359
- if (minorType .equals (Types . MinorType .VARCHAR )) {
368
+ if (minorType .equals (MinorType .VARCHAR )) {
360
369
VarCharVector date = (VarCharVector ) fieldVector ;
361
370
if (date .isNull (rowIndex )) {
362
371
addValueToRow (rowIndex , null );
@@ -376,7 +385,7 @@ public boolean doConvert(
376
385
}
377
386
break ;
378
387
case "DATETIME" :
379
- if (minorType .equals (Types . MinorType .VARCHAR )) {
388
+ if (minorType .equals (MinorType .VARCHAR )) {
380
389
VarCharVector varCharVector = (VarCharVector ) fieldVector ;
381
390
if (varCharVector .isNull (rowIndex )) {
382
391
addValueToRow (rowIndex , null );
@@ -400,7 +409,7 @@ public boolean doConvert(
400
409
}
401
410
break ;
402
411
case "DATETIMEV2" :
403
- if (minorType .equals (Types . MinorType .VARCHAR )) {
412
+ if (minorType .equals (MinorType .VARCHAR )) {
404
413
VarCharVector varCharVector = (VarCharVector ) fieldVector ;
405
414
if (varCharVector .isNull (rowIndex )) {
406
415
addValueToRow (rowIndex , null );
@@ -424,11 +433,11 @@ public boolean doConvert(
424
433
}
425
434
break ;
426
435
case "LARGEINT" :
427
- if (!minorType .equals (Types . MinorType .FIXEDSIZEBINARY )
428
- && !minorType .equals (Types . MinorType .VARCHAR )) {
436
+ if (!minorType .equals (MinorType .FIXEDSIZEBINARY )
437
+ && !minorType .equals (MinorType .VARCHAR )) {
429
438
return false ;
430
439
}
431
- if (minorType .equals (Types . MinorType .FIXEDSIZEBINARY )) {
440
+ if (minorType .equals (MinorType .FIXEDSIZEBINARY )) {
432
441
FixedSizeBinaryVector largeIntVector = (FixedSizeBinaryVector ) fieldVector ;
433
442
if (largeIntVector .isNull (rowIndex )) {
434
443
addValueToRow (rowIndex , null );
@@ -464,7 +473,7 @@ public boolean doConvert(
464
473
case "JSONB" :
465
474
case "JSON" :
466
475
case "VARIANT" :
467
- if (!minorType .equals (Types . MinorType .VARCHAR )) {
476
+ if (!minorType .equals (MinorType .VARCHAR )) {
468
477
return false ;
469
478
}
470
479
VarCharVector varCharVector = (VarCharVector ) fieldVector ;
@@ -477,21 +486,27 @@ public boolean doConvert(
477
486
addValueToRow (rowIndex , stringValue );
478
487
break ;
479
488
case "IPV6" :
480
- if (!minorType .equals (Types . MinorType .VARCHAR )) {
489
+ if (!minorType .equals (MinorType .VARCHAR )) {
481
490
return false ;
482
491
}
483
- VarCharVector ipv6VarcharVector = ( VarCharVector ) fieldVector ;
484
- if (ipv6VarcharVector .isNull (rowIndex )) {
492
+
493
+ if (fieldVector .isNull (rowIndex )) {
485
494
addValueToRow (rowIndex , null );
486
495
break ;
487
496
}
497
+
498
+ VarCharVector ipv6VarcharVector = (VarCharVector ) fieldVector ;
488
499
String ipv6Str =
489
500
new String (ipv6VarcharVector .get (rowIndex ), StandardCharsets .UTF_8 );
490
- String ipv6Address = IPUtils .fromBigInteger (new BigInteger (ipv6Str ));
491
- addValueToRow (rowIndex , ipv6Address );
501
+ if (ipv6Str .contains (":" )) {
502
+ addValueToRow (rowIndex , ipv6Str );
503
+ } else {
504
+ String ipv6Address = IPUtils .fromBigInteger (new BigInteger (ipv6Str ));
505
+ addValueToRow (rowIndex , ipv6Address );
506
+ }
492
507
break ;
493
508
case "ARRAY" :
494
- if (!minorType .equals (Types . MinorType .LIST )) {
509
+ if (!minorType .equals (MinorType .LIST )) {
495
510
return false ;
496
511
}
497
512
ListVector listVector = (ListVector ) fieldVector ;
@@ -501,7 +516,7 @@ public boolean doConvert(
501
516
addValueToRow (rowIndex , listValue );
502
517
break ;
503
518
case "MAP" :
504
- if (!minorType .equals (Types . MinorType .MAP )) {
519
+ if (!minorType .equals (MinorType .MAP )) {
505
520
return false ;
506
521
}
507
522
MapVector mapVector = (MapVector ) fieldVector ;
@@ -522,7 +537,7 @@ public boolean doConvert(
522
537
addValueToRow (rowIndex , mapValue );
523
538
break ;
524
539
case "STRUCT" :
525
- if (!minorType .equals (Types . MinorType .STRUCT )) {
540
+ if (!minorType .equals (MinorType .STRUCT )) {
526
541
return false ;
527
542
}
528
543
StructVector structVector = (StructVector ) fieldVector ;
@@ -627,7 +642,7 @@ public List<Object> next() {
627
642
return rowBatch .get (offsetInRowBatch ++).getCols ();
628
643
}
629
644
630
- private String typeMismatchMessage (final String flinkType , final Types . MinorType arrowType ) {
645
+ private String typeMismatchMessage (final String flinkType , final MinorType arrowType ) {
631
646
final String messageTemplate = "FLINK type is %1$s, but arrow type is %2$s." ;
632
647
return String .format (messageTemplate , flinkType , arrowType .name ());
633
648
}
0 commit comments