Skip to content

Commit

Permalink
DRILL-8506: Ignore JSON Elements with Empty Keys (#2935)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgivre authored Aug 26, 2024
1 parent a05b90d commit 11aaa3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ private void parseMember(TokenIterator tokenizer) {
*/
private ElementParser detectValueParser(String key, TokenIterator tokenizer) {
if (key.isEmpty()) {
throw errorFactory().structureError(
"Drill does not allow empty keys in JSON key/value pairs");
logger.warn("Ignoring empty key: {}", key);
return DummyValueParser.INSTANCE;
}
ElementParser fieldParser = onField(key, tokenizer);
if (fieldParser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
*/
package org.apache.drill.exec.store.easy.json.loader;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.apache.drill.categories.JsonTest;
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.common.types.TypeProtos.MinorType;
Expand All @@ -35,6 +29,12 @@
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@Category(JsonTest.class)
public class TestBasics extends BaseJsonLoaderTest {

Expand Down Expand Up @@ -176,12 +176,22 @@ public void testMissingEndOuterArray() {

@Test
public void testEmptyKey() {
expectError("{\"\": 10}", "does not allow empty keys");
JsonLoaderFixture loader = new JsonLoaderFixture();
loader.jsonOptions.skipMalformedRecords = true;
loader.open("{\"\": 10}");
RowSet results = loader.next();
assertNotNull(results);
assertEquals(1, results.rowCount());
}

@Test
public void testBlankKey() {
expectError("{\" \": 10}", "does not allow empty keys");
JsonLoaderFixture loader = new JsonLoaderFixture();
loader.jsonOptions.skipMalformedRecords = true;
loader.open("{\" \": 10}");
RowSet results = loader.next();
assertNotNull(results);
assertEquals(1, results.rowCount());
}

@Test
Expand Down

0 comments on commit 11aaa3f

Please sign in to comment.