@@ -35,6 +35,7 @@ public class DelimitedSchemaDetectorTest {
35
35
RawStringPerLine rawStringPerLineIterator ;
36
36
HttpBatchSourceConfig configSkipHeaderTrue ;
37
37
HttpBatchSourceConfig configSkipHeaderFalse ;
38
+ HttpBatchSourceConfig configSkipHeaderTrueAndQuotesEnabled ;
38
39
String csvDelimiter = "," ;
39
40
String tsvDelimiter = "\t " ;
40
41
@@ -46,6 +47,8 @@ public void setUp() {
46
47
MockitoAnnotations .initMocks (this );
47
48
configSkipHeaderTrue = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("true" ).build ();
48
49
configSkipHeaderFalse = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("false" ).build ();
50
+ configSkipHeaderTrueAndQuotesEnabled = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("true" )
51
+ .setEnableQuotesValues (true ).build ();
49
52
expectedSchemaWithHeaders = Schema .recordOf ("text" ,
50
53
Schema .Field .of ("name" , Schema .of (Schema .Type .STRING )),
51
54
Schema .Field .of ("age" , Schema .of (Schema .Type .INT )),
@@ -101,4 +104,24 @@ public void testDetectSchemaTsvHeader() throws IOException {
101
104
Assert .assertEquals (expectedSchemaWithHeaders , schema );
102
105
}
103
106
107
+ @ Test
108
+ public void testDetectSchemaWithQuotesEnabled () throws IOException {
109
+ String [] lines = new String []{"name,age,isIndian,country" , "\" raj,singh\" ,29,true,india" , "rahul,30,false," };
110
+ Mockito .when (rawStringPerLineIterator .hasNext ()).thenReturn (true , true , true , false );
111
+ Mockito .when (rawStringPerLineIterator .next ()).thenReturn (lines [0 ], lines [1 ], lines [2 ]);
112
+ Schema schema = DelimitedSchemaDetector .detectSchema (
113
+ configSkipHeaderTrueAndQuotesEnabled , csvDelimiter , rawStringPerLineIterator , null );
114
+ Assert .assertEquals (expectedSchemaWithHeaders , schema );
115
+ }
116
+
117
+ @ Test
118
+ public void testDetectSchemaWithQuotesDisabled () throws IOException {
119
+ String [] lines = new String []{"name,age,isIndian,country" , "\" raj,singh\" ,29,true,india" , "rahul,30,false," };
120
+ Mockito .when (rawStringPerLineIterator .hasNext ()).thenReturn (true , true , true , false );
121
+ Mockito .when (rawStringPerLineIterator .next ()).thenReturn (lines [0 ], lines [1 ], lines [2 ]);
122
+ Schema schema = DelimitedSchemaDetector .detectSchema (
123
+ configSkipHeaderTrue , csvDelimiter , rawStringPerLineIterator , null );
124
+ Assert .assertNotEquals (expectedSchemaWithHeaders , schema );
125
+ }
126
+
104
127
}
0 commit comments