mirror of https://github.com/apache/nifi.git
NIFI-10998 Fixed SplitJson to always compile new JsonPath when property changes
This closes #6803 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
06c8225bbd
commit
c11092b2b4
|
@ -143,10 +143,8 @@ public class SplitJson extends AbstractJsonPathProcessor {
|
|||
public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) {
|
||||
if (descriptor.equals(ARRAY_JSON_PATH_EXPRESSION)) {
|
||||
if (!StringUtils.equals(oldValue, newValue)) {
|
||||
if (oldValue != null) {
|
||||
// clear the cached item
|
||||
JSON_PATH_REF.set(null);
|
||||
}
|
||||
// This value will be computed and set in customValidate()
|
||||
JSON_PATH_REF.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.io.OutputStream;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT;
|
||||
|
@ -112,6 +113,39 @@ public class TestSplitJson {
|
|||
originalOut.assertContentEquals(JSON_SNIPPET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit_change_jsonpath() throws Exception {
|
||||
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
|
||||
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[0].range");
|
||||
|
||||
testRunner.enqueue(JSON_SNIPPET);
|
||||
testRunner.run();
|
||||
|
||||
int numSplitsExpected = 10;
|
||||
|
||||
testRunner.assertTransferCount(SplitJson.REL_ORIGINAL, 1);
|
||||
testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0).assertAttributeEquals(FRAGMENT_COUNT.key(), String.valueOf(numSplitsExpected));
|
||||
testRunner.assertTransferCount(SplitJson.REL_SPLIT, numSplitsExpected);
|
||||
final MockFlowFile originalOut = testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0);
|
||||
originalOut.assertContentEquals(JSON_SNIPPET);
|
||||
|
||||
// Change JsonPath Expression, verify it is being applied correctly
|
||||
testRunner.clearTransferState();
|
||||
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$[*].name");
|
||||
|
||||
testRunner.enqueue(JSON_SNIPPET, Collections.singletonMap(CoreAttributes.FILENAME.key(), "test.json"));
|
||||
testRunner.run();
|
||||
|
||||
testRunner.assertTransferCount(SplitJson.REL_ORIGINAL, 1);
|
||||
final MockFlowFile originalFlowFile = testRunner.getFlowFilesForRelationship(SplitJson.REL_ORIGINAL).get(0);
|
||||
originalFlowFile.assertAttributeExists(FRAGMENT_ID.key());
|
||||
originalFlowFile.assertAttributeEquals(FRAGMENT_COUNT.key(), "7");
|
||||
originalFlowFile.assertContentEquals(JSON_SNIPPET);
|
||||
testRunner.assertTransferCount(SplitJson.REL_SPLIT, 7);
|
||||
MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(SplitJson.REL_SPLIT).get(0);
|
||||
flowFile.assertContentEquals("{\"first\":\"Shaffer\",\"last\":\"Pearson\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplit_arrayResult_nonScalarValues() throws Exception {
|
||||
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
|
||||
|
|
Loading…
Reference in New Issue