3232
3333import java .io .ByteArrayInputStream ;
3434import java .util .List ;
35- import java .util .Objects ;
3635import java .util .stream .Collectors ;
3736
3837/** Write Arrow bytes to Paimon. */
@@ -53,11 +52,11 @@ public BytesWriter(TableWrite tableWrite, RowType rowType) {
5352 .collect (Collectors .toList ());
5453 }
5554
56- public void write (byte [] bytes , boolean needCheckSchema ) throws Exception {
55+ public void write (byte [] bytes ) throws Exception {
5756 ByteArrayInputStream bais = new ByteArrayInputStream (bytes );
5857 ArrowStreamReader arrowStreamReader = new ArrowStreamReader (bais , allocator );
5958 VectorSchemaRoot vsr = arrowStreamReader .getVectorSchemaRoot ();
60- if (needCheckSchema && ! checkSchema (arrowFields , vsr .getSchema ().getFields ())) {
59+ if (! checkTypesIgnoreNullability (arrowFields , vsr .getSchema ().getFields ())) {
6160 throw new RuntimeException (
6261 String .format (
6362 "Input schema isn't consistent with table schema.\n "
@@ -79,25 +78,22 @@ public void close() {
7978 allocator .close ();
8079 }
8180
82- private boolean checkSchema (List <Field > expectedFields , List <Field > actualFields ) {
81+ private boolean checkTypesIgnoreNullability (
82+ List <Field > expectedFields , List <Field > actualFields ) {
8383 if (expectedFields .size () != actualFields .size ()) {
8484 return false ;
8585 }
8686
8787 for (int i = 0 ; i < expectedFields .size (); i ++) {
8888 Field expectedField = expectedFields .get (i );
8989 Field actualField = actualFields .get (i );
90- if (!checkFieldIgnoreNullability (expectedField , actualField )
90+ // ArrowType doesn't have nullability (similar to DataTypeRoot)
91+ if (!actualField .getType ().equals (expectedField .getType ())
9192 || !checkSchema (expectedField .getChildren (), actualField .getChildren ())) {
9293 return false ;
9394 }
9495 }
9596
9697 return true ;
9798 }
98-
99- private boolean checkFieldIgnoreNullability (Field expected , Field actual ) {
100- return Objects .equals (expected .getName (), actual .getName ())
101- && Objects .equals (expected .getType (), actual .getType ());
102- }
10399}
0 commit comments