You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by js...@apache.org on 2015/05/05 03:38:27 UTC
[3/3] drill git commit: DRILL-2221: Do not skip writing an empty list
DRILL-2221: Do not skip writing an empty list
small fix for bad resolution of merge conflict in free marker template
Fix test to use dfs_test instead of the default dfs storage plugin
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/ac823fe8
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/ac823fe8
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/ac823fe8
Branch: refs/heads/master
Commit: ac823fe8bd9d6b778f37e32d95ab0d199f8ff551
Parents: dcbf461
Author: Sudheesh Katkam <sk...@maprtech.com>
Authored: Fri Apr 10 15:00:41 2015 -0700
Committer: Jason Altekruse <al...@gmail.com>
Committed: Mon May 4 16:33:53 2015 -0700
----------------------------------------------------------------------
.../main/codegen/templates/JsonOutputRecordWriter.java | 5 -----
.../test/java/org/apache/drill/TestExampleQueries.java | 12 ++++++++++++
.../resources/store/json/record_with_empty_list.json | 2 ++
3 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/ac823fe8/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java b/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java
index 1bea326..ea643f0 100644
--- a/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java
+++ b/exec/java-exec/src/main/codegen/templates/JsonOutputRecordWriter.java
@@ -89,13 +89,8 @@ public abstract class JSONOutputRecordWriter extends AbstractRecordWriter implem
@Override
public void writeField() throws IOException {
<#if mode.prefix == "Repeated" >
- // empty lists are represented by simply not starting a field, rather than starting one and putting in 0 elements
- if (reader.size() == 0) {
- return;
- }
gen.writeStartArray();
for (int i = 0; i < reader.size(); i++) {
- <#else>
</#if>
<#assign typeName = minor.class >
http://git-wip-us.apache.org/repos/asf/drill/blob/ac823fe8/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
index d5c5385..7e07500 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestExampleQueries.java
@@ -831,4 +831,16 @@ public class TestExampleQueries extends BaseTestQuery{
.baselineValues("MIDDLE EAST")
.build().run();
}
+
+ @Test // DRILL-2221
+ public void createJsonWithEmptyList() throws Exception {
+ final String file = FileUtils.getResourceAsFile("/store/json/record_with_empty_list.json").toURI().toString();
+ final String tableName = "jsonWithEmptyList";
+ test("USE dfs_test.tmp");
+ test("ALTER SESSION SET `store.format`='json'");
+ test(String.format("CREATE TABLE %s AS SELECT * FROM `%s`", tableName, file));
+ test(String.format("SELECT COUNT(*) FROM %s", tableName));
+ test("ALTER SESSION SET `store.format`='parquet'");
+ }
+
}
http://git-wip-us.apache.org/repos/asf/drill/blob/ac823fe8/exec/java-exec/src/test/resources/store/json/record_with_empty_list.json
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/store/json/record_with_empty_list.json b/exec/java-exec/src/test/resources/store/json/record_with_empty_list.json
new file mode 100644
index 0000000..4338365
--- /dev/null
+++ b/exec/java-exec/src/test/resources/store/json/record_with_empty_list.json
@@ -0,0 +1,2 @@
+{ "a": "A1", "b": [ "B1", "B2" ], "c": [ "C1", "C2" ] }
+{ "a": "A2", "b": [ "B3" ], "c": [] }
\ No newline at end of file