Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-pick] [6.8] Initialize dq_failure before use in send-to-error directive #703

Merged
merged 1 commit into from
Feb 14, 2024
Merged
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
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());
}
}