Allow using jsonpath predicates with AvroFlattener (#10330)

This commit is contained in:
Lasse Krogh Mammen 2020-10-02 10:14:48 +01:00 committed by GitHub
parent ede25f1b45
commit 20ca9aaaf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -193,6 +193,6 @@ public class GenericAvroJsonProvider implements JsonProvider
@Override @Override
public Object unwrap(final Object o) public Object unwrap(final Object o)
{ {
throw new UnsupportedOperationException("Unused"); return o;
} }
} }

View File

@ -23,6 +23,8 @@ import org.apache.druid.data.input.AvroStreamInputRowParserTest;
import org.apache.druid.data.input.SomeAvroDatum; import org.apache.druid.data.input.SomeAvroDatum;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.Collections;
import java.util.List;
public class AvroFlattenerMakerTest public class AvroFlattenerMakerTest
{ {
@ -195,6 +197,22 @@ public class AvroFlattenerMakerTest
record.getSomeRecordArray(), record.getSomeRecordArray(),
flattener.makeJsonPathExtractor("$.someRecordArray").apply(record) flattener.makeJsonPathExtractor("$.someRecordArray").apply(record)
); );
Assert.assertEquals(
record.getSomeRecordArray().get(0).getNestedString(),
flattener.makeJsonPathExtractor("$.someRecordArray[0].nestedString").apply(record)
);
Assert.assertEquals(
record.getSomeRecordArray(),
flattener.makeJsonPathExtractor("$.someRecordArray[?(@.nestedString)]").apply(record)
);
List<String> nestedStringArray = Collections.singletonList(record.getSomeRecordArray().get(0).getNestedString().toString());
Assert.assertEquals(
nestedStringArray,
flattener.makeJsonPathExtractor("$.someRecordArray[?(@.nestedString=='string in record')].nestedString").apply(record)
);
} }
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)