Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@
<exclude>src/test/resources/TestExtractGrok/simple_text.log</exclude>
<exclude>src/test/resources/TestExtractRecordSchema/name_age_schema.avsc</exclude>
<exclude>src/test/resources/TestForkRecord/input/complex-input-json.json</exclude>
<exclude>src/test/resources/TestForkRecord/input/complex-input-json-for-inference.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/extract-address-without-parents.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/extract-address-with-parents.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/extract-bank-accounts-with-parents.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/extract-transactions.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/split-address.json</exclude>
<exclude>src/test/resources/TestForkRecord/output/split-transactions.json</exclude>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,96 @@ public void testExtractMode() throws InitializationException, IOException {
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "6");
}

@Test
public void testExtractWithParentFieldsAndInferredSchema() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new ForkRecord());

final JsonTreeReader jsonReader = new JsonTreeReader();
runner.addControllerService("record-reader", jsonReader);
runner.enableControllerService(jsonReader);

final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
runner.addControllerService("record-writer", jsonWriter);
runner.setProperty(jsonWriter, "Pretty Print JSON", "true");
runner.enableControllerService(jsonWriter);

runner.setProperty(ForkRecord.RECORD_READER, "record-reader");
runner.setProperty(ForkRecord.RECORD_WRITER, "record-writer");
runner.setProperty(ForkRecord.MODE, ForkRecord.MODE_EXTRACT);
runner.setProperty(ForkRecord.INCLUDE_PARENT_FIELDS, "true");
runner.setProperty("bankAccounts", "/bankAccounts");

runner.enqueue(Paths.get("src/test/resources/TestForkRecord/input/complex-input-json-for-inference.json"));
runner.run();

runner.assertTransferCount(ForkRecord.REL_ORIGINAL, 1);
runner.assertTransferCount(ForkRecord.REL_FORK, 1);

final String expectedOutput = new String(Files.readAllBytes(Paths.get("src/test/resources/TestForkRecord/output/extract-bank-accounts-with-parents.json")));
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
}

@Test
public void testExtractFieldsAndInferredSchema() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new ForkRecord());

final JsonTreeReader jsonReader = new JsonTreeReader();
runner.addControllerService("record-reader", jsonReader);
runner.enableControllerService(jsonReader);

final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
runner.addControllerService("record-writer", jsonWriter);
runner.setProperty(jsonWriter, "Pretty Print JSON", "true");
runner.enableControllerService(jsonWriter);

runner.setProperty(ForkRecord.RECORD_READER, "record-reader");
runner.setProperty(ForkRecord.RECORD_WRITER, "record-writer");
runner.setProperty(ForkRecord.MODE, ForkRecord.MODE_EXTRACT);
runner.setProperty(ForkRecord.INCLUDE_PARENT_FIELDS, "false");
runner.setProperty("address", "/address");

runner.enqueue(Paths.get("src/test/resources/TestForkRecord/input/complex-input-json-for-inference.json"));
runner.run();

runner.assertTransferCount(ForkRecord.REL_ORIGINAL, 1);
runner.assertTransferCount(ForkRecord.REL_FORK, 1);

final String expectedOutput = new String(Files.readAllBytes(Paths.get("src/test/resources/TestForkRecord/output/extract-address-without-parents.json")));
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
}

@Test
public void testExtractFieldsWithParentsAndFieldConflictAndInferredSchema() throws Exception {
TestRunner runner = TestRunners.newTestRunner(new ForkRecord());

final JsonTreeReader jsonReader = new JsonTreeReader();
runner.addControllerService("record-reader", jsonReader);
runner.enableControllerService(jsonReader);

final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
runner.addControllerService("record-writer", jsonWriter);
runner.setProperty(jsonWriter, "Pretty Print JSON", "true");
runner.enableControllerService(jsonWriter);

runner.setProperty(ForkRecord.RECORD_READER, "record-reader");
runner.setProperty(ForkRecord.RECORD_WRITER, "record-writer");
runner.setProperty(ForkRecord.MODE, ForkRecord.MODE_EXTRACT);
runner.setProperty(ForkRecord.INCLUDE_PARENT_FIELDS, "true");
runner.setProperty("address", "/address");

runner.enqueue(Paths.get("src/test/resources/TestForkRecord/input/complex-input-json-for-inference.json"));
runner.run();

runner.assertTransferCount(ForkRecord.REL_ORIGINAL, 1);
runner.assertTransferCount(ForkRecord.REL_FORK, 1);

final String expectedOutput = new String(Files.readAllBytes(Paths.get("src/test/resources/TestForkRecord/output/extract-address-with-parents.json")));
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
}

