diff --git a/src/main/antlr4/org/s1ck/gdl/GDL.g4 b/src/main/antlr4/org/s1ck/gdl/GDL.g4 index 82382f0..762de97 100644 --- a/src/main/antlr4/org/s1ck/gdl/GDL.g4 +++ b/src/main/antlr4/org/s1ck/gdl/GDL.g4 @@ -138,6 +138,7 @@ literal timeFunc : interval '.' intervalFunc #intvF | timePoint '.' stampFunc #stmpF + | Identifier '.asOf(' timePoint ')' #asOf ; interval @@ -169,7 +170,8 @@ timeLiteral : Datetime | Date | Time - | IntegerLiteral; + | IntegerLiteral + | Now; timeSelector : Identifier '.' TimeProp @@ -177,7 +179,6 @@ timeSelector intervalFunc : overlapsIntervallOperator - | asOfOperator | fromToOperator | betweenOperator | precedesOperator @@ -187,9 +188,6 @@ overlapsIntervallOperator : 'overlaps(' interval ')' ; -asOfOperator - : 'asOf' '(' timePoint ')' - ; fromToOperator : 'fromTo(' timePoint ',' timePoint ')' @@ -210,7 +208,6 @@ succeedsOperator stampFunc : beforePointOperator | afterPointOperator - | asOfOperator | precedesOperator | succeedsOperator ; @@ -346,6 +343,10 @@ Time : Digit Digit ':' Digit Digit (':' Digit Digit)? ; +Now + : ('N'|'n')('O'|'o')('W'|'w') + ; + //------------------------------- // General fragments //------------------------------- diff --git a/src/main/java/org/s1ck/gdl/GDLLoader.java b/src/main/java/org/s1ck/gdl/GDLLoader.java index 6d9542e..cb30159 100644 --- a/src/main/java/org/s1ck/gdl/GDLLoader.java +++ b/src/main/java/org/s1ck/gdl/GDLLoader.java @@ -36,6 +36,8 @@ import java.util.*; import java.util.stream.Collectors; +import static org.s1ck.gdl.utils.Comparator.LTE; + class GDLLoader extends GDLBaseListener { // used to cache elements which are assigned to user-defined variables @@ -89,6 +91,7 @@ class GDLLoader extends GDLBaseListener { private static final String ANONYMOUS_VERTEX_VARIABLE = "__v%d"; private static final String ANONYMOUS_EDGE_VARIABLE = "__e%d"; + /** * Initializes a new GDL Loader. * @@ -375,13 +378,15 @@ public void enterOutgoingEdge(GDLParser.OutgoingEdgeContext outgoingEdgeContext) * Called when the parser leaves a WHERE expression * * Takes care that the filter build from the current expression is stored - * in the graph + * in the graph and that default asOf(now) predicates are added iff there are no constraints + * on any tx_to values * * @param ctx where context */ @Override public void exitWhere(GDLParser.WhereContext ctx) { - addPredicates(Collections.singletonList(currentPredicates.pop())); + Predicate predicate = currentPredicates.pop(); + addPredicates(Collections.singletonList(predicate)); } /** @@ -396,7 +401,7 @@ public void enterComparisonExpression(GDLParser.ComparisonExpressionContext ctx) /** * Builds a {@code Predicate} from the given Intervall-Function (caller is a interval) - * interval functions are e.g. asOf(x), between(x,y).... + * interval functions are e.g. succeeds(x), between(x,y).... * * @param ctx interval function context */ @@ -420,7 +425,7 @@ private Predicate buildIntervalFunction(GDLParser.IntvFContext ctx) { /** * Creates a new predicate about an intervall. There are different types of intervall predicates/ - * functions: asOf, fromTo,... + * functions: precedes, fromTo,... * @param from represents the start time (from value) of the intervall * @param to represents the end time (to value) of the intervall * @param intervalFunc contains the context information needed to create the correct predicate @@ -431,9 +436,6 @@ private Predicate createIntervalPredicates(TimePoint from, TimePoint to, GDLPars if(intervalFunc.overlapsIntervallOperator()!=null){ return createOverlapsPredicates(from, to, intervalFunc.overlapsIntervallOperator()); } - else if(intervalFunc.asOfOperator()!=null){ - return createAsOfPredicates(from, to, intervalFunc.asOfOperator()); - } else if(intervalFunc.fromToOperator()!=null){ return createFromToPredicates(from, to, intervalFunc.fromToOperator()); } @@ -465,10 +467,6 @@ private Predicate createOverlapsPredicates(TimePoint from, TimePoint to, GDLPars return new Comparison(mx, Comparator.LT, mn); } - private Predicate createAsOfPredicates(TimePoint from, TimePoint to, GDLParser.AsOfOperatorContext ctx){ - TimePoint x = buildTimePoint(ctx.timePoint()); - return new And(new Comparison(from, Comparator.LTE, x), new Comparison(to, Comparator.GTE, x)); - } /** * Creates a predicate a.fromTo(x,y)= a.fromx @@ -497,7 +495,7 @@ private Predicate createBetweenPredicates(TimePoint from, TimePoint to, GDLParse TimePoint x = buildTimePoint(ctx.timePoint(0)); TimePoint y = buildTimePoint(ctx.timePoint(1)); return new And( - new Comparison(from, Comparator.LTE, y), + new Comparison(from, LTE, y), new Comparison(to, Comparator.GT, x) ); } @@ -513,7 +511,7 @@ private Predicate createBetweenPredicates(TimePoint from, TimePoint to, GDLParse private Predicate createPrecedesPredicates(TimePoint point, GDLParser.PrecedesOperatorContext ctx){ TimePoint[] arg = buildIntervall(ctx.interval()); TimePoint arg_from = arg[0]; - return new Comparison(point, Comparator.LTE, arg_from); + return new Comparison(point, LTE, arg_from); } /** @@ -556,7 +554,7 @@ else if(ctx.intervalFromStamps()!=null){ /** * Builds a {@code Predicate} from the given TimeStamp-Function (caller is a timestamp) - * time stamp functions are e.g. asOf(x), before(x),... + * time stamp functions are e.g. succeeds(x), before(x),... * * @param ctx stamp function context */ @@ -567,7 +565,7 @@ public void enterStmpF(GDLParser.StmpFContext ctx){ /** * Converts a time stamp function into a (potentially complex) {@code Predicate} - * For example, i.asOf(x) would be translated to a {@code Predicate} i<=x + * For example, i.before(x) would be translated to a {@code Predicate} i vars = new HashSet<>(); + vars.addAll(userEdgeCache.keySet()); + vars.addAll(userVertexCache.keySet()); + vars.addAll(autoEdgeCache.keySet()); + vars.addAll(autoVertexCache.keySet()); + if(vars==null){ + return null; + } + else{ + TimeLiteral now = new TimeLiteral("now"); + ArrayList variables = new ArrayList<>(); + variables.addAll(vars); + Predicate asOfNow = new And( + new Comparison( + new TimeSelector(variables.get(0), TimeSelector.TimeField.TX_FROM), + Comparator.LTE, + now + ), + new Comparison( + new TimeSelector(variables.get(0), TimeSelector.TimeField.TX_TO), + Comparator.GTE, + now + ) + ); + for(int i=1; i exists pi: (pi>=p1 AND pi>=p2...AND pi>=pn) AND (pi==x) diff --git a/src/main/java/org/s1ck/gdl/model/comparables/time/MinTimePoint.java b/src/main/java/org/s1ck/gdl/model/comparables/time/MinTimePoint.java index 994f365..6d6d673 100644 --- a/src/main/java/org/s1ck/gdl/model/comparables/time/MinTimePoint.java +++ b/src/main/java/org/s1ck/gdl/model/comparables/time/MinTimePoint.java @@ -67,6 +67,16 @@ public long getUpperBound(){ return res; } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + for(TimePoint p: args){ + if(p.containsSelectorType(type)){ + return true; + } + } + return false; + } + @Override protected Predicate unfoldEQ(TimePoint arg){ //MIN(p1...pn) == x <=> exists pi: (pi<=p1 AND pi<=p2...AND pi<=pn) AND (pi==x) diff --git a/src/main/java/org/s1ck/gdl/model/comparables/time/PlusTimePoint.java b/src/main/java/org/s1ck/gdl/model/comparables/time/PlusTimePoint.java index 8037b36..ab04334 100644 --- a/src/main/java/org/s1ck/gdl/model/comparables/time/PlusTimePoint.java +++ b/src/main/java/org/s1ck/gdl/model/comparables/time/PlusTimePoint.java @@ -61,6 +61,11 @@ public long getUpperBound(){ return tp_ub + constant.getMillis(); } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return timePoint.containsSelectorType(type); + } + } diff --git a/src/main/java/org/s1ck/gdl/model/comparables/time/TimeLiteral.java b/src/main/java/org/s1ck/gdl/model/comparables/time/TimeLiteral.java index 963b5a9..ab61ac8 100644 --- a/src/main/java/org/s1ck/gdl/model/comparables/time/TimeLiteral.java +++ b/src/main/java/org/s1ck/gdl/model/comparables/time/TimeLiteral.java @@ -32,12 +32,19 @@ public TimeLiteral(long millis){ /** * Constructs a literal from a given string of the form YYYY-MM-DDTHH:MM(:SS) or YYYY-MM-DD + * or "now" * @param date the string to construct the DateTime from */ public TimeLiteral(String date){ try { - date = preprocessDateString(date); - this.time = LocalDateTime.parse(date); + if(date.toLowerCase().equals("now")){ + this.time = LocalDateTime.now(); + } + else{ + date = preprocessDateString(date); + this.time = LocalDateTime.parse(date); + } + } catch(Exception e){ throw new IllegalArgumentException("Date string not in the right format"); @@ -133,6 +140,11 @@ public long getUpperBound(){ return getMilliseconds(); } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return false; + } + /** * Utility method to handle input strings like 1970-01-01. They are not recognized by LocalDateTime. diff --git a/src/main/java/org/s1ck/gdl/model/comparables/time/TimeSelector.java b/src/main/java/org/s1ck/gdl/model/comparables/time/TimeSelector.java index 9611bdf..ea390f7 100644 --- a/src/main/java/org/s1ck/gdl/model/comparables/time/TimeSelector.java +++ b/src/main/java/org/s1ck/gdl/model/comparables/time/TimeSelector.java @@ -89,6 +89,11 @@ public long getUpperBound(){ return Long.MAX_VALUE; } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return timeProp.equals(type); + } + @Override protected Predicate unfoldEQ(TimePoint arg){ return new Comparison(this, Comparator.EQ, arg); diff --git a/src/main/java/org/s1ck/gdl/model/predicates/Predicate.java b/src/main/java/org/s1ck/gdl/model/predicates/Predicate.java index 86e0c70..b7a5b98 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/Predicate.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/Predicate.java @@ -17,6 +17,7 @@ package org.s1ck.gdl.model.predicates; import org.s1ck.gdl.model.GraphElement; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.model.comparables.Literal; import org.s1ck.gdl.model.comparables.PropertySelector; @@ -86,10 +87,8 @@ static Predicate unfoldTemporalComparisons(Predicate p){ unfolded_old = unfolded_new; unfolded_new = unfolded_new.unfoldTemporalComparisonsLeft(); } - System.out.println("After left unfold: " + unfolded_new); // now unfold RHSs until there are only atoms left on right hand sides anymore unfolded_new = unfolded_new.switchSides(); - System.out.println("After switch: " + unfolded_new); while(!unfolded_new.equals(unfolded_old)){ unfolded_old = unfolded_new; unfolded_new = unfolded_new.unfoldTemporalComparisonsLeft(); @@ -126,4 +125,18 @@ static Predicate unfoldTemporalComparisons(Predicate p){ * @return equivalent predicate with rhs and lhs of comparisons switched */ Predicate switchSides(); + + /** + * Checks whether a certain type of selector (val_from, val_to, tx_from, tx_to) is contained + * @param type the type of selector (val_from, val_to, tx_from, tx_to) + * @return true iff the specified type of selector is contained + */ + boolean containsSelectorType(TimeSelector.TimeField type); + + /** + * Checks whether the query contains temporal elements + * @return true iff the query contains temporal elements + */ + boolean isTemporal(); + } diff --git a/src/main/java/org/s1ck/gdl/model/predicates/booleans/And.java b/src/main/java/org/s1ck/gdl/model/predicates/booleans/And.java index bf93c1b..e4325d7 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/booleans/And.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/booleans/And.java @@ -16,6 +16,7 @@ package org.s1ck.gdl.model.predicates.booleans; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.Predicate; import java.util.Set; @@ -60,6 +61,16 @@ public Predicate unfoldTemporalComparisonsLeft(){ return new And(lhs.unfoldTemporalComparisonsLeft(), rhs.unfoldTemporalComparisonsLeft()); } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return lhs.containsSelectorType(type) || rhs.containsSelectorType(type); + } + + @Override + public boolean isTemporal(){ + return lhs.isTemporal() || rhs.isTemporal(); + } + @Override public String toString() { return String.format("(%s AND %s)", lhs, rhs); @@ -76,4 +87,5 @@ public boolean equals(Object o){ And that = (And)o; return (that.lhs.equals(this.lhs) && that.rhs.equals(this.rhs)); } + } diff --git a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Not.java b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Not.java index dba7cab..be842be 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Not.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Not.java @@ -16,6 +16,7 @@ package org.s1ck.gdl.model.predicates.booleans; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.Predicate; import java.util.Set; @@ -53,6 +54,16 @@ public Predicate switchSides(){ return new Not(expression.switchSides()); } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return expression.containsSelectorType(type); + } + + @Override + public boolean isTemporal(){ + return expression.isTemporal(); + } + @Override public String toString() { return String.format("(NOT %s)", expression); diff --git a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Or.java b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Or.java index 6ae52b8..9f1fdbc 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Or.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Or.java @@ -16,6 +16,7 @@ package org.s1ck.gdl.model.predicates.booleans; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.Predicate; import java.util.Set; @@ -60,6 +61,16 @@ public Predicate switchSides(){ return new Or(lhs.switchSides(), rhs.switchSides()); } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return lhs.containsSelectorType(type) || rhs.containsSelectorType(type); + } + + @Override + public boolean isTemporal(){ + return lhs.isTemporal() || rhs.isTemporal(); + } + @Override public String toString() { return String.format("(%s OR %s)", lhs, rhs); diff --git a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Xor.java b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Xor.java index 9349904..fd16587 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/booleans/Xor.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/booleans/Xor.java @@ -16,6 +16,7 @@ package org.s1ck.gdl.model.predicates.booleans; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.Predicate; import java.util.Set; @@ -60,6 +61,16 @@ public Set getVariables() { return variables; } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return lhs.containsSelectorType(type) || rhs.containsSelectorType(type); + } + + @Override + public boolean isTemporal(){ + return lhs.isTemporal() || rhs.isTemporal(); + } + @Override public String toString() { return String.format("(%s XOR %s)", lhs, rhs); diff --git a/src/main/java/org/s1ck/gdl/model/predicates/expressions/Comparison.java b/src/main/java/org/s1ck/gdl/model/predicates/expressions/Comparison.java index 47cf6d6..7091a61 100644 --- a/src/main/java/org/s1ck/gdl/model/predicates/expressions/Comparison.java +++ b/src/main/java/org/s1ck/gdl/model/predicates/expressions/Comparison.java @@ -17,6 +17,7 @@ package org.s1ck.gdl.model.predicates.expressions; import org.s1ck.gdl.model.comparables.time.TimePoint; +import org.s1ck.gdl.model.comparables.time.TimeSelector; import org.s1ck.gdl.model.predicates.Predicate; import org.s1ck.gdl.model.comparables.ComparableExpression; import org.s1ck.gdl.utils.Comparator; @@ -76,14 +77,11 @@ public ComparableExpression[] getComparableExpressions() { return list; } - /** - * Comparisons can be temporal or not (TimePoints can only be compared to TimePoints, enforced by the grammar) - * Method returns whether the comparison is temporal - * @return whether the comparison is temporal - */ + @Override public boolean isTemporal(){ - //time data can only be compared to time data, thus it suffices to check whether lhs a TimePoint - return lhs instanceof TimePoint; + //actually, time data can only be compared to time data (yet), thus it would suffices to check whether + // lhs is a TimePoint at the moment + return lhs instanceof TimePoint || rhs instanceof TimePoint; } @Override @@ -135,6 +133,12 @@ public Set getVariables() { return variables; } + @Override + public boolean containsSelectorType(TimeSelector.TimeField type){ + return lhs.containsSelectorType(type) || rhs.containsSelectorType(type); + } + + @Override public String toString() { return lhs + " " + comparator + " " + rhs; diff --git a/src/test/java/org/s1ck/gdl/GDLLoaderTemporalTest.java b/src/test/java/org/s1ck/gdl/GDLLoaderTemporalTest.java index d391846..e69ea12 100644 --- a/src/test/java/org/s1ck/gdl/GDLLoaderTemporalTest.java +++ b/src/test/java/org/s1ck/gdl/GDLLoaderTemporalTest.java @@ -23,15 +23,15 @@ public class GDLLoaderTemporalTest { public void simpleTimestampFunctionsTest(){ GDLLoader loader = getLoaderFromGDLString( "MATCH (alice)-[e1:knows {since : 2014}]->(bob) (alice)-[e2:knows {since : 2013}]->(eve) " + - "WHERE (e1.tx_from.before(2017-01-01) AND e2.val_to.asOf(2018-12-23T15:55:23)) OR e1.knows>2010"); + "WHERE (e1.val_from.before(2017-01-01) AND e2.tx_to.after(2018-12-23T15:55:23)) OR e1.knows>2010"); System.out.println("Edges: "+loader.getEdgeCache()); System.out.println("Vertices: "+loader.getVertexCache()); System.out.println("Predicates: "+loader.getPredicates()); assertTrue(predicateContainedIn( - new Comparison(new TimeSelector("e1", "tx_from"), Comparator.LT, new TimeLiteral("2017-01-01")), + new Comparison(new TimeSelector("e1", "val_from"), Comparator.LT, new TimeLiteral("2017-01-01")), loader.getPredicates().get().switchSides())); assertTrue(predicateContainedIn( - new Comparison(new TimeSelector("e2", "val_to"), Comparator.LTE, new TimeLiteral("2018-12-23T15:55:23")), + new Comparison(new TimeSelector("e2", "tx_to"), Comparator.GT, new TimeLiteral("2018-12-23T15:55:23")), loader.getPredicates().get().switchSides())); assertTrue(predicateContainedIn( new Comparison(new PropertySelector("e1", "knows"), Comparator.GT, new Literal(2010)), @@ -75,12 +75,20 @@ public void periodLiteralTest(){ @Test public void afterTest(){ GDLLoader loader = getLoaderFromGDLString("MATCH (a)-->(b) " + - "WHERE a.val_from.after(1970-01-01T00:00:01)"); + "WHERE a.val_from.after(1970-01-01T00:00:01) AND a.tx_to.after(1970-01-01T00:00:01)"); Predicate result = loader.getPredicates().get(); - Predicate expected = new Comparison( - new TimeLiteral("1970-01-01T00:00:01"), - Comparator.LT, - new TimeSelector("a", "val_from")); + Predicate expected = + new And( + new Comparison( + new TimeLiteral("1970-01-01T00:00:01"), + Comparator.LT, + new TimeSelector("a", "val_from")), + new Comparison( + new TimeLiteral("1970-01-01T00:00:01"), + Comparator.LT, + new TimeSelector("a", "tx_to")) + + ); assertEquals(result.toString(), expected.toString()); } @@ -138,10 +146,10 @@ public void precedesTest(){ // timestamp as caller loader = getLoaderFromGDLString("MATCH (a)-->(b) " + - "WHERE a.tx_from.precedes(b.val)"); + "WHERE a.tx_to.precedes(b.val)"); result = loader.getPredicates().get(); expected = new Comparison( - new TimeSelector("a", TimeSelector.TimeField.TX_FROM), + new TimeSelector("a", TimeSelector.TimeField.TX_TO), Comparator.LTE, new TimeSelector("b", TimeSelector.TimeField.VAL_FROM) ).switchSides(); @@ -162,16 +170,37 @@ public void succeedsTest(){ // timestamp as caller loader = getLoaderFromGDLString("MATCH (a)-->(b) " + - "WHERE a.val_to.succeeds(b.tx)"); + "WHERE a.tx_to.succeeds(b.val)"); result = loader.getPredicates().get(); expected = new Comparison( - new TimeSelector("a", TimeSelector.TimeField.VAL_TO), + new TimeSelector("a", TimeSelector.TimeField.TX_TO), Comparator.GTE, - new TimeSelector("b", TimeSelector.TimeField.TX_TO) + new TimeSelector("b", TimeSelector.TimeField.VAL_TO) ).switchSides(); assertEquals(result.toString(), expected.toString()); } + @Test + public void asOfTest(){ + GDLLoader loader = getLoaderFromGDLString("MATCH (a)-[e]->(b) " + + "WHERE e.asOf(1970-01-01"); + Predicate result = loader.getPredicates().get(); + Predicate expected = new And( + new Comparison( + new TimeSelector("e", TimeSelector.TimeField.TX_FROM), + Comparator.LTE, + new TimeLiteral("1970-01-01") + ), + new Comparison( + new TimeSelector("e", TimeSelector.TimeField.TX_TO), + Comparator.GTE, + new TimeLiteral("1970-01-01") + ) + ).switchSides(); + assertEquals(result.toString(), expected.toString()); + } + + @Test public void graphTimeStampTest(){ diff --git a/src/test/java/org/s1ck/gdl/comparables/time/MaxTimeTest.java b/src/test/java/org/s1ck/gdl/comparables/time/MaxTimeTest.java index 0e05497..d58b37d 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/MaxTimeTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/MaxTimeTest.java @@ -7,8 +7,7 @@ import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.utils.Comparator; - -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class MaxTimeTest { @@ -287,4 +286,16 @@ public void unfoldLTETest(){ System.out.println(unfolded); assertEquals(expected, unfolded); } + + @Test + public void containsTxToTest(){ + TimeSelector s1 = new TimeSelector("a", "val_to"); + TimeLiteral l = new TimeLiteral("2020-04-28"); + MaxTimePoint m1 = new MaxTimePoint(s1,l); + assertFalse(m1.containsSelectorType(TimeSelector.TimeField.TX_TO)); + + TimeSelector s2 = new TimeSelector("a", "tx_to"); + MaxTimePoint m2 = new MaxTimePoint(s2,l); + assertTrue(m2.containsSelectorType(TimeSelector.TimeField.TX_TO)); + } } diff --git a/src/test/java/org/s1ck/gdl/comparables/time/MinTimeTest.java b/src/test/java/org/s1ck/gdl/comparables/time/MinTimeTest.java index b58b25d..50ea268 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/MinTimeTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/MinTimeTest.java @@ -12,8 +12,7 @@ import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.utils.Comparator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; public class MinTimeTest { @@ -296,6 +295,18 @@ public void unfoldLTETest(){ assertEquals(expected, unfolded); } + @Test + public void containsTxToTest(){ + TimeSelector s1 = new TimeSelector("a", "val_to"); + TimeLiteral l = new TimeLiteral("2020-04-28"); + MinTimePoint m1 = new MinTimePoint(s1,l); + assertFalse(m1.containsSelectorType(TimeSelector.TimeField.TX_TO)); + + TimeSelector s2 = new TimeSelector("a", "tx_to"); + MinTimePoint m2 = new MinTimePoint(s2,l); + assertTrue(m2.containsSelectorType(TimeSelector.TimeField.TX_TO)); + } + diff --git a/src/test/java/org/s1ck/gdl/comparables/time/PlusTimeTest.java b/src/test/java/org/s1ck/gdl/comparables/time/PlusTimeTest.java index 3e5a5fe..a2e0f00 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/PlusTimeTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/PlusTimeTest.java @@ -6,7 +6,7 @@ import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.utils.Comparator; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class PlusTimeTest { @@ -102,4 +102,16 @@ public void unfoldPredicateTest(){ assertEquals(plus.unfoldComparison(Comparator.LTE, s), cLte); } + + @Test + public void containsTxToTest(){ + TimeConstant c = new TimeConstant(1000); + TimeSelector s1 = new TimeSelector("a", "val_from"); + PlusTimePoint p1 = new PlusTimePoint(s1, c); + assertFalse(p1.containsSelectorType(TimeSelector.TimeField.TX_TO)); + + TimeSelector s2 = new TimeSelector("a", "tx_to"); + PlusTimePoint p2 = new PlusTimePoint(s2, c); + assertTrue(p2.containsSelectorType(TimeSelector.TimeField.TX_TO));maxPlusTest(); + } } diff --git a/src/test/java/org/s1ck/gdl/comparables/time/TimeLiteralTest.java b/src/test/java/org/s1ck/gdl/comparables/time/TimeLiteralTest.java index 4ba06e2..a5186fe 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/TimeLiteralTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/TimeLiteralTest.java @@ -5,7 +5,12 @@ import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.utils.Comparator; -import static org.junit.Assert.assertEquals; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Date; + +import static org.junit.Assert.*; public class TimeLiteralTest { @@ -45,6 +50,13 @@ public void stringInitTest(){ assertEquals(tl2.getHour(),0); assertEquals(tl2.getMinute(),0); assertEquals(tl2.getSecond(), 0); + + TimeLiteral tl3 = new TimeLiteral("now"); + System.out.println(tl3.getMilliseconds()); + long millis = LocalDateTime.now().toInstant(ZoneOffset.ofTotalSeconds(0)).toEpochMilli(); + //should work... + assertTrue(millis - tl3.getMilliseconds() > 0); + assertTrue(millis - tl3.getMilliseconds() < 5000); } @Test @@ -67,4 +79,10 @@ public void unfoldPredicateTest(){ assertEquals(literal.unfoldComparison(Comparator.LTE, s), cLte); } + + @Test + public void containsTxToTest(){ + TimeLiteral literal = new TimeLiteral("1970-02-01T15:23:05"); + assertFalse(literal.containsSelectorType(TimeSelector.TimeField.TX_TO)); + } } diff --git a/src/test/java/org/s1ck/gdl/comparables/time/TimeSelectorTest.java b/src/test/java/org/s1ck/gdl/comparables/time/TimeSelectorTest.java index f9d43d6..661b3cb 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/TimeSelectorTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/TimeSelectorTest.java @@ -4,7 +4,7 @@ import org.s1ck.gdl.model.predicates.expressions.Comparison; import org.s1ck.gdl.utils.Comparator; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; public class TimeSelectorTest { @@ -39,4 +39,16 @@ public void unfoldPredicateTest(){ assertEquals(selector.unfoldComparison(Comparator.LTE, s2), cLte); } + + @Test + public void containsTxToTest(){ + TimeSelector valF = new TimeSelector("a", "val_from"); + assertFalse(valF.containsSelectorType(TimeSelector.TimeField.TX_TO)); + TimeSelector valT = new TimeSelector("a", "val_to"); + assertFalse(valT.containsSelectorType(TimeSelector.TimeField.TX_TO)); + TimeSelector txF = new TimeSelector("a", "tx_from"); + assertFalse(txF.containsSelectorType(TimeSelector.TimeField.TX_TO)); + TimeSelector txT = new TimeSelector("a", "tx_to"); + assertTrue(txT.containsSelectorType(TimeSelector.TimeField.TX_TO)); + } } diff --git a/src/test/java/org/s1ck/gdl/comparables/time/TimeConstantTest.java b/src/test/java/org/s1ck/gdl/comparables/time/util/TimeConstantTest.java similarity index 94% rename from src/test/java/org/s1ck/gdl/comparables/time/TimeConstantTest.java rename to src/test/java/org/s1ck/gdl/comparables/time/util/TimeConstantTest.java index e4f85ea..cd5d0f6 100644 --- a/src/test/java/org/s1ck/gdl/comparables/time/TimeConstantTest.java +++ b/src/test/java/org/s1ck/gdl/comparables/time/util/TimeConstantTest.java @@ -1,4 +1,4 @@ -package org.s1ck.gdl.comparables.time; +package org.s1ck.gdl.comparables.time.util; import org.junit.Test; import org.s1ck.gdl.model.comparables.time.util.TimeConstant; import org.s1ck.gdl.model.comparables.time.TimeLiteral;