You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by cg...@apache.org on 2021/02/28 14:35:36 UTC
[drill] branch master updated: DRILL-7821: Treat Empty String as
NULL in JSON Reader
This is an automated email from the ASF dual-hosted git repository.
cgivre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
The following commit(s) were added to refs/heads/master by this push:
new a045428 DRILL-7821: Treat Empty String as NULL in JSON Reader
a045428 is described below
commit a04542828c70a5cf1c3efc0fc6f318a40c44f9c4
Author: Martin Kusnir <mk...@uwaterloo.ca>
AuthorDate: Fri Feb 12 13:19:33 2021 -0500
DRILL-7821: Treat Empty String as NULL in JSON Reader
DRILL-7821: Treat Empty String as NULL in JSON Reader
---
.../drill/exec/vector/complex/fn/JsonReader.java | 15 ++++--
.../exec/vector/complex/writer/TestJsonReader.java | 56 ++++++++++++++++++++++
2 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
index 1ce89fc..1bbcb97 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/JsonReader.java
@@ -407,11 +407,16 @@ public class JsonReader extends BaseJsonReader {
}
}
- private void handleString(JsonParser parser, MapWriter writer,
- String fieldName) throws IOException {
- writer.varChar(fieldName).writeVarChar(0,
- workingBuffer.prepareVarCharHolder(parser.getText()),
- workingBuffer.getBuf());
+ private void handleString(JsonParser parser, MapWriter writer, String fieldName) throws IOException {
+ try {
+ writer.varChar(fieldName)
+ .writeVarChar(0, workingBuffer.prepareVarCharHolder(parser.getText()), workingBuffer.getBuf());
+ } catch (IllegalArgumentException e) {
+ if (parser.getText() == null || parser.getText().isEmpty()) {
+ return;
+ }
+ throw e;
+ }
}
private void handleString(JsonParser parser, ListWriter writer)
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonReader.java b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonReader.java
index 3fae12b..71f2ffd 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonReader.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestJsonReader.java
@@ -804,4 +804,60 @@ public class TestJsonReader extends BaseTestQuery {
.baselineValues("2", "abc")
.go();
}
+
+ @Test // DRILL-7821
+ public void testEmptyObjectInference() throws Exception {
+ String fileName = "emptyObject.json";
+
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dirTestWatcher.getRootDir(), fileName)))) {
+ writer.write("{\"sample\": [{\"data\": {}},{\"data\": \"\"}]}");
+ }
+
+ String sql = "SELECT * from dfs.`%s` t";
+
+ testBuilder()
+ .sqlQuery(sql, fileName)
+ .ordered()
+ .baselineColumns("sample")
+ .baselineValues(
+ listOf(
+ mapOf(
+ "data", mapOf()
+ ),
+ mapOf(
+ "data", mapOf()
+ )
+ )
+ )
+ .go();
+ }
+
+ @Test // DRILL-7821
+ public void testFilledObjectInference() throws Exception {
+ String fileName = "filledObject.json";
+
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dirTestWatcher.getRootDir(), fileName)))) {
+ writer.write("{\"sample\": [{\"data\": {\"foo\": \"bar\"}},{\"data\": \"\"}]}");
+ }
+
+ String sql = "SELECT * from dfs.`%s` t";
+
+ testBuilder()
+ .sqlQuery(sql, fileName)
+ .ordered()
+ .baselineColumns("sample")
+ .baselineValues(
+ listOf(
+ mapOf(
+ "data", mapOf(
+ "foo", "bar"
+ )
+ ),
+ mapOf(
+ "data", mapOf()
+ )
+ )
+ )
+ .go();
+ }
}