31
31
import java .util .HashMap ;
32
32
import java .util .Map ;
33
33
34
+ import static io .streamthoughts .kafka .connect .filepulse .config .DelimitedRowFilterConfig .READER_AUTO_GENERATE_COLUMN_NAME_CONFIG ;
34
35
import static io .streamthoughts .kafka .connect .filepulse .config .DelimitedRowFilterConfig .READER_EXTRACT_COLUMN_NAME_CONFIG ;
35
36
import static io .streamthoughts .kafka .connect .filepulse .config .DelimitedRowFilterConfig .READER_FIELD_COLUMNS_CONFIG ;
36
37
import static io .streamthoughts .kafka .connect .filepulse .config .DelimitedRowFilterConfig .READER_FIELD_DUPLICATE_COLUMNS_AS_ARRAY_CONFIG ;
@@ -42,12 +43,10 @@ public class DelimitedRowFileInputFilterTest {
42
43
43
44
private DelimitedRowFilter filter ;
44
45
45
-
46
46
private static final TypedStruct DEFAULT_STRUCT = TypedStruct .create ()
47
47
.put ("message" , "value1;2;true" )
48
48
.put ("headers" , Collections .singletonList ("col1;col2;col3" ));
49
49
50
-
51
50
@ Before
52
51
public void setUp () {
53
52
filter = new DelimitedRowFilter ();
@@ -101,6 +100,32 @@ public void should_extract_repeated_columns_names_from_given_field() {
101
100
Assert .assertEquals ("value3" , output .getString ("col3" ));
102
101
}
103
102
103
+ @ Test
104
+ public void should_generate_column_names_given_records_with_different_size () {
105
+ configs .put (READER_AUTO_GENERATE_COLUMN_NAME_CONFIG , "true" );
106
+ filter .configure (configs , alias -> null );
107
+
108
+ TypedStruct input , output ;
109
+
110
+ input = TypedStruct .create ().put ("message" , "value1;value2;" );
111
+ RecordsIterable <TypedStruct > iterable1 = filter .apply (null , input , false );
112
+ Assert .assertNotNull (iterable1 );
113
+ Assert .assertEquals (1 , iterable1 .size ());
114
+
115
+ output = iterable1 .iterator ().next ();
116
+ Assert .assertNotNull (output .schema ().field ("column1" ));
117
+ Assert .assertNotNull (output .schema ().field ("column2" ));
118
+
119
+ input = TypedStruct .create ().put ("message" , "value1;value2;value3" );
120
+ RecordsIterable <TypedStruct > iterable2 = filter .apply (null , input , false );
121
+ Assert .assertNotNull (iterable2 );
122
+ Assert .assertEquals (1 , iterable2 .size ());
123
+
124
+ output = iterable2 .iterator ().next ();
125
+ Assert .assertNotNull (output .schema ().field ("column1" ));
126
+ Assert .assertNotNull (output .schema ().field ("column2" ));
127
+ Assert .assertNotNull (output .schema ().field ("column3" ));
128
+ }
104
129
105
130
@ Test (expected = DataException .class )
106
131
public void should_fail_given_repeated_columns_names_and_duplicate_not_allowed () {
0 commit comments