Skip to content

Commit

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

[Cherry-pick] [6.8] Initialize dq_failure before use in send-to-error directive
  • Loading branch information
DJSagarAhire authored Feb 14, 2024
2 parents 56c91cd + e8c0ea9 commit 3cf97eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>io.cdap.wrangler</groupId>
<artifactId>wrangler</artifactId>
<version>4.8.2</version>
<version>4.8.3-SNAPSHOT</version>
<name>Wrangler</name>
<packaging>pom</packaging>
<description>An interactive tool for data cleansing and transformation.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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 3cf97eb

Please sign in to comment.