@@ -35,6 +35,7 @@ public class DelimitedSchemaDetectorTest {
3535 RawStringPerLine rawStringPerLineIterator ;
3636 HttpBatchSourceConfig configSkipHeaderTrue ;
3737 HttpBatchSourceConfig configSkipHeaderFalse ;
38+ HttpBatchSourceConfig configSkipHeaderTrueAndQuotesEnabled ;
3839 String csvDelimiter = "," ;
3940 String tsvDelimiter = "\t " ;
4041
@@ -46,6 +47,8 @@ public void setUp() {
4647 MockitoAnnotations .initMocks (this );
4748 configSkipHeaderTrue = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("true" ).build ();
4849 configSkipHeaderFalse = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("false" ).build ();
50+ configSkipHeaderTrueAndQuotesEnabled = HttpBatchSourceConfig .builder ().setCsvSkipFirstRow ("true" )
51+ .setEnableQuotesValues (true ).build ();
4952 expectedSchemaWithHeaders = Schema .recordOf ("text" ,
5053 Schema .Field .of ("name" , Schema .of (Schema .Type .STRING )),
5154 Schema .Field .of ("age" , Schema .of (Schema .Type .INT )),
@@ -101,4 +104,24 @@ public void testDetectSchemaTsvHeader() throws IOException {
101104 Assert .assertEquals (expectedSchemaWithHeaders , schema );
102105 }
103106
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+
104127}
0 commit comments