drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject drill git commit: DRILL-4145: Handle empty final field in Text reader correctly
Date Wed, 02 Dec 2015 22:48:19 GMT
Repository: drill
Updated Branches:
  refs/heads/master 36bd63786 -> 8f56250ae


DRILL-4145: Handle empty final field in Text reader correctly


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/8f56250a
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/8f56250a
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/8f56250a

Branch: refs/heads/master
Commit: 8f56250aeb29d5d21bcdc6c727cec89607150224
Parents: 36bd637
Author: Steven Phillips <smp@apache.org>
Authored: Wed Dec 2 02:09:20 2015 -0800
Committer: Steven Phillips <smp@apache.org>
Committed: Wed Dec 2 02:13:23 2015 -0800

----------------------------------------------------------------------
 .../store/easy/text/compliant/TextReader.java   |  1 +
 .../drill/exec/store/text/TestCsvHeader.java    | 27 ++++++++++++++++++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/8f56250a/exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/text/compliant/TextReader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/text/compliant/TextReader.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/text/compliant/TextReader.java
index 5d41254..82427bb 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/text/compliant/TextReader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/text/compliant/TextReader.java
@@ -143,6 +143,7 @@ final class TextReader {
         if (ch != newLine) {
           ch = input.nextChar();
           if (ch == newLine) {
+            output.startField(fieldsWritten++);
             output.endEmptyField();
             break;
           }

http://git-wip-us.apache.org/repos/asf/drill/blob/8f56250a/exec/java-exec/src/test/java/org/apache/drill/exec/store/text/TestCsvHeader.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/text/TestCsvHeader.java
b/exec/java-exec/src/test/java/org/apache/drill/exec/store/text/TestCsvHeader.java
index 92aa02b..0192ab8 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/text/TestCsvHeader.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/text/TestCsvHeader.java
@@ -18,10 +18,14 @@
 package org.apache.drill.exec.store.text;
 
 import org.apache.drill.BaseTestQuery;
+import org.apache.drill.TestBuilder;
 import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.exception.SchemaChangeException;
 import org.apache.drill.exec.rpc.user.QueryDataBatch;
 
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.util.List;
 
 import org.junit.Before;
@@ -162,6 +166,29 @@ public class TestCsvHeader extends BaseTestQuery{
     validateResults (batches, expectedOutput);
   }
 
+  @Test
+  public void testEmptyFinalColumn() throws Exception {
+    String dfs_temp = getDfsTestTmpSchemaLocation();
+    File table_dir = new File(dfs_temp, "emptyFinalColumn");
+    table_dir.mkdir();
+    BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(table_dir,
"a.csvh")));
+    os.write("field1,field2\n".getBytes());
+    for (int i = 0; i < 10000; i++) {
+      os.write("a,\n".getBytes());
+    }
+    os.flush();
+    os.close();
+    String query = "select * from dfs_test.tmp.emptyFinalColumn";
+      TestBuilder builder = testBuilder()
+              .sqlQuery(query)
+              .ordered()
+              .baselineColumns("field1", "field2");
+      for (int i = 0; i < 10000; i++) {
+        builder.baselineValues("a", "");
+      }
+      builder.go();
+  }
+
   private void validateResults (List<QueryDataBatch> batches, String expectedOutput)
throws SchemaChangeException {
     String actualOutput = getResultString(batches, OUTPUT_DELIMITER);
     //for your and machine's eyes


Mime
View raw message