@@ -45,9 +45,9 @@ public class FixedwidthFormatConfig implements FormatPluginConfig {
4545 private static final Logger logger = LoggerFactory .getLogger (FixedwidthFormatConfig .class );
4646 private final List <String > extensions ;
4747 private final List <FixedwidthFieldConfig > fields ;
48- private final List <TypeProtos .MinorType > validDataTypes = Arrays .asList (new TypeProtos . MinorType []{ TypeProtos .MinorType .INT , TypeProtos .MinorType .VARCHAR ,
48+ private final List <TypeProtos .MinorType > validDataTypes = Arrays .asList (TypeProtos .MinorType .INT , TypeProtos .MinorType .VARCHAR ,
4949 TypeProtos .MinorType .DATE , TypeProtos .MinorType .TIME , TypeProtos .MinorType .TIMESTAMP , TypeProtos .MinorType .FLOAT4 ,
50- TypeProtos .MinorType .FLOAT8 , TypeProtos .MinorType .BIGINT , TypeProtos .MinorType .VARDECIMAL } );
50+ TypeProtos .MinorType .FLOAT8 , TypeProtos .MinorType .BIGINT , TypeProtos .MinorType .VARDECIMAL );
5151
5252 @ JsonCreator
5353 public FixedwidthFormatConfig (@ JsonProperty ("extensions" ) List <String > extensions ,
@@ -139,15 +139,6 @@ public List<Integer> getFieldWidths() {
139139 return result ;
140140 }
141141
142- @ JsonIgnore
143- public void setFieldWidths (int i , int value ) {
144- for (FixedwidthFieldConfig field : fields ) {
145- if (field .getIndex () == i ) {
146- field .setWidth (value );
147- }
148- }
149- }
150-
151142 @ JsonIgnore
152143 public List <TypeProtos .MinorType > getFieldTypes () {
153144 List <TypeProtos .MinorType > result = new ArrayList <>();
@@ -180,7 +171,7 @@ public void validateFieldInput(){
180171 int width = 0 ;
181172 int prevIndexAndWidth = -1 ;
182173
183- // Ensure no two fields have the same name
174+ // Validate Field Name - Ensure field is not empty, no two fields have the same name, and field is valid SQL syntax
184175 for (String name : this .getFieldNames ()){
185176 if (name .length () == 0 ){
186177 throw UserException
@@ -199,7 +190,7 @@ public void validateFieldInput(){
199190 uniqueNames .add (name );
200191 }
201192
202- //assuming that fieldIndices is the same size as fieldWidths, width is required
193+ // Validate Field Index - Must be greater than 0, and must not overlap with other fields
203194 for (int i = 0 ; i <fieldIndices .size (); i ++) {
204195 if (fieldIndices .get (i ) < 1 ) {
205196 throw UserException
@@ -216,26 +207,26 @@ else if (fieldIndices.get(i) <= prevIndexAndWidth) {
216207 .build (logger );
217208 }
218209
210+ // Validate Field Width - must be greater than 0.
219211 if (fieldWidths .get (i ) == null || fieldWidths .get (i ) < 1 ) {
220- // Come back to this - can we calculate this instead of throwing an error?
221- if (i == fieldIndices .size ()-1 ) {
222212 throw UserException
223213 .validationError ()
224- .message ("Width for field '" + fieldNames .get (i ) + "' is empty ." )
214+ .message ("Width for field '" + fieldNames .get (i ) + "' is invalid. Widths must be greater than 0 ." )
225215 .addContext ("Plugin" , FixedwidthFormatPlugin .DEFAULT_NAME )
226216 .build (logger );
227- }
228- width = fieldIndices .get (i +1 ) - fieldIndices .get (i ) - 1 ;
229- setFieldWidths (fieldIndices .get (i ), width );
230217 }
231218 prevIndexAndWidth = fieldIndices .get (i ) + fieldWidths .get (i );
232219
233- // Validate Field Type
220+ // Validate Field Type - must not be empty and must be included in list of valid data types for the fixed width plugin
234221 if (fieldTypes .get (i ) == null || fieldTypes .get (i ).toString ().length () == 0 ) {
235222 setFieldTypes (fieldIndices .get (i ));
236223 }
237224 else if (!validDataTypes .contains (fieldTypes .get (i ))){
238- setFieldTypes (fieldIndices .get (i )); //Should we throw an error or default to VARCHAR for data types that are not yet available in this plugin
225+ throw UserException
226+ .validationError ()
227+ .message ("Field type " + fieldTypes .get (i ) + " is not valid. Please check for typos and ensure the required data type is included in the Fixed Width Format Plugin." )
228+ .addContext ("Plugin" , FixedwidthFormatPlugin .DEFAULT_NAME )
229+ .build (logger );
239230 }
240231 }
241232 }
0 commit comments