Skip to content

Commit

Permalink
Merge pull request #701 from data-integrations/PLUGIN-1736-send-to-er…
Browse files Browse the repository at this point in the history
…ror-410

[Cherry-pick] [6.10] Initialize dq_failure before use in send-to-error directive
  • Loading branch information
DJSagarAhire authored Feb 14, 2024
2 parents 4f81b98 + 99676e4 commit 90c9208
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public List<Row> execute(List<Row> rows, ExecutorContext context)
context.getTransientStore().increment(TransientVariableScope.LOCAL, "dq_failure", 1);
}
throw new ReportErrorAndProceed(message, 1);
} else if (context != null && !context.getTransientStore().getVariables().contains("dq_failure")) {
context.getTransientStore().set(TransientVariableScope.LOCAL, "dq_failure", 0L);
}
} catch (ELException e) {
throw new DirectiveExecutionException(NAME, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,29 @@ public void testErrorConditionTrueAndContinueWithTransientVariable() throws Exce
Assert.assertEquals(2, errors.size());
Assert.assertEquals(3, results.size());
}

@Test
public void testErrorConditionFalseAndContinueWithTransientVariable() throws Exception {
String[] directives = new String[] {
"parse-as-csv body , true",
"drop body",
"send-to-error-and-continue exp:{body_3 == 'xyzw'} 'invalid value'",
"send-to-error-and-continue exp:{body_4=='1000'} 'junk' ",
"send-to-error exp:{dq_failure >= 1} "
};

List<Row> rows = Arrays.asList(
new Row("body", "1020134.298,,1,2,2 "),
new Row("body", "1020134.298,,xx,1,3"),
new Row("body", "1020134.298,,4,1,4"),
new Row("body", "1020134.298,,4,2,5"),
new Row("body", "1020134.298,,1,2,1")
);

RecipePipeline pipeline = TestingRig.execute(directives);
List<Row> results = pipeline.execute(rows);
List<ErrorRecord> errors = pipeline.errors();
Assert.assertEquals(0, errors.size());
Assert.assertEquals(5, results.size());
}
}

0 comments on commit 90c9208

Please sign in to comment.