-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial date arithmetic support #91 * code generation and interpreter date arithmetic plus tests * remove obsolete comment about operator selection * 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 * add individual function tests add test for subtracting 10000 years
- Loading branch information
Showing
20 changed files
with
693 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
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
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
50 changes: 50 additions & 0 deletions
50
...og/plugins/pipelineprocessor/functions/dates/periods/AbstractPeriodComponentFunction.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,50 @@ | ||
package org.graylog.plugins.pipelineprocessor.functions.dates.periods; | ||
|
||
import com.google.common.primitives.Ints; | ||
|
||
import org.graylog.plugins.pipelineprocessor.EvaluationContext; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.AbstractFunction; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.FunctionDescriptor; | ||
import org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor; | ||
import org.joda.time.Period; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public abstract class AbstractPeriodComponentFunction extends AbstractFunction<Period> { | ||
|
||
private final ParameterDescriptor<Long, Period> value = | ||
ParameterDescriptor | ||
.integer("value", Period.class) | ||
.transform(this::getPeriodOfInt) | ||
.build(); | ||
|
||
private Period getPeriodOfInt(long period) { | ||
return getPeriod(Ints.saturatedCast(period)); | ||
} | ||
|
||
@Nonnull | ||
protected abstract Period getPeriod(int period); | ||
|
||
@Override | ||
public Period evaluate(FunctionArgs args, EvaluationContext context) { | ||
return value.required(args, context); | ||
} | ||
|
||
@Override | ||
public FunctionDescriptor<Period> descriptor() { | ||
return FunctionDescriptor.<Period>builder() | ||
.name(getName()) | ||
.description(getDescription()) | ||
.pure(true) | ||
.returnType(Period.class) | ||
.params(value) | ||
.build(); | ||
} | ||
|
||
@Nonnull | ||
protected abstract String getName(); | ||
|
||
@Nonnull | ||
protected abstract String getDescription(); | ||
} |
28 changes: 28 additions & 0 deletions
28
plugin/src/main/java/org/graylog/plugins/pipelineprocessor/functions/dates/periods/Days.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,28 @@ | ||
package org.graylog.plugins.pipelineprocessor.functions.dates.periods; | ||
|
||
import org.joda.time.Period; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class Days extends AbstractPeriodComponentFunction { | ||
|
||
public static final String NAME = "days"; | ||
|
||
@Nonnull | ||
@Override | ||
protected Period getPeriod(int period) { | ||
return Period.days(period); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getName() { | ||
return NAME; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getDescription() { | ||
return "Create a period with a specified number of days."; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...in/src/main/java/org/graylog/plugins/pipelineprocessor/functions/dates/periods/Hours.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,28 @@ | ||
package org.graylog.plugins.pipelineprocessor.functions.dates.periods; | ||
|
||
import org.joda.time.Period; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class Hours extends AbstractPeriodComponentFunction { | ||
|
||
public static final String NAME = "hours"; | ||
|
||
@Nonnull | ||
@Override | ||
protected Period getPeriod(int period) { | ||
return Period.hours(period); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getName() { | ||
return NAME; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getDescription() { | ||
return "Create a period with a specified number of hours."; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...n/src/main/java/org/graylog/plugins/pipelineprocessor/functions/dates/periods/Millis.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,28 @@ | ||
package org.graylog.plugins.pipelineprocessor.functions.dates.periods; | ||
|
||
import org.joda.time.Period; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class Millis extends AbstractPeriodComponentFunction { | ||
|
||
public static final String NAME = "millis"; | ||
|
||
@Nonnull | ||
@Override | ||
protected Period getPeriod(int period) { | ||
return Period.millis(period); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getName() { | ||
return NAME; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getDescription() { | ||
return "Create a period with a specified number of millis."; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/org/graylog/plugins/pipelineprocessor/functions/dates/periods/Minutes.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,28 @@ | ||
package org.graylog.plugins.pipelineprocessor.functions.dates.periods; | ||
|
||
import org.joda.time.Period; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class Minutes extends AbstractPeriodComponentFunction { | ||
|
||
public static final String NAME = "minutes"; | ||
|
||
@Nonnull | ||
@Override | ||
protected Period getPeriod(int period) { | ||
return Period.minutes(period); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getName() { | ||
return NAME; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected String getDescription() { | ||
return "Create a period with a specified number of minutes."; | ||
} | ||
} |
Oops, something went wrong.