Skip to content

Commit

Permalink
Added another constructor to enable user to not have to enter dateTim…
Browse files Browse the repository at this point in the history
…eFormat when not appropriate, started adding methods to perform field name verification (not complete).
  • Loading branch information
Megan Foss committed Nov 4, 2021
1 parent a91be4c commit 9d66f91
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public class FixedwidthFieldConfig {
private final TypeProtos.MinorType type;
private final String dateTimeFormat;

public FixedwidthFieldConfig(@JsonProperty("name") String name,
@JsonProperty("index") int index,
@JsonProperty("width") int width,
@JsonProperty("type") TypeProtos.MinorType type) {
this(name, index, width, type, null);
}

public FixedwidthFieldConfig(@JsonProperty("name") String name,
@JsonProperty("index") int index,
@JsonProperty("width") int width,
Expand All @@ -49,6 +56,8 @@ public FixedwidthFieldConfig(@JsonProperty("name") String name,
this.type = type;
this.dateTimeFormat = dateTimeFormat;



// Need to verify names are different - where can we access all the names of other columns
// if(name != null){
// this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
package org.apache.drill.exec.store.fixedwidth;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import org.apache.drill.common.PlanStringBuilder;
import org.apache.drill.common.logical.FormatPluginConfig;
import org.apache.drill.exec.store.log.LogFormatField;
import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -77,4 +80,35 @@ public String toString() {
.field("fields", fields)
.toString();
}
}


@JsonIgnore
public boolean hasFields() {
return fields != null && ! fields.isEmpty();
}

@JsonIgnore
public List<String> getFieldNames() {
List<String> result = new ArrayList<>();
if (! hasFields()) {
return result;
}

for (FixedwidthFieldConfig field : fields) {
result.add(field.getName());
}
return result;
}

@JsonIgnore
public boolean validateFieldNames(String fieldName){
boolean result = false;
List<String> names = this.getFieldNames();
if (names.contains(fieldName)){
result = true;
}
return result;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void testEmptyRow() throws Exception {
new RowSetComparison(expected).verifyAndClearAll(results);
}

//
// Create unit test for overloaded constructor

private RowSet setupTestData(){
TupleMetadata expectedSchema = new SchemaBuilder()
Expand Down

0 comments on commit 9d66f91

Please sign in to comment.