@@ -305,6 +305,16 @@ public void reset() {
305305 }
306306 }
307307
308+ public void checkNullable (Object [] batch , int rows ) {
309+ for (int i = 0 ; i < rows ; ++i ) {
310+ if (batch [i ] == null ) {
311+ throw new RuntimeException (
312+ "the result of " + i + " row is null, but the return type is not nullable, please check "
313+ + "the always_nullable property in create function statement, it's should be true" );
314+ }
315+ }
316+ }
317+
308318 public final boolean isNullAt (int rowId ) {
309319 if (numNulls == 0 || nullMap == 0 ) {
310320 return false ;
@@ -405,6 +415,7 @@ public void appendBoolean(Boolean[] batch, boolean isNullable) {
405415 }
406416 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
407417 } else {
418+ checkNullable (batch , rows );
408419 for (int i = 0 ; i < rows ; ++i ) {
409420 batchData [i ] = (byte ) (batch [i ] ? 1 : 0 );
410421 }
@@ -462,6 +473,7 @@ public void appendByte(Byte[] batch, boolean isNullable) {
462473 }
463474 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
464475 } else {
476+ checkNullable (batch , rows );
465477 for (int i = 0 ; i < rows ; ++i ) {
466478 batchData [i ] = batch [i ];
467479 }
@@ -519,6 +531,7 @@ public void appendShort(Short[] batch, boolean isNullable) {
519531 }
520532 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
521533 } else {
534+ checkNullable (batch , rows );
522535 for (int i = 0 ; i < rows ; ++i ) {
523536 batchData [i ] = batch [i ];
524537 }
@@ -576,6 +589,7 @@ public void appendInt(Integer[] batch, boolean isNullable) {
576589 }
577590 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
578591 } else {
592+ checkNullable (batch , rows );
579593 for (int i = 0 ; i < rows ; ++i ) {
580594 batchData [i ] = batch [i ];
581595 }
@@ -633,6 +647,7 @@ public void appendFloat(Float[] batch, boolean isNullable) {
633647 }
634648 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
635649 } else {
650+ checkNullable (batch , rows );
636651 for (int i = 0 ; i < rows ; ++i ) {
637652 batchData [i ] = batch [i ];
638653 }
@@ -690,6 +705,7 @@ public void appendLong(Long[] batch, boolean isNullable) {
690705 }
691706 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
692707 } else {
708+ checkNullable (batch , rows );
693709 for (int i = 0 ; i < rows ; ++i ) {
694710 batchData [i ] = batch [i ];
695711 }
@@ -747,6 +763,7 @@ public void appendDouble(Double[] batch, boolean isNullable) {
747763 }
748764 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
749765 } else {
766+ checkNullable (batch , rows );
750767 for (int i = 0 ; i < rows ; ++i ) {
751768 batchData [i ] = batch [i ];
752769 }
@@ -788,6 +805,9 @@ public int appendBigInteger(BigInteger v) {
788805 }
789806
790807 public void appendBigInteger (BigInteger [] batch , boolean isNullable ) {
808+ if (!isNullable ) {
809+ checkNullable (batch , batch .length );
810+ }
791811 reserve (appendIndex + batch .length );
792812 for (BigInteger v : batch ) {
793813 if (v == null ) {
@@ -834,6 +854,9 @@ public int appendDecimal(BigDecimal v) {
834854 }
835855
836856 public void appendDecimal (BigDecimal [] batch , boolean isNullable ) {
857+ if (!isNullable ) {
858+ checkNullable (batch , batch .length );
859+ }
837860 reserve (appendIndex + batch .length );
838861 for (BigDecimal v : batch ) {
839862 if (v == null ) {
@@ -880,6 +903,9 @@ public int appendDate(LocalDate v) {
880903 }
881904
882905 public void appendDate (LocalDate [] batch , boolean isNullable ) {
906+ if (!isNullable ) {
907+ checkNullable (batch , batch .length );
908+ }
883909 reserve (appendIndex + batch .length );
884910 for (LocalDate v : batch ) {
885911 if (v == null ) {
@@ -946,6 +972,9 @@ public int appendDateTime(LocalDateTime v) {
946972 }
947973
948974 public void appendDateTime (LocalDateTime [] batch , boolean isNullable ) {
975+ if (!isNullable ) {
976+ checkNullable (batch , batch .length );
977+ }
949978 reserve (appendIndex + batch .length );
950979 for (LocalDateTime v : batch ) {
951980 if (v == null ) {
@@ -1047,6 +1076,9 @@ public int appendStringAndOffset(String str) {
10471076 }
10481077
10491078 public void appendStringAndOffset (String [] batch , boolean isNullable ) {
1079+ if (!isNullable ) {
1080+ checkNullable (batch , batch .length );
1081+ }
10501082 reserve (appendIndex + batch .length );
10511083 for (String v : batch ) {
10521084 byte [] bytes ;
@@ -1063,6 +1095,9 @@ public void appendStringAndOffset(String[] batch, boolean isNullable) {
10631095 }
10641096
10651097 public void appendBinaryAndOffset (byte [][] batch , boolean isNullable ) {
1098+ if (!isNullable ) {
1099+ checkNullable (batch , batch .length );
1100+ }
10661101 reserve (appendIndex + batch .length );
10671102 for (byte [] v : batch ) {
10681103 byte [] bytes = v ;
@@ -1116,6 +1151,9 @@ public int appendArray(List<ColumnValue> values) {
11161151 }
11171152
11181153 public void appendArray (List <Object >[] batch , boolean isNullable ) {
1154+ if (!isNullable ) {
1155+ checkNullable (batch , batch .length );
1156+ }
11191157 reserve (appendIndex + batch .length );
11201158 int offset = childColumns [0 ].appendIndex ;
11211159 for (List <Object > v : batch ) {
@@ -1175,6 +1213,9 @@ public int appendMap(List<ColumnValue> keys, List<ColumnValue> values) {
11751213 }
11761214
11771215 public void appendMap (Map <Object , Object >[] batch , boolean isNullable ) {
1216+ if (!isNullable ) {
1217+ checkNullable (batch , batch .length );
1218+ }
11781219 reserve (appendIndex + batch .length );
11791220 int offset = childColumns [0 ].appendIndex ;
11801221 for (Map <Object , Object > v : batch ) {
@@ -1239,6 +1280,9 @@ public int appendStruct(List<Integer> structFieldIndex, List<ColumnValue> values
12391280 }
12401281
12411282 public void appendStruct (Map <String , Object >[] batch , boolean isNullable ) {
1283+ if (!isNullable ) {
1284+ checkNullable (batch , batch .length );
1285+ }
12421286 reserve (appendIndex + batch .length );
12431287 Object [][] columnData = new Object [childColumns .length ][];
12441288 for (int j = 0 ; j < childColumns .length ; ++j ) {
0 commit comments