private class JsonRecordReader extends AbstractControllerService implements RecordReaderFactory {

private static final JsonParserFactory jsonParserFactory = new JsonParserFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"id": 1,
"name": {
"last": "Doe",
"first": "John"
},
"address": [
{
"id": "home",
"street": "1 nifi street",
"city": "nifi city"
}
],
"bankAccounts": [
{
"bankID": "OneBank",
"IBAN": "OneIBAN",
"last5Transactions": [
{
"comment": "food",
"amount": "-450"
}
]
}
]
}, {
"id": 2,
"name": {
"last": "Smith",
"first": "John"
},
"address": [null],
"bankAccounts": null
}, {
"id": 3,
"name": {
"last": "Smith",
"first": "Jane"
},
"address": [
{
"id": "home",
"street": "1 nifi street",
"city": "nifi city"
}, {
"id": "work",
"street": "1 nifi avenue",
"city": "apache city"
}
],
"bankAccounts": [
{
"bankID": "nifi bank",
"IBAN": "myIBAN",
"last5Transactions": null
}, {
"bankID": "apache bank",
"IBAN": "myIBAN",
"last5Transactions": [
{
"comment": "gas station",
"amount": "-45"
}, {
"comment": "hair cut",
"amount": "-19"
}
]
}
]
}, {
"id": 4,
"name": {
"last": "Clark",
"first": "Jane"
},
"address": [
{
"id": "home",
"street": "10 nifi street",
"city": "nifi city"
}, {
"id": "work",
"street": "10 nifi avenue",
"city": "apache city"
}
],
"bankAccounts": [
{
"bankID": "nifi bank",
"IBAN": "myIBAN",
"last5Transactions": [
{
"comment": "gift",
"amount": "+100"
}, {
"comment": "flights",
"amount": "-190"
}
]
}, {
"bankID": "apache bank",
"IBAN": "myIBAN",
"last5Transactions": [
{
"comment": "nifi tshirt",
"amount": "0"
}, {
"comment": "theatre",
"amount": "-19"
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
[ {
"id" : "home",
"street" : "1 nifi street",
"city" : "nifi city",
"name" : {
"last" : "Doe",
"first" : "John"
},
"bankAccounts" : [ {
"bankID" : "OneBank",
"IBAN" : "OneIBAN",
"last5Transactions" : [ {
"comment" : "food",
"amount" : "-450"
} ]
} ]
}, {
"id" : "home",
"street" : "1 nifi street",
"city" : "nifi city",
"name" : {
"last" : "Smith",
"first" : "Jane"
},
"bankAccounts" : [ {
"bankID" : "nifi bank",
"IBAN" : "myIBAN",
"last5Transactions" : null
}, {
"bankID" : "apache bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "gas station",
"amount" : "-45"
}, {
"comment" : "hair cut",
"amount" : "-19"
} ]
} ]
}, {
"id" : "work",
"street" : "1 nifi avenue",
"city" : "apache city",
"name" : {
"last" : "Smith",
"first" : "Jane"
},
"bankAccounts" : [ {
"bankID" : "nifi bank",
"IBAN" : "myIBAN",
"last5Transactions" : null
}, {
"bankID" : "apache bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "gas station",
"amount" : "-45"
}, {
"comment" : "hair cut",
"amount" : "-19"
} ]
} ]
}, {
"id" : "home",
"street" : "10 nifi street",
"city" : "nifi city",
"name" : {
"last" : "Clark",
"first" : "Jane"
},
"bankAccounts" : [ {
"bankID" : "nifi bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "gift",
"amount" : "+100"
}, {
"comment" : "flights",
"amount" : "-190"
} ]
}, {
"bankID" : "apache bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "nifi tshirt",
"amount" : "0"
}, {
"comment" : "theatre",
"amount" : "-19"
} ]
} ]
}, {
"id" : "work",
"street" : "10 nifi avenue",
"city" : "apache city",
"name" : {
"last" : "Clark",
"first" : "Jane"
},
"bankAccounts" : [ {
"bankID" : "nifi bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "gift",
"amount" : "+100"
}, {
"comment" : "flights",
"amount" : "-190"
} ]
}, {
"bankID" : "apache bank",
"IBAN" : "myIBAN",
"last5Transactions" : [ {
"comment" : "nifi tshirt",
"amount" : "0"
}, {
"comment" : "theatre",
"amount" : "-19"
} ]
} ]
} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[ {
"id" : "home",
"street" : "1 nifi street",
"city" : "nifi city"
}, {
"id" : "home",
"street" : "1 nifi street",
"city" : "nifi city"
}, {
"id" : "work",
"street" : "1 nifi avenue",
"city" : "apache city"
}, {
"id" : "home",
"street" : "10 nifi street",
"city" : "nifi city"
}, {
"id" : "work",
"street" : "10 nifi avenue",
"city" : "apache city"
} ]
Loading
Loading