From 9d66f9114ab27429a8366d1d71b15f638574dc45 Mon Sep 17 00:00:00 2001 From: Megan Foss Date: Thu, 4 Nov 2021 14:30:23 -0400 Subject: [PATCH] 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). --- .../fixedwidth/FixedwidthFieldConfig.java | 9 +++++ .../fixedwidth/FixedwidthFormatConfig.java | 36 ++++++++++++++++++- .../TestFixedwidthRecordReader.java | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFieldConfig.java b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFieldConfig.java index 69ad9b55b6d..ae2c7c0f095 100644 --- a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFieldConfig.java +++ b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFieldConfig.java @@ -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, @@ -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; diff --git a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFormatConfig.java b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFormatConfig.java index 06f867a2d37..053d83676e3 100644 --- a/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFormatConfig.java +++ b/contrib/format-fixedwidth/src/main/java/org/apache/drill/exec/store/fixedwidth/FixedwidthFormatConfig.java @@ -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; @@ -77,4 +80,35 @@ public String toString() { .field("fields", fields) .toString(); } -} \ No newline at end of file + + + @JsonIgnore + public boolean hasFields() { + return fields != null && ! fields.isEmpty(); + } + + @JsonIgnore + public List getFieldNames() { + List 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 names = this.getFieldNames(); + if (names.contains(fieldName)){ + result = true; + } + return result; + } + + +} diff --git a/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java b/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java index f29219e6bd7..9aa471488f9 100644 --- a/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java +++ b/contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java @@ -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()