Skip to content

Commit 11aaa3f

Browse files
authored
DRILL-8506: Ignore JSON Elements with Empty Keys (#2935)
1 parent a05b90d commit 11aaa3f

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/store/easy/json/parser/ObjectParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ private void parseMember(TokenIterator tokenizer) {
238238
*/
239239
private ElementParser detectValueParser(String key, TokenIterator tokenizer) {
240240
if (key.isEmpty()) {
241-
throw errorFactory().structureError(
242-
"Drill does not allow empty keys in JSON key/value pairs");
241+
logger.warn("Ignoring empty key: {}", key);
242+
return DummyValueParser.INSTANCE;
243243
}
244244
ElementParser fieldParser = onField(key, tokenizer);
245245
if (fieldParser == null) {

exec/java-exec/src/test/java/org/apache/drill/exec/store/easy/json/loader/TestBasics.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
*/
1818
package org.apache.drill.exec.store.easy.json.loader;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
25-
2620
import org.apache.drill.categories.JsonTest;
2721
import org.apache.drill.common.exceptions.UserException;
2822
import org.apache.drill.common.types.TypeProtos.MinorType;
@@ -35,6 +29,12 @@
3529
import org.junit.Test;
3630
import org.junit.experimental.categories.Category;
3731

32+
import static org.junit.Assert.assertEquals;
33+
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertNull;
35+
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
37+
3838
@Category(JsonTest.class)
3939
public class TestBasics extends BaseJsonLoaderTest {
4040

@@ -176,12 +176,22 @@ public void testMissingEndOuterArray() {
176176

177177
@Test
178178
public void testEmptyKey() {
179-
expectError("{\"\": 10}", "does not allow empty keys");
179+
JsonLoaderFixture loader = new JsonLoaderFixture();
180+
loader.jsonOptions.skipMalformedRecords = true;
181+
loader.open("{\"\": 10}");
182+
RowSet results = loader.next();
183+
assertNotNull(results);
184+
assertEquals(1, results.rowCount());
180185
}
181186

182187
@Test
183188
public void testBlankKey() {
184-
expectError("{\" \": 10}", "does not allow empty keys");
189+
JsonLoaderFixture loader = new JsonLoaderFixture();
190+
loader.jsonOptions.skipMalformedRecords = true;
191+
loader.open("{\" \": 10}");
192+
RowSet results = loader.next();
193+
assertNotNull(results);
194+
assertEquals(1, results.rowCount());
185195
}
186196

187197
@Test

0 commit comments

Comments
 (0)