Skip to content

Commit 1a91592

Browse files
estherbuchwalterMegan Foss
authored andcommitted
Added to field validation for field names. Checks for valid length and valid SQL syntax.
1 parent 523366a commit 1a91592

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFormatConfig.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.List;
3939
import java.util.Objects;
4040
import java.util.Set;
41+
import java.util.regex.Pattern;
4142

4243
@JsonTypeName(FixedwidthFormatPlugin.DEFAULT_NAME)
4344
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@@ -168,10 +169,11 @@ public void validateFieldInput(){
168169
List<Integer> fieldWidths = this.getFieldWidths();
169170
List<String> fieldNames = this.getFieldNames();
170171
List<TypeProtos.MinorType> fieldTypes = this.getFieldTypes();
171-
int width = 0;
172172
int prevIndexAndWidth = -1;
173173

174-
// Validate Field Name - Ensure field is not empty, no two fields have the same name, and field is valid SQL syntax
174+
/* Validate Field Name - Ensure field is not empty, does not exceed maximum length,
175+
is valid SQL syntax, and no two fields have the same name
176+
*/
175177
for (String name : this.getFieldNames()){
176178
if (name.length() == 0){
177179
throw UserException
@@ -180,6 +182,20 @@ public void validateFieldInput(){
180182
.addContext("Plugin", FixedwidthFormatPlugin.DEFAULT_NAME)
181183
.build(logger);
182184
}
185+
if (name.length() > 1024) {
186+
throw UserException
187+
.validationError()
188+
.message("Exceeds maximum length of 1024 characters: " + name.substring(0, 1024))
189+
.addContext("Plugin", FixedwidthFormatPlugin.DEFAULT_NAME)
190+
.build(logger);
191+
}
192+
if (!Pattern.matches("[a-zA-Z]\\w*", name)) {
193+
throw UserException
194+
.validationError()
195+
.message("Invalid input: " + name)
196+
.addContext("Plugin", FixedwidthFormatPlugin.DEFAULT_NAME)
197+
.build(logger);
198+
}
183199
if (uniqueNames.contains(name)){
184200
throw UserException
185201
.validationError()

0 commit comments

Comments
 (0)