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 ;
3132import org .apache .arrow .vector .types .pojo .FieldType ;
3233import org .apache .arrow .vector .types .pojo .Schema ;
3334import org .apache .datafusion .protobuf .CsvReadOptionsProto ;
34- import org .apache .datafusion .protobuf .FileCompressionType ;
3535import org .junit .jupiter .api .Test ;
3636
3737import com .google .protobuf .InvalidProtocolBufferException ;
@@ -47,7 +47,8 @@ void defaultsRoundTripThroughProto() throws InvalidProtocolBufferException {
4747 assertEquals ((int ) '"' , p .getQuote ());
4848 assertEquals (".csv" , p .getFileExtension ());
4949 assertEquals (
50- FileCompressionType .FILE_COMPRESSION_TYPE_UNCOMPRESSED , p .getFileCompressionType ());
50+ org .apache .datafusion .protobuf .FileCompressionType .FILE_COMPRESSION_TYPE_UNCOMPRESSED ,
51+ p .getFileCompressionType ());
5152
5253 assertFalse (p .hasTerminator ());
5354 assertFalse (p .hasEscape ());
@@ -69,7 +70,7 @@ void fullyConfiguredRoundTripsThroughProto() throws InvalidProtocolBufferExcepti
6970 .newlinesInValues (true )
7071 .schemaInferMaxRecords (10L )
7172 .fileExtension (".tsv" )
72- .fileCompressionType (CsvReadOptions . FileCompressionType .GZIP );
73+ .fileCompressionType (FileCompressionType .GZIP );
7374
7475 CsvReadOptionsProto p = CsvReadOptionsProto .parseFrom (opts .toBytes ());
7576
@@ -82,7 +83,9 @@ void fullyConfiguredRoundTripsThroughProto() throws InvalidProtocolBufferExcepti
8283 assertTrue (p .getNewlinesInValues ());
8384 assertEquals (10L , p .getSchemaInferMaxRecords ());
8485 assertEquals (".tsv" , p .getFileExtension ());
85- assertEquals (FileCompressionType .FILE_COMPRESSION_TYPE_GZIP , p .getFileCompressionType ());
86+ assertEquals (
87+ org .apache .datafusion .protobuf .FileCompressionType .FILE_COMPRESSION_TYPE_GZIP ,
88+ p .getFileCompressionType ());
8689 }
8790
8891 @ Test
@@ -96,7 +99,7 @@ void schemaIsHeldByReferenceAndNotInProto() {
9699
97100 @ Test
98101 void allCompressionTypesMapThroughProto () throws InvalidProtocolBufferException {
99- for (CsvReadOptions . FileCompressionType t : CsvReadOptions . FileCompressionType .values ()) {
102+ for (FileCompressionType t : FileCompressionType .values ()) {
100103 CsvReadOptionsProto p =
101104 CsvReadOptionsProto .parseFrom (new CsvReadOptions ().fileCompressionType (t ).toBytes ());
102105 assertEquals (
@@ -105,4 +108,14 @@ void allCompressionTypesMapThroughProto() throws InvalidProtocolBufferException
105108 "mismatch for " + t );
106109 }
107110 }
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+ }
108121}
0 commit comments