@@ -310,6 +310,16 @@ public void reset() {
310310 }
311311 }
312312
313+ public void checkNullable (Object [] batch , int rows ) {
314+ for (int i = 0 ; i < rows ; ++i ) {
315+ if (batch [i ] == null ) {
316+ throw new RuntimeException (
317+ "the result of " + i + " row is null, but the return type is not nullable, please check "
318+ + "the always_nullable property in create function statement, it's should be true" );
319+ }
320+ }
321+ }
322+
313323 public final boolean isNullAt (int rowId ) {
314324 if (numNulls == 0 || nullMap == 0 ) {
315325 return false ;
@@ -410,6 +420,7 @@ public void appendBoolean(Boolean[] batch, boolean isNullable) {
410420 }
411421 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
412422 } else {
423+ checkNullable (batch , rows );
413424 for (int i = 0 ; i < rows ; ++i ) {
414425 batchData [i ] = (byte ) (batch [i ] ? 1 : 0 );
415426 }
@@ -467,6 +478,7 @@ public void appendByte(Byte[] batch, boolean isNullable) {
467478 }
468479 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
469480 } else {
481+ checkNullable (batch , rows );
470482 for (int i = 0 ; i < rows ; ++i ) {
471483 batchData [i ] = batch [i ];
472484 }
@@ -524,6 +536,7 @@ public void appendShort(Short[] batch, boolean isNullable) {
524536 }
525537 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
526538 } else {
539+ checkNullable (batch , rows );
527540 for (int i = 0 ; i < rows ; ++i ) {
528541 batchData [i ] = batch [i ];
529542 }
@@ -581,6 +594,7 @@ public void appendInt(Integer[] batch, boolean isNullable) {
581594 }
582595 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
583596 } else {
597+ checkNullable (batch , rows );
584598 for (int i = 0 ; i < rows ; ++i ) {
585599 batchData [i ] = batch [i ];
586600 }
@@ -638,6 +652,7 @@ public void appendFloat(Float[] batch, boolean isNullable) {
638652 }
639653 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
640654 } else {
655+ checkNullable (batch , rows );
641656 for (int i = 0 ; i < rows ; ++i ) {
642657 batchData [i ] = batch [i ];
643658 }
@@ -695,6 +710,7 @@ public void appendLong(Long[] batch, boolean isNullable) {
695710 }
696711 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
697712 } else {
713+ checkNullable (batch , rows );
698714 for (int i = 0 ; i < rows ; ++i ) {
699715 batchData [i ] = batch [i ];
700716 }
@@ -752,6 +768,7 @@ public void appendDouble(Double[] batch, boolean isNullable) {
752768 }
753769 OffHeap .UNSAFE .copyMemory (batchNulls , OffHeap .BYTE_ARRAY_OFFSET , null , nullMap + appendIndex , rows );
754770 } else {
771+ checkNullable (batch , rows );
755772 for (int i = 0 ; i < rows ; ++i ) {
756773 batchData [i ] = batch [i ];
757774 }
@@ -793,6 +810,9 @@ public int appendBigInteger(BigInteger v) {
793810 }
794811
795812 public void appendBigInteger (BigInteger [] batch , boolean isNullable ) {
813+ if (!isNullable ) {
814+ checkNullable (batch , batch .length );
815+ }
796816 reserve (appendIndex + batch .length );
797817 for (BigInteger v : batch ) {
798818 if (v == null ) {
@@ -839,6 +859,9 @@ public int appendDecimal(BigDecimal v) {
839859 }
840860
841861 public void appendDecimal (BigDecimal [] batch , boolean isNullable ) {
862+ if (!isNullable ) {
863+ checkNullable (batch , batch .length );
864+ }
842865 reserve (appendIndex + batch .length );
843866 for (BigDecimal v : batch ) {
844867 if (v == null ) {
@@ -885,6 +908,9 @@ public int appendDate(LocalDate v) {
885908 }
886909
887910 public void appendDate (LocalDate [] batch , boolean isNullable ) {
911+ if (!isNullable ) {
912+ checkNullable (batch , batch .length );
913+ }
888914 reserve (appendIndex + batch .length );
889915 for (LocalDate v : batch ) {
890916 if (v == null ) {
@@ -951,6 +977,9 @@ public int appendDateTime(LocalDateTime v) {
951977 }
952978
953979 public void appendDateTime (LocalDateTime [] batch , boolean isNullable ) {
980+ if (!isNullable ) {
981+ checkNullable (batch , batch .length );
982+ }
954983 reserve (appendIndex + batch .length );
955984 for (LocalDateTime v : batch ) {
956985 if (v == null ) {
@@ -1052,6 +1081,9 @@ public int appendStringAndOffset(String str) {
10521081 }
10531082
10541083 public void appendStringAndOffset (String [] batch , boolean isNullable ) {
1084+ if (!isNullable ) {
1085+ checkNullable (batch , batch .length );
1086+ }
10551087 reserve (appendIndex + batch .length );
10561088 for (String v : batch ) {
10571089 byte [] bytes ;
@@ -1068,6 +1100,9 @@ public void appendStringAndOffset(String[] batch, boolean isNullable) {
10681100 }
10691101
10701102 public void appendBinaryAndOffset (byte [][] batch , boolean isNullable ) {
1103+ if (!isNullable ) {
1104+ checkNullable (batch , batch .length );
1105+ }
10711106 reserve (appendIndex + batch .length );
10721107 for (byte [] v : batch ) {
10731108 byte [] bytes = v ;
@@ -1121,6 +1156,9 @@ public int appendArray(List<ColumnValue> values) {
11211156 }
11221157
11231158 public void appendArray (List <Object >[] batch , boolean isNullable ) {
1159+ if (!isNullable ) {
1160+ checkNullable (batch , batch .length );
1161+ }
11241162 reserve (appendIndex + batch .length );
11251163 int offset = childColumns [0 ].appendIndex ;
11261164 for (List <Object > v : batch ) {
@@ -1181,6 +1219,9 @@ public int appendMap(List<ColumnValue> keys, List<ColumnValue> values) {
11811219 }
11821220
11831221 public void appendMap (Map <Object , Object >[] batch , boolean isNullable ) {
1222+ if (!isNullable ) {
1223+ checkNullable (batch , batch .length );
1224+ }
11841225 reserve (appendIndex + batch .length );
11851226 int offset = childColumns [0 ].appendIndex ;
11861227 for (Map <Object , Object > v : batch ) {
@@ -1247,6 +1288,9 @@ public int appendStruct(List<Integer> structFieldIndex, List<ColumnValue> values
12471288 }
12481289
12491290 public void appendStruct (Map <String , Object >[] batch , boolean isNullable ) {
1291+ if (!isNullable ) {
1292+ checkNullable (batch , batch .length );
1293+ }
12501294 reserve (appendIndex + batch .length );
12511295 Object [][] columnData = new Object [childColumns .length ][];
12521296 Preconditions .checkArgument (this .getColumnType ().getChildNames ().size () == childColumns .length );
0 commit comments