mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Handle equality comparison in Java execution where one or more fields is null
Fixes #9843. Fixes #10039
This commit is contained in:
parent
4e4c390ac5
commit
96ae3fc158
2 changed files with 30 additions and 2 deletions
|
@ -363,8 +363,12 @@ public interface EventCondition {
|
|||
final EventValueExpression second) {
|
||||
final FieldReference field1 = FieldReference.from(first.getFieldName());
|
||||
final FieldReference field2 = FieldReference.from(second.getFieldName());
|
||||
return event -> event.getEvent().getUnconvertedField(field1)
|
||||
.equals(event.getEvent().getUnconvertedField(field2));
|
||||
return event -> {
|
||||
Event java = event.getEvent();
|
||||
return Objects.equals(
|
||||
java.getUnconvertedField(field1),
|
||||
java.getUnconvertedField(field2));
|
||||
};
|
||||
}
|
||||
|
||||
private static EventCondition truthy(final EventValueExpression evalE) {
|
||||
|
|
|
@ -240,6 +240,30 @@ public final class CompiledPipelineTest extends RubyEnvTestCase {
|
|||
assertCorrectFieldToFieldComparison(gte, 7, 8, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalWithNullField() throws Exception {
|
||||
final PipelineIR pipelineIR = ConfigCompiler.configToPipelineIR(
|
||||
"input {mockinput{}} filter { if [foo] == [bar] { mockaddfilter {} } } output {mockoutput{} }",
|
||||
false
|
||||
);
|
||||
final JrubyEventExtLibrary.RubyEvent testEvent =
|
||||
JrubyEventExtLibrary.RubyEvent.newRubyEvent(RubyUtil.RUBY, new Event());
|
||||
final Map<String, Supplier<IRubyObject>> filters = new HashMap<>();
|
||||
filters.put("mockaddfilter", () -> ADD_FIELD_FILTER);
|
||||
new CompiledPipeline(
|
||||
pipelineIR,
|
||||
new CompiledPipelineTest.MockPluginFactory(
|
||||
Collections.singletonMap("mockinput", () -> null),
|
||||
filters,
|
||||
Collections.singletonMap("mockoutput", mockOutputSupplier())
|
||||
)
|
||||
).buildExecution().compute(RubyUtil.RUBY.newArray(testEvent), false, false);
|
||||
final Collection<JrubyEventExtLibrary.RubyEvent> outputEvents = EVENT_SINKS.get(runId);
|
||||
MatcherAssert.assertThat(outputEvents.size(), CoreMatchers.is(1));
|
||||
MatcherAssert.assertThat(outputEvents.contains(testEvent), CoreMatchers.is(true));
|
||||
MatcherAssert.assertThat(testEvent.getEvent().getField("foo"), CoreMatchers.is("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalNestedMetaFieldPipeline() throws Exception {
|
||||
final PipelineIR pipelineIR = ConfigCompiler.configToPipelineIR(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue