This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent adding two dates at parse time
attempting to add (not subtract) two dates raises an InvalidOperation parse error because there aren't any sane semantics for doing so while subtraction gives the duration between the dates, there's hardly any good reason to add them
- Loading branch information
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...n/src/main/java/org/graylog/plugins/pipelineprocessor/parser/errors/InvalidOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.graylog.plugins.pipelineprocessor.parser.errors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import org.antlr.v4.runtime.ParserRuleContext; | ||
import org.graylog.plugins.pipelineprocessor.ast.expressions.Expression; | ||
|
||
public class InvalidOperation extends ParseError { | ||
private final Expression expr; | ||
|
||
private final String message; | ||
|
||
public InvalidOperation(ParserRuleContext ctx, Expression expr, String message) { | ||
super("invalid_operation", ctx); | ||
this.expr = expr; | ||
this.message = message; | ||
} | ||
|
||
@JsonProperty("reason") | ||
@Override | ||
public String toString() { | ||
return "Invalid operation: " + message; | ||
} | ||
|
||
public Expression getExpression() { | ||
return expr; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...n/src/test/resources/org/graylog/plugins/pipelineprocessor/parser/invalidDateAddition.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rule "cannot add dates" | ||
when | ||
now() + now() == now() | ||
end |