File tree Expand file tree Collapse file tree
main/java/org/apache/datafusion
test/java/org/apache/datafusion Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,6 +81,9 @@ public CsvReadOptions newlinesInValues(boolean v) {
8181 }
8282
8383 public CsvReadOptions schemaInferMaxRecords (long n ) {
84+ if (n < 0 ) {
85+ throw new IllegalArgumentException ("schemaInferMaxRecords must be non-negative, got " + n );
86+ }
8487 this .schemaInferMaxRecords = n ;
8588 return this ;
8689 }
Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ public NdJsonReadOptions fileCompressionType(FileCompressionType t) {
4949 }
5050
5151 public NdJsonReadOptions schemaInferMaxRecords (long n ) {
52+ if (n < 0 ) {
53+ throw new IllegalArgumentException ("schemaInferMaxRecords must be non-negative, got " + n );
54+ }
5255 this .schemaInferMaxRecords = n ;
5356 return this ;
5457 }
Original file line number Diff line number Diff line change 2222import static org .junit .jupiter .api .Assertions .assertEquals ;
2323import static org .junit .jupiter .api .Assertions .assertFalse ;
2424import static org .junit .jupiter .api .Assertions .assertSame ;
25+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2526import static org .junit .jupiter .api .Assertions .assertTrue ;
2627
2728import java .util .List ;
@@ -107,4 +108,14 @@ void allCompressionTypesMapThroughProto() throws InvalidProtocolBufferException
107108 "mismatch for " + t );
108109 }
109110 }
111+
112+ @ Test
113+ void schemaInferMaxRecordsRejectsNegative () {
114+ // The proto wire field is uint64, so a negative long would be reinterpreted
115+ // as a huge unsigned value on the Rust side and silently expand schema
116+ // inference across the full dataset. Reject at the Java setter instead.
117+ CsvReadOptions opts = new CsvReadOptions ();
118+ assertThrows (IllegalArgumentException .class , () -> opts .schemaInferMaxRecords (-1L ));
119+ assertThrows (IllegalArgumentException .class , () -> opts .schemaInferMaxRecords (Long .MIN_VALUE ));
120+ }
110121}
Original file line number Diff line number Diff line change 2222import static org .junit .jupiter .api .Assertions .assertEquals ;
2323import static org .junit .jupiter .api .Assertions .assertFalse ;
2424import static org .junit .jupiter .api .Assertions .assertSame ;
25+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2526
2627import java .util .List ;
2728
@@ -85,4 +86,14 @@ void allCompressionTypesMapThroughProto() throws InvalidProtocolBufferException
8586 "mismatch for " + t );
8687 }
8788 }
89+
90+ @ Test
91+ void schemaInferMaxRecordsRejectsNegative () {
92+ // The proto wire field is uint64, so a negative long would be reinterpreted
93+ // as a huge unsigned value on the Rust side and silently expand schema
94+ // inference across the full dataset. Reject at the Java setter instead.
95+ NdJsonReadOptions opts = new NdJsonReadOptions ();
96+ assertThrows (IllegalArgumentException .class , () -> opts .schemaInferMaxRecords (-1L ));
97+ assertThrows (IllegalArgumentException .class , () -> opts .schemaInferMaxRecords (Long .MIN_VALUE ));
98+ }
8899}
You can’t perform that action at this time.
0 commit comments