Skip to content

Commit 9d66f91

Browse files
author
Megan Foss
committed
Added another constructor to enable user to not have to enter dateTimeFormat when not appropriate, started adding methods to perform field name verification (not complete).
1 parent a91be4c commit 9d66f91

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public class FixedwidthFieldConfig {
3737
private final TypeProtos.MinorType type;
3838
private final String dateTimeFormat;
3939

40+
public FixedwidthFieldConfig(@JsonProperty("name") String name,
41+
@JsonProperty("index") int index,
42+
@JsonProperty("width") int width,
43+
@JsonProperty("type") TypeProtos.MinorType type) {
44+
this(name, index, width, type, null);
45+
}
46+
4047
public FixedwidthFieldConfig(@JsonProperty("name") String name,
4148
@JsonProperty("index") int index,
4249
@JsonProperty("width") int width,
@@ -49,6 +56,8 @@ public FixedwidthFieldConfig(@JsonProperty("name") String name,
4956
this.type = type;
5057
this.dateTimeFormat = dateTimeFormat;
5158

59+
60+
5261
// Need to verify names are different - where can we access all the names of other columns
5362
// if(name != null){
5463
// this.name = name;

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

+35-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
package org.apache.drill.exec.store.fixedwidth;
2020

2121
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonIgnore;
2223
import com.fasterxml.jackson.annotation.JsonInclude;
2324
import com.fasterxml.jackson.annotation.JsonProperty;
2425
import com.fasterxml.jackson.annotation.JsonTypeName;
2526
import org.apache.drill.common.PlanStringBuilder;
2627
import org.apache.drill.common.logical.FormatPluginConfig;
28+
import org.apache.drill.exec.store.log.LogFormatField;
2729
import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList;
2830

31+
import java.util.ArrayList;
2932
import java.util.Collections;
3033
import java.util.List;
3134
import java.util.Objects;
@@ -77,4 +80,35 @@ public String toString() {
7780
.field("fields", fields)
7881
.toString();
7982
}
80-
}
83+
84+
85+
@JsonIgnore
86+
public boolean hasFields() {
87+
return fields != null && ! fields.isEmpty();
88+
}
89+
90+
@JsonIgnore
91+
public List<String> getFieldNames() {
92+
List<String> result = new ArrayList<>();
93+
if (! hasFields()) {
94+
return result;
95+
}
96+
97+
for (FixedwidthFieldConfig field : fields) {
98+
result.add(field.getName());
99+
}
100+
return result;
101+
}
102+
103+
@JsonIgnore
104+
public boolean validateFieldNames(String fieldName){
105+
boolean result = false;
106+
List<String> names = this.getFieldNames();
107+
if (names.contains(fieldName)){
108+
result = true;
109+
}
110+
return result;
111+
}
112+
113+
114+
}

contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void testEmptyRow() throws Exception {
174174
new RowSetComparison(expected).verifyAndClearAll(results);
175175
}
176176

177-
//
177+
// Create unit test for overloaded constructor
178178

179179
private RowSet setupTestData(){
180180
TupleMetadata expectedSchema = new SchemaBuilder()

0 commit comments

Comments
 (0)