├── protoc.exe ├── .gitignore ├── RQLServer ├── src │ ├── main │ │ └── java │ │ │ └── retroscope │ │ │ └── rql │ │ │ ├── syntaxtree │ │ │ ├── AggregatorType.java │ │ │ ├── expression │ │ │ │ ├── IllegalExpressionException.java │ │ │ │ ├── condition │ │ │ │ │ ├── Ternary.java │ │ │ │ │ └── Condition.java │ │ │ │ ├── stackedexpression │ │ │ │ │ ├── IteratingFunc.java │ │ │ │ │ ├── ForEach.java │ │ │ │ │ ├── Exists.java │ │ │ │ │ ├── ForAll.java │ │ │ │ │ └── ForSome.java │ │ │ │ ├── EvalExpression.java │ │ │ │ ├── literals │ │ │ │ │ ├── IntegerLiteral.java │ │ │ │ │ ├── StringLiteral.java │ │ │ │ │ ├── FloatLiteral.java │ │ │ │ │ ├── SetLiteral.java │ │ │ │ │ └── Variable.java │ │ │ │ ├── sets │ │ │ │ │ ├── IsSubset.java │ │ │ │ │ ├── SetDifference.java │ │ │ │ │ ├── InOperator.java │ │ │ │ │ ├── IsProperSubset.java │ │ │ │ │ ├── Union.java │ │ │ │ │ ├── Intersect.java │ │ │ │ │ ├── NotInOperator.java │ │ │ │ │ ├── SymbolAndSetOperator.java │ │ │ │ │ └── SetOperator.java │ │ │ │ ├── compare │ │ │ │ │ ├── EQExpression.java │ │ │ │ │ ├── NEQExpression.java │ │ │ │ │ ├── GEQExpression.java │ │ │ │ │ ├── LEQExpression.java │ │ │ │ │ ├── LessThanExpression.java │ │ │ │ │ ├── GreaterThanExpression.java │ │ │ │ │ └── CompareExpression.java │ │ │ │ ├── arithmetic │ │ │ │ │ ├── Mod.java │ │ │ │ │ ├── Plus.java │ │ │ │ │ ├── Multiply.java │ │ │ │ │ ├── Divide.java │ │ │ │ │ ├── Minus.java │ │ │ │ │ └── ArithmeticExpression.java │ │ │ │ ├── ExpressionList.java │ │ │ │ ├── TwoOperandExpression.java │ │ │ │ ├── assign │ │ │ │ │ ├── OutExpression.java │ │ │ │ │ ├── AssignExpression.java │ │ │ │ │ └── DeclareExpression.java │ │ │ │ ├── Expression.java │ │ │ │ ├── logical │ │ │ │ │ ├── Or.java │ │ │ │ │ ├── LogicalExpression.java │ │ │ │ │ ├── NotExpression.java │ │ │ │ │ └── And.java │ │ │ │ └── FuncCall.java │ │ │ ├── Aggregator.java │ │ │ ├── When.java │ │ │ ├── OnTime.java │ │ │ ├── AtNodes.java │ │ │ ├── ParamList.java │ │ │ ├── IdentifierList.java │ │ │ ├── Query.java │ │ │ ├── TimeSearch.java │ │ │ ├── Param.java │ │ │ └── QueryEnd.java │ │ │ ├── environment │ │ │ ├── EnvironmentStack.java │ │ │ ├── SymbolTable.java │ │ │ └── GlobalCut.java │ │ │ ├── server │ │ │ ├── DistributedJobException.java │ │ │ ├── Runner.java │ │ │ ├── StatementProcessor.java │ │ │ └── SearchJobCallable.java │ │ │ ├── errors │ │ │ ├── RQLRunTimeException.java │ │ │ └── RQLRunTimeWarning.java │ │ │ ├── parser │ │ │ ├── Valuable.java │ │ │ └── mTokens.java │ │ │ └── functions │ │ │ ├── Sum.java │ │ │ ├── Max.java │ │ │ ├── Min.java │ │ │ ├── Tan.java │ │ │ ├── NodeSum.java │ │ │ ├── Sin.java │ │ │ ├── Cos.java │ │ │ ├── Abs.java │ │ │ ├── Ceil.java │ │ │ ├── Floor.java │ │ │ ├── RQLBuiltInFunction.java │ │ │ ├── Node.java │ │ │ ├── Subset.java │ │ │ ├── Cardinality.java │ │ │ ├── Flatten.java │ │ │ └── AbstractMathFunc.java │ └── test │ │ └── java │ │ └── retroscope │ │ └── rql │ │ └── server │ │ ├── DistributedQueryStructTest.java │ │ ├── DistributedQuerySetStructTest.java │ │ └── LocalQueryRunnerStringsTest.java ├── log4j.config ├── pom.xml └── RQLServer.iml ├── RetroLogServer ├── src │ ├── main │ │ ├── java │ │ │ ├── retroscope │ │ │ │ ├── datamodel │ │ │ │ │ ├── datastruct │ │ │ │ │ │ ├── RQLType.java │ │ │ │ │ │ ├── RQLDataStructure.java │ │ │ │ │ │ ├── misc │ │ │ │ │ │ │ └── IdList.java │ │ │ │ │ │ ├── variables │ │ │ │ │ │ │ ├── LongRQLVariable.java │ │ │ │ │ │ │ ├── DoubleRQLVariable.java │ │ │ │ │ │ │ ├── StringRQLVariable.java │ │ │ │ │ │ │ └── RQLVariable.java │ │ │ │ │ │ ├── Null.java │ │ │ │ │ │ ├── sets │ │ │ │ │ │ │ ├── RemoveRQLSet.java │ │ │ │ │ │ │ ├── AppendRQLSet.java │ │ │ │ │ │ │ └── TimerRQLSet.java │ │ │ │ │ │ └── RQLSymbol.java │ │ │ │ │ └── parser │ │ │ │ │ │ ├── SetItems.java │ │ │ │ │ │ ├── dataTokens.java │ │ │ │ │ │ ├── datamodel.flex │ │ │ │ │ │ └── RQLData.java │ │ │ │ ├── net │ │ │ │ │ ├── ignite │ │ │ │ │ │ ├── StreamEntry.java │ │ │ │ │ │ ├── EventStreamEntry.java │ │ │ │ │ │ ├── CommitStreamEntry.java │ │ │ │ │ │ └── NodeMeta.java │ │ │ │ │ ├── RetroscopeNetworkException.java │ │ │ │ │ └── Streamer.java │ │ │ │ ├── log │ │ │ │ │ ├── BasicLog.java │ │ │ │ │ ├── LogOutTimeBoundsException.java │ │ │ │ │ └── RetroscopeSnapshotException.java │ │ │ │ ├── LogTypeException.java │ │ │ │ ├── LogNotFoundException.java │ │ │ │ ├── RetroscopeException.java │ │ │ │ ├── util │ │ │ │ │ ├── netHLCSerializer.java │ │ │ │ │ └── ByteArray.java │ │ │ │ └── hlc │ │ │ │ │ └── Timestamp.java │ │ │ └── META-INF │ │ │ │ └── MANIFEST.MF │ │ └── protoc │ │ │ └── protocol.proto │ └── test │ │ └── java │ │ └── retroscope │ │ ├── RetroscopeTest.java │ │ └── datamodel │ │ └── parser │ │ └── RQLDataTest.java ├── retroscope-library.iml ├── log4j.config ├── pom.xml └── RetroLogServer.iml ├── log4j.config ├── RetroAppViewer ├── log4j.config ├── src │ └── main │ │ └── java │ │ └── retroscope │ │ └── appviewer │ │ └── AppData.java ├── pom.xml └── RetroAppViewer.iml ├── smb_start.bat ├── RQLBench ├── src │ └── main │ │ └── java │ │ └── retroscope │ │ └── bench │ │ └── QueryResult.java ├── pom.xml └── RQLBench.iml ├── IgniteServer ├── log4j.config ├── src │ └── main │ │ └── java │ │ └── retroscope │ │ └── net │ │ └── igniteserver │ │ └── IgniteServer.java ├── pom.xml └── IgniteServer.iml ├── RetrscopeExample ├── log4j.config ├── pom.xml └── RetrscopeExample.iml ├── LICENSE ├── README.md ├── retroscope-config.xml ├── retroscope.iml └── pom.xml /protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acharapko/retroscope-lib/HEAD/protoc.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | */target/* 3 | */artifacts/* 4 | iplist.txt 5 | aws/* 6 | *.txt 7 | RQLServer/src/test/java/retroscope/rql/server/zktest/* 8 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/AggregatorType.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | public enum AggregatorType { 4 | SUM, 5 | COUNT 6 | } 7 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/RQLType.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct; 2 | 3 | public enum RQLType { 4 | VAR, 5 | SET, 6 | LIST 7 | } 8 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/environment/EnvironmentStack.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.environment; 2 | 3 | import java.util.Stack; 4 | 5 | public class EnvironmentStack extends Stack { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: commons-codec-1.9.jar protobuf-java-2.6.1.jar hamcrest-cor 3 | e-1.3.jar junit-4.11.jar netty-all-4.1.5.Final.jar 4 | Main-Class: 5 | 6 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/ignite/StreamEntry.java: -------------------------------------------------------------------------------- 1 | package retroscope.net.ignite; 2 | 3 | public interface StreamEntry extends Cloneable { 4 | 5 | long getHLCTime(); 6 | 7 | String getEntry(); 8 | } 9 | -------------------------------------------------------------------------------- /RetroLogServer/retroscope-library.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/RQLDataStructure.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct; 2 | 3 | public interface RQLDataStructure extends Cloneable{ 4 | 5 | String getName(); 6 | 7 | void setName(String name); 8 | 9 | String toRQLString(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/log/BasicLog.java: -------------------------------------------------------------------------------- 1 | package retroscope.log; 2 | 3 | /** 4 | * Created by Aleksey on 1/31/2017. 5 | * 6 | */ 7 | public interface BasicLog { 8 | 9 | String getName(); 10 | 11 | //LogEntry getHead(); 12 | 13 | //LogEntry getTail(); 14 | 15 | int getLength(); 16 | } 17 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/server/DistributedJobException.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import retroscope.rql.errors.RQLRunTimeException; 4 | 5 | public class DistributedJobException extends RQLRunTimeException { 6 | 7 | public DistributedJobException(String message) { 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=DEBUG, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | # A1 uses PatternLayout. 9 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /RetroLogServer/log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=INFO, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | # A1 uses PatternLayout. 9 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/LogTypeException.java: -------------------------------------------------------------------------------- 1 | package retroscope; 2 | 3 | /** 4 | * Created by Aleksey on 12/28/2016. 5 | * exception cleitn network errors 6 | */ 7 | public class LogTypeException extends RetroscopeException { 8 | public LogTypeException(String message) { 9 | super(RetroscopeException.INCORRECT_LOG_TYPE, message); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/errors/RQLRunTimeException.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.errors; 2 | 3 | /** 4 | * Created by ALEKS on 1/12/2017. 5 | * Exception to be thrown during RQL runtime, if runtime errors arise 6 | */ 7 | public class RQLRunTimeException extends Exception { 8 | public RQLRunTimeException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /RetroAppViewer/log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=DEBUG, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | # A1 uses PatternLayout. 9 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/LogNotFoundException.java: -------------------------------------------------------------------------------- 1 | package retroscope; 2 | 3 | /** 4 | * Created by Aleksey on 12/28/2016. 5 | * exception cleitn network errors 6 | */ 7 | public class LogNotFoundException extends RetroscopeException { 8 | public LogNotFoundException(String message) { 9 | super(RetroscopeException.LOG_DOES_NOT_EXIST, message); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /smb_start.bat: -------------------------------------------------------------------------------- 1 | echo Starting SimpleMultiNode Test 2 | java -jar D:\Dropbox\Retroscope++\retroscope-lib\IgniteServer\target\IgniteServer-1.0-SNAPSHOT-jar-with-dependencies.jar D:\Dropbox\Retroscope++\retroscope-lib\IgniteServer\target\retroscope-config.xml 3 | java -jar RetrscopeExample-1.0-SNAPSHOT-jar-with-dependencies.jar 12000 iplist.txt D:\Dropbox\Retroscope++\retroscope-lib\IgniteServer\target\retroscope-config.xml 10 50 192.168.1.3 -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/log/LogOutTimeBoundsException.java: -------------------------------------------------------------------------------- 1 | package retroscope.log; 2 | 3 | import retroscope.RetroscopeException; 4 | 5 | /** 6 | * Created by aleksey on 10/17/16. 7 | * 8 | */ 9 | public class LogOutTimeBoundsException extends RetroscopeException { 10 | public LogOutTimeBoundsException(String message) { 11 | super(RetroscopeException.LOG_OUT_OF_BOUNDS, message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/IllegalExpressionException.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | import retroscope.rql.errors.RQLRunTimeException; 4 | 5 | /** 6 | * Created by Aleksey on 12/21/2016. 7 | * 8 | */ 9 | public class IllegalExpressionException extends RQLRunTimeException { 10 | public IllegalExpressionException(String message) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/Aggregator.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | /** 4 | * Created by Aleksey on 12/20/2016. 5 | */ 6 | public class Aggregator { 7 | 8 | private AggregatorType aggregator; 9 | 10 | 11 | public Aggregator(AggregatorType aggregator) { 12 | this.aggregator = aggregator; 13 | } 14 | 15 | public AggregatorType getAggregator() { 16 | return aggregator; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/log/RetroscopeSnapshotException.java: -------------------------------------------------------------------------------- 1 | package retroscope.log; 2 | 3 | import retroscope.RetroscopeException; 4 | 5 | /** 6 | * Created by Aleksey on 12/28/2016. 7 | * exception for snapshots 8 | */ 9 | public class RetroscopeSnapshotException extends RetroscopeException { 10 | public RetroscopeSnapshotException(String message) { 11 | super(RetroscopeException.SNAPSHOT_DOES_NOT_EXIST, message); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/RetroscopeNetworkException.java: -------------------------------------------------------------------------------- 1 | package retroscope.net; 2 | 3 | import retroscope.RetroscopeException; 4 | 5 | /** 6 | * Created by Aleksey on 12/28/2016. 7 | * exception cleitn network errors 8 | */ 9 | public class RetroscopeNetworkException extends RetroscopeException { 10 | public RetroscopeNetworkException(String message) { 11 | super(RetroscopeException.CLIENT_NETWORK_ERROR, message); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/When.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | import retroscope.rql.syntaxtree.expression.Expression; 4 | 5 | /** 6 | * Created by Aleksey on 12/20/2016. 7 | * 8 | */ 9 | public class When { 10 | 11 | private Expression expression; 12 | 13 | public When(Expression expression) { 14 | this.expression = expression; 15 | } 16 | 17 | public Expression getConditions() { 18 | return expression; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /RQLBench/src/main/java/retroscope/bench/QueryResult.java: -------------------------------------------------------------------------------- 1 | package retroscope.bench; 2 | 3 | public class QueryResult { 4 | 5 | private long queryRuntime; 6 | private int numCuts; 7 | 8 | public QueryResult(long queryRuntime, int numCuts) { 9 | this.queryRuntime = queryRuntime; 10 | this.numCuts = numCuts; 11 | } 12 | 13 | public long getQueryRuntime() { 14 | return queryRuntime; 15 | } 16 | 17 | public int getNumCuts() { 18 | return numCuts; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/misc/IdList.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.misc; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | public class IdList { 7 | 8 | private Set ids; 9 | 10 | public IdList(long id) { 11 | ids = new HashSet<>(); 12 | this.ids.add(id); 13 | } 14 | 15 | public void addId(long id) { 16 | ids.add(id); 17 | } 18 | 19 | public Set getIds() { 20 | return ids; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/parser/Valuable.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.parser; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.rql.environment.EnvironmentStack; 5 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 6 | 7 | /** 8 | * Created by Aleksey on 1/21/2017. 9 | */ 10 | public interface Valuable { 11 | 12 | RQLSymbol getValue(); 13 | 14 | void evaluate() throws IllegalExpressionException; 15 | 16 | void setEnvironmentStack(EnvironmentStack environment); 17 | } 18 | -------------------------------------------------------------------------------- /IgniteServer/log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=DEBUG, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | #log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | log4j.appender.A1=org.apache.log4j.RollingFileAppender 9 | 10 | log4j.appender.A1.File=logIS.txt 11 | log4j.appender.A1.maxFileSize = 50MB 12 | log4j.appender.A1.MaxBackupIndex=10 13 | 14 | # A1 uses PatternLayout. 15 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n -------------------------------------------------------------------------------- /RQLServer/log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=DEBUG, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | #log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | log4j.appender.A1=org.apache.log4j.RollingFileAppender 9 | 10 | log4j.appender.A1.File=F:\\logRQLS.txt 11 | log4j.appender.A1.maxFileSize = 50MB 12 | log4j.appender.A1.MaxBackupIndex=10 13 | 14 | # A1 uses PatternLayout. 15 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 17 | -------------------------------------------------------------------------------- /RetroLogServer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | RetroLogServer 13 | 14 | 15 | -------------------------------------------------------------------------------- /RetrscopeExample/log4j.config: -------------------------------------------------------------------------------- 1 | 2 | # Set root logger level to DEBUG and its only appender to A1. 3 | log4j.rootLogger=DEBUG, A1 4 | 5 | # A1 is set to be a ConsoleAppender. 6 | #log4j.appender.A1=org.apache.log4j.ConsoleAppender 7 | 8 | log4j.appender.A1=org.apache.log4j.RollingFileAppender 9 | 10 | log4j.appender.A1.File=F:\\logExample.txt 11 | log4j.appender.A1.maxFileSize = 50MB 12 | log4j.appender.A1.MaxBackupIndex=10 13 | 14 | # A1 uses PatternLayout. 15 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n 17 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/OnTime.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | import retroscope.rql.syntaxtree.expression.Expression; 4 | 5 | /** 6 | * Created by Aleksey on 12/20/2016. 7 | */ 8 | public class OnTime { 9 | 10 | private Expression timeEx1, timeEx2; 11 | 12 | public OnTime(Expression ex1, Expression ex2) { 13 | timeEx1 = ex1; 14 | timeEx2 = ex2; 15 | } 16 | 17 | public Expression getTimeEx1() { 18 | return timeEx1; 19 | } 20 | 21 | public Expression getTimeEx2() { 22 | return timeEx2; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 SUNY Buffalo 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/Streamer.java: -------------------------------------------------------------------------------- 1 | package retroscope.net; 2 | 3 | import retroscope.log.RetroscopeLog; 4 | import retroscope.net.ignite.StreamEntry; 5 | 6 | /** 7 | * Created by Aleksey on 7/23/2017. 8 | * 9 | */ 10 | public interface Streamer { 11 | 12 | 13 | boolean connect(); 14 | 15 | boolean connect(int nodeID); 16 | 17 | void stream(StreamEntry streamEntry, RetroscopeLog log, long blockTime); 18 | 19 | void streamCommit(RetroscopeLog log, long lastEntryHLC); 20 | 21 | void addStreamer(String logName); 22 | 23 | void close(); 24 | 25 | void flushStreams(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/ignite/EventStreamEntry.java: -------------------------------------------------------------------------------- 1 | package retroscope.net.ignite; 2 | 3 | 4 | /** 5 | * Created by aleksey on 7/17/16. 6 | */ 7 | public class EventStreamEntry implements StreamEntry{ 8 | 9 | protected String entry; 10 | private long hlcTime; 11 | 12 | public EventStreamEntry(long hlcTime, String entry) { 13 | this.entry = entry; 14 | this.hlcTime = hlcTime; 15 | } 16 | 17 | @Override 18 | public long getHLCTime() { 19 | return hlcTime; 20 | } 21 | 22 | @Override 23 | public String getEntry() { 24 | return entry; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/AtNodes.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | /** 4 | * Created by Aleksey on 12/20/2016. 5 | */ 6 | public class AtNodes { 7 | 8 | private IdentifierList identifierList; 9 | private boolean allNodes = false; 10 | 11 | public AtNodes(IdentifierList idlist) { 12 | this.identifierList = idlist; 13 | } 14 | 15 | public AtNodes() { 16 | allNodes = true; 17 | } 18 | 19 | public IdentifierList getIdentifierList() { 20 | return identifierList; 21 | } 22 | 23 | public boolean isAllNodes() { 24 | return allNodes; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/server/Runner.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import retroscope.rql.environment.GlobalCut; 4 | import retroscope.rql.errors.RQLRunTimeException; 5 | import retroscope.rql.errors.RQLRunTimeWarning; 6 | 7 | import java.util.ArrayList; 8 | 9 | public interface Runner { 10 | 11 | void execute(); 12 | 13 | String explain(); 14 | 15 | boolean isExplain(); 16 | 17 | boolean hasRunTimeErrors(); 18 | 19 | boolean hasRunTimeWarnings(); 20 | 21 | ArrayList getExceptions(); 22 | 23 | ArrayList getWarnings(); 24 | 25 | ArrayList getEmittedCuts(); 26 | } 27 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/variables/LongRQLVariable.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.variables; 2 | 3 | public class LongRQLVariable extends RQLVariable { 4 | 5 | public LongRQLVariable(long val) { 6 | super(); 7 | this.setValue(val); 8 | } 9 | 10 | public LongRQLVariable(String name, long val) { 11 | super(name, val); 12 | } 13 | 14 | public LongRQLVariable clone() { 15 | LongRQLVariable clone = new LongRQLVariable(value); 16 | clone.setName(this.getName()); 17 | return clone; 18 | } 19 | 20 | @Override 21 | public void negate() { 22 | this.value = - this.value; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/parser/SetItems.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.parser; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.hlc.Timestamp; 5 | 6 | import java.util.*; 7 | 8 | public class SetItems { 9 | 10 | private ArrayList setItems; 11 | 12 | public SetItems() { 13 | setItems = new ArrayList<>(); 14 | } 15 | 16 | public SetItems(RQLSymbol s) { 17 | this(); 18 | setItems.add(s); 19 | } 20 | 21 | public SetItems addItem(RQLSymbol s) { 22 | setItems.add(s); 23 | return this; 24 | } 25 | 26 | public ArrayList getSetItems() { 27 | return setItems; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/condition/Ternary.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.condition; 2 | 3 | import retroscope.rql.syntaxtree.expression.Expression; 4 | 5 | public class Ternary { 6 | 7 | private Expression choice1; 8 | private Expression choice2; 9 | 10 | public Ternary(Expression choice1, Expression choice2) { 11 | this.choice1 = choice1; 12 | this.choice2 = choice2; 13 | } 14 | 15 | public Ternary(Expression choice1) { 16 | this.choice1 = choice1; 17 | } 18 | 19 | public Expression getChoice1() { 20 | return choice1; 21 | } 22 | 23 | public Expression getChoice2() { 24 | return choice2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/variables/DoubleRQLVariable.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.variables; 2 | 3 | public class DoubleRQLVariable extends RQLVariable { 4 | 5 | public DoubleRQLVariable(double val) { 6 | super(); 7 | this.setValue(val); 8 | } 9 | 10 | public DoubleRQLVariable(String name, double val) { 11 | super(name, val); 12 | } 13 | 14 | public DoubleRQLVariable clone() { 15 | DoubleRQLVariable clone = new DoubleRQLVariable(value); 16 | clone.setName(this.getName()); 17 | return clone; 18 | } 19 | 20 | @Override 21 | public void negate() { 22 | this.value = - this.value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/Null.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct; 2 | 3 | public class Null extends RQLSymbol { 4 | 5 | public Null() { 6 | super(); 7 | } 8 | 9 | @Override 10 | public void merge(RQLSymbol mergeSymbol) { 11 | 12 | } 13 | 14 | @Override 15 | public RQLSymbol clone() { 16 | return new Null(); 17 | } 18 | 19 | @Override 20 | public String toRQLString() { 21 | return this.getName() + ":null"; 22 | } 23 | 24 | @Override 25 | public String toEmitRQLString() { 26 | return this.getName() + ":null"; 27 | } 28 | 29 | @Override 30 | public String toValueString() { 31 | return "null"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/stackedexpression/IteratingFunc.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.stackedexpression; 2 | 3 | import retroscope.rql.syntaxtree.IdentifierList; 4 | import retroscope.rql.syntaxtree.expression.Expression; 5 | 6 | public class IteratingFunc { 7 | 8 | private IdentifierList ids; 9 | private Expression ex1, ex2; 10 | 11 | public IteratingFunc(IdentifierList ids, Expression ex1, Expression ex2) { 12 | this.ids = ids; 13 | this.ex1 = ex1; 14 | this.ex2 = ex2; 15 | } 16 | 17 | public IdentifierList getIds() { 18 | return ids; 19 | } 20 | 21 | public Expression getEx1() { 22 | return ex1; 23 | } 24 | 25 | public Expression getEx2() { 26 | return ex2; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/parser/dataTokens.java: -------------------------------------------------------------------------------- 1 | // Output created by jacc on Sat Dec 09 19:35:56 EST 2017 2 | package retroscope.datamodel.parser; 3 | 4 | public interface dataTokens { 5 | int ENDINPUT = 0; 6 | int APPEND = 1; 7 | int FLOAT_LITERAL = 2; 8 | int IDENTIFIER = 3; 9 | int INTEGER_LITERAL = 4; 10 | int NIL = 5; 11 | int REMOVE = 6; 12 | int STRING_LITERAL = 7; 13 | int error = 8; 14 | // '(' (code=40) 15 | // ')' (code=41) 16 | // ',' (code=44) 17 | // '-' (code=45) 18 | // ':' (code=58) 19 | // ';' (code=59) 20 | // '<' (code=60) 21 | // '=' (code=61) 22 | // '>' (code=62) 23 | // '[' (code=91) 24 | // ']' (code=93) 25 | // '{' (code=123) 26 | // '|' (code=124) 27 | // '}' (code=125) 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/EvalExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | 4 | public class EvalExpression 5 | { 6 | public EvalExpression(Expression ex1) 7 | { 8 | /*try { 9 | ex1.evaluate(); 10 | RQLInterpreterValue ex1Val = ex1.getValue(); 11 | 12 | if (ex1Val.getType() == Types.DOUBLE) { 13 | System.out.println(ex1Val.getDoubleVal()); 14 | } else if (ex1Val.getType() == Types.INT) { 15 | System.out.println(ex1Val.getIntVal()); 16 | } 17 | if (ex1Val.getType() == Types.STRING) { 18 | System.out.println(ex1Val.getStringVal()); 19 | } 20 | 21 | } catch (IllegalExpressionException e) {System.err.println("Illegal Expression Exception " +e.getMessage());}*/ 22 | 23 | } 24 | 25 | public void evaluate() { 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Sum.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.rql.environment.EnvironmentStack; 4 | import retroscope.rql.syntaxtree.expression.ExpressionList; 5 | 6 | /** 7 | * Created by Aleksey on 1/21/2017. 8 | * 9 | */ 10 | public class Sum extends AbstractPairwiseAggregateMathFunc { 11 | 12 | public Sum(ExpressionList params, EnvironmentStack stack) { 13 | super(params, stack); 14 | } 15 | 16 | @Override 17 | protected long twoVarAction(long n1, long n2) { 18 | return n1 + n2; 19 | } 20 | 21 | @Override 22 | protected double twoVarAction(long n1, double n2) { 23 | return n1 + n2; 24 | } 25 | 26 | @Override 27 | protected double twoVarAction(double n1, double n2) { 28 | return n1 + n2; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Max.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.rql.environment.EnvironmentStack; 4 | import retroscope.rql.syntaxtree.expression.ExpressionList; 5 | /** 6 | * Created by Aleksey on 1/21/2017. 7 | * 8 | */ 9 | public class Max extends AbstractPairwiseAggregateMathFunc { 10 | 11 | public Max(ExpressionList params, EnvironmentStack stack) { 12 | super(params, stack); 13 | } 14 | 15 | @Override 16 | protected long twoVarAction(long n1, long n2) { 17 | return Math.max(n1, n2); 18 | } 19 | 20 | @Override 21 | protected double twoVarAction(long n1, double n2) { 22 | return Math.max(n1, n2); 23 | } 24 | 25 | @Override 26 | protected double twoVarAction(double n1, double n2) { 27 | return Math.max(n1, n2); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Min.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.rql.environment.EnvironmentStack; 4 | import retroscope.rql.syntaxtree.expression.ExpressionList; 5 | /** 6 | * Created by Aleksey on 1/21/2017. 7 | * 8 | */ 9 | public class Min extends AbstractPairwiseAggregateMathFunc { 10 | 11 | public Min(ExpressionList params, EnvironmentStack stack) { 12 | super(params, stack); 13 | } 14 | 15 | @Override 16 | protected long twoVarAction(long n1, long n2) { 17 | return Math.min(n1, n2); 18 | } 19 | 20 | @Override 21 | protected double twoVarAction(long n1, double n2) { 22 | return Math.min(n1, n2); 23 | } 24 | 25 | @Override 26 | protected double twoVarAction(double n1, double n2) { 27 | return Math.min(n1, n2); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /RetroLogServer/src/test/java/retroscope/RetroscopeTest.java: -------------------------------------------------------------------------------- 1 | package retroscope; 2 | 3 | import org.junit.Before; 4 | import org.apache.ignite.Ignite; 5 | import org.apache.ignite.Ignition; 6 | import java.util.*; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | /** 11 | * Created by Aleksey on 11/7/2016. 12 | * Tests on the main library class 13 | */ 14 | public class RetroscopeTest { 15 | 16 | 17 | private int runs = 10000; 18 | private int smallRuns = 100; 19 | private Random rand; 20 | private Retroscope retroscope; 21 | private Ignite ignite; 22 | 23 | @Before 24 | public void setUp() throws Exception { 25 | rand = new Random(System.nanoTime()); 26 | retroscope = new Retroscope("testApp"); 27 | ignite = Ignition.ignite(); 28 | retroscope.connectIgnite(ignite); 29 | } 30 | 31 | 32 | 33 | } -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Tan.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.syntaxtree.expression.ExpressionList; 7 | /** 8 | * Created by Aleksey on 1/21/2017. 9 | * 10 | */ 11 | public class Tan extends AbstractMathFunc { 12 | 13 | public Tan(ExpressionList params, EnvironmentStack stack) { 14 | super(params, stack); 15 | } 16 | 17 | @Override 18 | protected RQLSymbol longVarOperation(long val) { 19 | return new DoubleRQLVariable(Math.tan(val)); 20 | } 21 | 22 | @Override 23 | protected RQLSymbol doubleVarOperation(double val) { 24 | return new DoubleRQLVariable(Math.tan(val)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/NodeSum.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.rql.environment.EnvironmentStack; 4 | import retroscope.rql.syntaxtree.expression.ExpressionList; 5 | 6 | /** 7 | * Created by Aleksey on 1/21/2017. 8 | * 9 | */ 10 | public class NodeSum extends AbstractPairwiseAggregateMathFunc { 11 | 12 | public NodeSum(ExpressionList params, EnvironmentStack stack) { 13 | super(params, stack); 14 | setExpandSet(true); 15 | } 16 | 17 | @Override 18 | protected long twoVarAction(long n1, long n2) { 19 | return n1 + n2; 20 | } 21 | 22 | @Override 23 | protected double twoVarAction(long n1, double n2) { 24 | return n1 + n2; 25 | } 26 | 27 | @Override 28 | protected double twoVarAction(double n1, double n2) { 29 | return n1 + n2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Sin.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.syntaxtree.expression.ExpressionList; 7 | 8 | /** 9 | * Created by Aleksey on 1/21/2017. 10 | * 11 | */ 12 | public class Sin extends AbstractMathFunc { 13 | 14 | public Sin(ExpressionList params, EnvironmentStack stack) { 15 | super(params, stack); 16 | } 17 | 18 | @Override 19 | protected RQLSymbol longVarOperation(long val) { 20 | return new DoubleRQLVariable(Math.sin(val)); 21 | } 22 | 23 | @Override 24 | protected RQLSymbol doubleVarOperation(double val) { 25 | return new DoubleRQLVariable(Math.sin(val)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Cos.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.syntaxtree.expression.ExpressionList; 7 | 8 | /** 9 | * Created by Aleksey on 1/21/2017. 10 | * 11 | */ 12 | public class Cos extends AbstractMathFunc { 13 | 14 | public Cos(ExpressionList params, EnvironmentStack stack) { 15 | super(params, stack); 16 | } 17 | 18 | @Override 19 | protected RQLSymbol longVarOperation(long val) { 20 | return new DoubleRQLVariable(Math.cos(val)); 21 | } 22 | 23 | @Override 24 | protected RQLSymbol doubleVarOperation(double val) { 25 | return new DoubleRQLVariable(Math.cos(val)); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/literals/IntegerLiteral.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.literals; 2 | 3 | 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class IntegerLiteral extends Expression 10 | { 11 | public IntegerLiteral(long value) 12 | { 13 | this.value = new LongRQLVariable(value); 14 | dirty = false; 15 | } 16 | 17 | public void evaluate() { 18 | 19 | } 20 | 21 | public IntegerLiteral clone() { 22 | return new IntegerLiteral(((LongRQLVariable)this.value).getValue()); 23 | } 24 | 25 | // integerLiteral is never dirty 26 | @Override 27 | public boolean computeDirty() { 28 | return dirty; 29 | } 30 | 31 | @Override 32 | public ArrayList findVars() { 33 | return new ArrayList<>(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/literals/StringLiteral.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.literals; 2 | 3 | import retroscope.datamodel.datastruct.variables.StringRQLVariable; 4 | import retroscope.rql.syntaxtree.expression.Expression; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class StringLiteral extends Expression 9 | { 10 | public StringLiteral(String value) 11 | { 12 | this.value = new StringRQLVariable(value); 13 | dirty = false; 14 | } 15 | 16 | public void evaluate() { 17 | 18 | } 19 | 20 | public StringLiteral clone() { 21 | return new StringLiteral(((StringRQLVariable)this.value).getValue()); 22 | } 23 | 24 | // StringLiteral is never dirty 25 | @Override 26 | public boolean computeDirty() { 27 | return dirty; 28 | } 29 | 30 | @Override 31 | public ArrayList findVars() { 32 | return new ArrayList<>(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Abs.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.ExpressionList; 8 | /** 9 | * Created by Aleksey on 1/21/2017. 10 | * 11 | */ 12 | public class Abs extends AbstractMathFunc { 13 | 14 | public Abs(ExpressionList params, EnvironmentStack stack) { 15 | super(params, stack); 16 | } 17 | 18 | @Override 19 | protected RQLSymbol longVarOperation(long val) { 20 | return new LongRQLVariable(Math.abs(val)); 21 | } 22 | 23 | @Override 24 | protected RQLSymbol doubleVarOperation(double val) { 25 | return new DoubleRQLVariable(Math.abs(val)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/IsSubset.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class IsSubset extends SetOperator { 10 | 11 | public IsSubset(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 17 | return new LongRQLVariable(s2.isSubset(s1) ? 1 : 0); 18 | } 19 | 20 | @Override 21 | public IsSubset clone() { 22 | return new IsSubset(ex1.clone(), ex2.clone()); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Ceil.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.ExpressionList; 8 | 9 | /** 10 | * Created by Aleksey on 1/21/2017. 11 | * 12 | */ 13 | public class Ceil extends AbstractMathFunc { 14 | 15 | public Ceil(ExpressionList params, EnvironmentStack stack) { 16 | super(params, stack); 17 | } 18 | 19 | @Override 20 | protected RQLSymbol longVarOperation(long val) { 21 | return new DoubleRQLVariable(Math.ceil(val)); 22 | } 23 | 24 | @Override 25 | protected RQLSymbol doubleVarOperation(double val) { 26 | return new LongRQLVariable((long) Math.ceil(val)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Floor.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.ExpressionList; 8 | 9 | /** 10 | * Created by Aleksey on 1/21/2017. 11 | * 12 | */ 13 | public class Floor extends AbstractMathFunc { 14 | 15 | public Floor(ExpressionList params, EnvironmentStack stack) { 16 | super(params, stack); 17 | } 18 | 19 | @Override 20 | protected RQLSymbol longVarOperation(long val) { 21 | return new DoubleRQLVariable(Math.floor(val)); 22 | } 23 | 24 | @Override 25 | protected RQLSymbol doubleVarOperation(double val) { 26 | return new LongRQLVariable((long) Math.floor(val)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/SetDifference.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | 8 | public class SetDifference extends SetOperator { 9 | 10 | public SetDifference(Expression ex1, Expression ex2) { 11 | super(ex1, ex2); 12 | } 13 | 14 | @Override 15 | protected RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 16 | RQLSet diff = new RQLSet(); 17 | diff.addAll(s1); 18 | diff.removeAll(s2); 19 | return diff; 20 | } 21 | 22 | @Override 23 | public SetDifference clone() { 24 | return new SetDifference(ex1.clone(), ex2.clone()); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/literals/FloatLiteral.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.literals; 2 | 3 | 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | 7 | import java.util.ArrayList; 8 | 9 | public class FloatLiteral extends Expression 10 | { 11 | public FloatLiteral(double value) 12 | { 13 | this.value = new DoubleRQLVariable(value); 14 | dirty = false; 15 | } 16 | 17 | public void evaluate() { 18 | 19 | } 20 | 21 | public FloatLiteral clone() { 22 | return new FloatLiteral(((DoubleRQLVariable)this.value).getValue()); 23 | } 24 | 25 | // FloatLiteral is never dirty 26 | // integerLiteral is never dirty 27 | @Override 28 | public boolean computeDirty() { 29 | return dirty; 30 | } 31 | 32 | @Override 33 | public ArrayList findVars() { 34 | return new ArrayList<>(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/sets/RemoveRQLSet.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.parser.SetItems; 5 | 6 | public class RemoveRQLSet extends RQLSet { 7 | 8 | public RemoveRQLSet(String name) { 9 | super(name); 10 | } 11 | 12 | public RemoveRQLSet(SetItems items) { 13 | super(items); 14 | } 15 | 16 | @Override 17 | public String toRQLString() { 18 | StringBuilder sb = new StringBuilder(); 19 | sb.append(this.getName()); 20 | sb.append(':'); 21 | sb.append("--"); 22 | sb.append('{'); 23 | for (RQLSymbol s: getSet()) { 24 | sb.append(s.toRQLString()); 25 | sb.append(','); 26 | } 27 | sb.deleteCharAt(sb.length() - 1); 28 | sb.append('}'); 29 | return sb.toString(); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/InOperator.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class InOperator extends SymbolAndSetOperator { 10 | 11 | public InOperator(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected RQLSymbol symbolAndSetOperation(RQLSymbol s1, RQLSet s2) throws IllegalExpressionException { 17 | return new LongRQLVariable(s2.getSet().contains(s1) ? 1 : 0); 18 | } 19 | 20 | @Override 21 | public InOperator clone() { 22 | return new InOperator(ex1.clone(), ex2.clone()); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/IsProperSubset.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class IsProperSubset extends SetOperator { 10 | 11 | public IsProperSubset(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 17 | return new LongRQLVariable(s2.isSubset(s1) && s2.size() < s1.size() ? 1 : 0); 18 | } 19 | 20 | @Override 21 | public IsSubset clone() { 22 | return new IsSubset(ex1.clone(), ex2.clone()); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/Union.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class Union extends SetOperator { 10 | 11 | public Union(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 17 | RQLSet union = new RQLSet(); 18 | union.addAll(s1); 19 | union.addAll(s2); 20 | return union; 21 | } 22 | 23 | @Override 24 | public Union clone() { 25 | return new Union(ex1.clone(), ex2.clone()); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/Intersect.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | 8 | public class Intersect extends SetOperator { 9 | 10 | public Intersect(Expression ex1, Expression ex2) { 11 | super(ex1, ex2); 12 | } 13 | 14 | @Override 15 | protected RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 16 | RQLSet intersect = new RQLSet(); 17 | intersect.getSet().addAll(s1.getSet()); 18 | intersect.getSet().retainAll(s2.getSet()); 19 | return intersect; 20 | } 21 | 22 | @Override 23 | public Intersect clone() { 24 | return new Intersect(ex1.clone(), ex2.clone()); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/NotInOperator.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class NotInOperator extends SymbolAndSetOperator { 10 | 11 | public NotInOperator(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected RQLSymbol symbolAndSetOperation(RQLSymbol s1, RQLSet s2) throws IllegalExpressionException { 17 | return new LongRQLVariable(s2.getSet().contains(s1) ? 0 : 1); 18 | } 19 | 20 | @Override 21 | public NotInOperator clone() { 22 | return new NotInOperator(ex1.clone(), ex2.clone()); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/ParamList.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by Aleksey on 12/20/2016. 9 | * 10 | */ 11 | public class ParamList { 12 | 13 | //private Param[] params; 14 | 15 | private ArrayList params; 16 | 17 | public ParamList(Param p) { 18 | params = new ArrayList<>(); 19 | params.add(p); 20 | } 21 | 22 | public ParamList(Param p, ParamList pList) { 23 | params = pList.params; 24 | params.add(p); 25 | } 26 | 27 | public ArrayList getParams() { 28 | return params; 29 | } 30 | 31 | 32 | 33 | /*public String toString() 34 | { 35 | StringBuilder sb = new StringBuilder(); 36 | for (Param p : params) { 37 | sb.append(p.toString()); 38 | sb.append(", "); 39 | } 40 | return sb.toString(); 41 | }*/ 42 | } 43 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/EQExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | import retroscope.datamodel.datastruct.sets.RQLSet; 4 | import retroscope.rql.syntaxtree.expression.Expression; 5 | 6 | public class EQExpression extends CompareExpression 7 | { 8 | 9 | public EQExpression(Expression ex1, Expression ex2) 10 | { 11 | super(ex1, ex2); 12 | } 13 | 14 | @Override 15 | protected boolean compareNums(Number n1, Number n2) { 16 | if (n1 instanceof Long && n2 instanceof Long) { 17 | return n1.longValue() == n2.longValue(); 18 | } 19 | return n1.doubleValue() == n2.doubleValue(); 20 | } 21 | 22 | @Override 23 | protected boolean compareStrings(String s1, String s2) { 24 | return s1.equals(s2); 25 | } 26 | 27 | public EQExpression clone() { 28 | return new EQExpression(ex1.clone(), ex2.clone()); 29 | } 30 | 31 | @Override 32 | protected boolean compareSets(RQLSet s1, RQLSet s2) { 33 | return s1.equals(s2); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/IdentifierList.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | /** 4 | * Created by Aleksey on 12/20/2016. 5 | */ 6 | public class IdentifierList { 7 | 8 | private String[] identifiers; 9 | 10 | public IdentifierList(String id) { 11 | identifiers = new String[1]; 12 | identifiers[0] = id; 13 | } 14 | 15 | public IdentifierList(String id, IdentifierList idList) { 16 | identifiers = new String[idList.getIdentifiers().length + 1]; 17 | System.arraycopy(idList.getIdentifiers(), 0, identifiers, 1, idList.getIdentifiers().length); 18 | identifiers[0] = id; 19 | } 20 | 21 | public String[] getIdentifiers() { 22 | return identifiers; 23 | } 24 | 25 | public String toString() 26 | { 27 | StringBuilder sb = new StringBuilder(); 28 | for (String p : identifiers) { 29 | sb.append(p.toString()); 30 | sb.append(", "); 31 | } 32 | return sb.toString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/Query.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | /** 4 | * Created by Aleksey on 12/20/2016. 5 | * This is the main query class from the retroscope.rql syntax tree 6 | * This class implements pulling data from the remotes, 7 | * 8 | */ 9 | public class Query { 10 | 11 | private ParamList params; 12 | private IdentifierList logs; 13 | private QueryEnd qe; 14 | 15 | private boolean isExplain = false; 16 | 17 | 18 | public Query(ParamList pl, IdentifierList logs, QueryEnd qe) { 19 | params = pl; 20 | this.logs = logs; 21 | this.qe = qe; 22 | } 23 | 24 | public void explain() { 25 | isExplain = true; 26 | } 27 | 28 | public ParamList getParams() { 29 | return params; 30 | } 31 | 32 | public IdentifierList getLogs() { 33 | return logs; 34 | } 35 | 36 | public QueryEnd getQe() { 37 | return qe; 38 | } 39 | 40 | public boolean isExplain() { 41 | return isExplain; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/RetroscopeException.java: -------------------------------------------------------------------------------- 1 | package retroscope; 2 | 3 | /** 4 | * Created by aleksey on 10/17/16. 5 | * 6 | */ 7 | public abstract class RetroscopeException extends Exception { 8 | 9 | public final static int UNIDENTIFIED_ERROR= 1; 10 | public final static int LOG_OUT_OF_BOUNDS= 2; 11 | public final static int LOG_DOES_NOT_EXIST = 3; 12 | public final static int RQL_ITEM_ERROR = 4; 13 | public final static int SNAPSHOT_DOES_NOT_EXIST = 5; 14 | public final static int CLIENT_NETWORK_ERROR = 6; 15 | public final static int INCORRECT_LOG_TYPE = 7; 16 | 17 | private int type = 1; 18 | 19 | public RetroscopeException(String message) { 20 | this(1, message); 21 | } 22 | 23 | public RetroscopeException(int type, String message) { 24 | super(message); 25 | type = this.type; 26 | } 27 | 28 | public RetroscopeException(int type) { 29 | super(""); 30 | type = this.type; 31 | } 32 | 33 | public int getType() { 34 | return type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/sets/AppendRQLSet.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.RQLType; 5 | import retroscope.datamodel.parser.SetItems; 6 | 7 | import java.util.HashSet; 8 | import java.util.Iterator; 9 | 10 | public class AppendRQLSet extends RQLSet { 11 | 12 | public AppendRQLSet(String name) { 13 | super(name); 14 | } 15 | 16 | public AppendRQLSet(SetItems items) { 17 | super(items); 18 | } 19 | 20 | @Override 21 | public String toRQLString() { 22 | StringBuilder sb = new StringBuilder(); 23 | sb.append(this.getName()); 24 | sb.append(':'); 25 | sb.append("..."); 26 | sb.append('{'); 27 | for (RQLSymbol s: getSet()) { 28 | sb.append(s.toRQLString()); 29 | sb.append(','); 30 | } 31 | sb.deleteCharAt(sb.length() - 1); 32 | sb.append('}'); 33 | return sb.toString(); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/NEQExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | 7 | public class NEQExpression extends CompareExpression 8 | { 9 | 10 | public NEQExpression(Expression ex1, Expression ex2) 11 | { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected boolean compareNums(Number n1, Number n2) { 17 | if (n1 instanceof Long && n2 instanceof Long) { 18 | return ((Long) n1).compareTo((Long)n2) != 0; 19 | } 20 | return n1.doubleValue() != n2.doubleValue(); 21 | } 22 | 23 | @Override 24 | protected boolean compareStrings(String s1, String s2) { 25 | return !s1.equals(s2); 26 | } 27 | 28 | @Override 29 | protected boolean compareSets(RQLSet s1, RQLSet s2) { 30 | return !s1.equals(s2); 31 | } 32 | 33 | public NEQExpression clone() { 34 | return new NEQExpression(ex1.clone(), ex2.clone()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/ignite/CommitStreamEntry.java: -------------------------------------------------------------------------------- 1 | package retroscope.net.ignite; 2 | 3 | import retroscope.hlc.Timestamp; 4 | 5 | /** 6 | * Created by aleksey on 10/30/76. 7 | * 8 | */ 9 | public class CommitStreamEntry implements StreamEntry{ 10 | 11 | protected int nodeID; 12 | protected Timestamp timestamp; 13 | protected String commitSnap; 14 | 15 | 16 | public CommitStreamEntry(Timestamp timestamp, String commitSnap, int nodeID) { 17 | this.timestamp = timestamp; 18 | this.commitSnap = commitSnap; 19 | this.nodeID = nodeID; 20 | } 21 | 22 | public void setNodeID(int nodeID) { 23 | this.nodeID = nodeID; 24 | } 25 | 26 | public int getNodeID() { 27 | return nodeID; 28 | } 29 | 30 | public CommitStreamEntry clone() { 31 | return new CommitStreamEntry(this.timestamp.clone(), commitSnap, this.nodeID); 32 | } 33 | 34 | @Override 35 | public long getHLCTime() { 36 | return timestamp.toLong(); 37 | } 38 | 39 | @Override 40 | public String getEntry() { 41 | return commitSnap; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RetroLogServer/src/test/java/retroscope/datamodel/parser/RQLDataTest.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.parser; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import retroscope.datamodel.datastruct.RQLSymbol; 6 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 7 | 8 | import java.util.ArrayList; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | public class RQLDataTest { 13 | 14 | private static final int LEN = 50; 15 | 16 | private RQLData rqlData; 17 | 18 | @Before 19 | public void setUp() { 20 | rqlData = new RQLData(); 21 | for (int i = 0; i < LEN; i++) { 22 | RQLSymbol sym = new LongRQLVariable("key" + (i%5), i); 23 | rqlData.appendDataItem(sym); 24 | } 25 | } 26 | 27 | @Test 28 | public void restrict() throws Exception { 29 | ArrayList params = new ArrayList<>(); 30 | params.add("key0"); 31 | params.add("key3"); 32 | rqlData.restrict(params); 33 | System.out.println(rqlData.getDataItems().size()); 34 | assertTrue(rqlData.getDataItems().size() == 20); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/TimeSearch.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | import retroscope.rql.syntaxtree.expression.Expression; 4 | 5 | /** 6 | * Created by Aleksey on 1/23/2017. 7 | * 8 | */ 9 | public class TimeSearch { 10 | 11 | public static final int BETWEEN = 1; 12 | public static final int BEFORE = 2; 13 | public static final int AFTER = 3; 14 | 15 | private Expression ex1, ex2, link; 16 | private int type; 17 | 18 | public TimeSearch(int timeSearchType, Expression ex1) { 19 | type = timeSearchType; 20 | this.ex1 = ex1; 21 | } 22 | 23 | public TimeSearch(int timeSearchType, Expression ex1, Expression ex2, Expression link) { 24 | type = timeSearchType; 25 | this.ex1 = ex1; 26 | this.ex2 = ex2; 27 | this.link = link; 28 | } 29 | 30 | public Expression getEx1() { 31 | return ex1; 32 | } 33 | 34 | public Expression getEx2() { 35 | return ex2; 36 | } 37 | 38 | public Expression getLink() { 39 | return link; 40 | } 41 | 42 | public int getType() { 43 | return type; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/GEQExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | import retroscope.datamodel.datastruct.sets.RQLSet; 4 | import retroscope.rql.syntaxtree.expression.Expression; 5 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 6 | 7 | public class GEQExpression extends CompareExpression 8 | { 9 | public GEQExpression(Expression ex1, Expression ex2) 10 | { 11 | super(ex1, ex2); 12 | } 13 | 14 | @Override 15 | protected boolean compareNums(Number n1, Number n2) { 16 | if (n1 instanceof Long && n2 instanceof Long) { 17 | return n1.longValue() >= n2.longValue(); 18 | } 19 | return n1.doubleValue() >= n2.doubleValue(); 20 | } 21 | 22 | @Override 23 | protected boolean compareStrings(String s1, String s2) { 24 | return s1.compareTo(s2) >= 0; 25 | } 26 | 27 | @Override 28 | protected boolean compareSets(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 29 | throw new IllegalExpressionException("Greater or equal than is undefined for sets"); 30 | } 31 | 32 | public GEQExpression clone() { 33 | return new GEQExpression(ex1.clone(), ex2.clone()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/RQLBuiltInFunction.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.rql.environment.EnvironmentStack; 5 | import retroscope.rql.parser.Valuable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.ExpressionList; 8 | 9 | /** 10 | * Created by Aleksey on 1/21/2017. 11 | * 12 | */ 13 | public abstract class RQLBuiltInFunction implements Valuable { 14 | 15 | protected ExpressionList params; 16 | protected EnvironmentStack environmentStack; 17 | protected RQLSymbol value; 18 | 19 | public RQLBuiltInFunction(ExpressionList params, EnvironmentStack environmentStack) { 20 | this.params = params; 21 | this.environmentStack = environmentStack; 22 | } 23 | 24 | public RQLSymbol getValue() { 25 | return value; 26 | } 27 | 28 | public void setEnvironmentStack(EnvironmentStack environmentStack) { 29 | this.environmentStack = environmentStack; 30 | for (Expression ex: params.getList()) { 31 | ex.setEnvironmentStack(environmentStack); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/LEQExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | 8 | public class LEQExpression extends CompareExpression 9 | { 10 | 11 | public LEQExpression(Expression ex1, Expression ex2) 12 | { 13 | super(ex1, ex2); 14 | } 15 | 16 | @Override 17 | protected boolean compareNums(Number n1, Number n2) { 18 | if (n1 instanceof Long && n2 instanceof Long) { 19 | return n1.longValue() <= n2.longValue(); 20 | } 21 | return n1.doubleValue() <= n1.doubleValue(); 22 | } 23 | 24 | @Override 25 | protected boolean compareStrings(String s1, String s2) { 26 | return s1.compareTo(s2) <= 0; 27 | } 28 | 29 | @Override 30 | protected boolean compareSets(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 31 | throw new IllegalExpressionException("Less or equal than is undefined for sets"); 32 | } 33 | 34 | public LEQExpression clone() { 35 | return new LEQExpression(ex1.clone(), ex2.clone()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/util/netHLCSerializer.java: -------------------------------------------------------------------------------- 1 | package retroscope.util; 2 | 3 | import retroscope.hlc.Timestamp; 4 | import retroscope.util.ByteHelper; 5 | 6 | import java.util.Arrays; 7 | 8 | 9 | /** 10 | * Created by aleksey on 10/15/16. 11 | * 12 | */ 13 | public class netHLCSerializer { 14 | 15 | public static byte[] networkAddHLC(Timestamp hlcTime, byte[] message) { 16 | long hlcLong = hlcTime.toLong(); 17 | 18 | byte[] hlcMessage = new byte[message.length + 8]; //retroscope.hlc takes 8 bytes 19 | ByteHelper.longToBytes(hlcMessage, hlcLong, 0); 20 | System.arraycopy(message, 0, hlcMessage, 0, message.length); 21 | return hlcMessage; 22 | } 23 | 24 | public static Timestamp networkReadHLC(byte[] message) { 25 | long hlcLong = ByteHelper.bytesToLong(message, 0); 26 | //byte[] strippedMessage = Arrays.copyOfRange(message, 0, 8); 27 | //message = strippedMessage; 28 | return new Timestamp(hlcLong); 29 | } 30 | 31 | public static byte[] networkUnwrapHLC(byte[] message) { 32 | byte[] strippedMessage = Arrays.copyOfRange(message, 8, message.length); 33 | return strippedMessage; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/Param.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | /** 4 | * Created by Aleksey on 12/20/2016. 5 | */ 6 | public class Param { 7 | 8 | private String identifier; 9 | private String superIdentifier = ""; 10 | 11 | 12 | public Param(String identifier) { 13 | this.identifier = identifier; 14 | } 15 | 16 | public Param(String superIdentifier, String identifier) { 17 | this.superIdentifier = superIdentifier; 18 | this.identifier = identifier; 19 | } 20 | 21 | public String toString() 22 | { 23 | if (superIdentifier.equals("")) { 24 | return identifier; 25 | } else { 26 | return superIdentifier + "." + identifier; 27 | } 28 | } 29 | 30 | public void setIdentifier(String identifier) { 31 | this.identifier = identifier; 32 | } 33 | 34 | public void setSuperIdentifier(String superIdentifier) { 35 | this.superIdentifier = superIdentifier; 36 | } 37 | 38 | public String getIdentifier() { 39 | return identifier; 40 | } 41 | 42 | public String getSuperIdentifier() { 43 | return superIdentifier; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/Mod.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | 9 | public class Mod extends ArithmeticExpression 10 | { 11 | 12 | public Mod(Expression ex1, Expression ex2) 13 | { 14 | super(ex1, ex2); 15 | } 16 | 17 | @Override 18 | protected RQLVariable arithmeticOperation(long n1, long n2) { 19 | return new LongRQLVariable(n1 % n2); 20 | } 21 | 22 | @Override 23 | protected RQLVariable arithmeticOperation(long n1, double n2) { 24 | return new DoubleRQLVariable(n1 % n2); 25 | } 26 | 27 | @Override 28 | protected RQLVariable arithmeticOperation(double n1, long n2) { 29 | return new DoubleRQLVariable(n1 % n2); 30 | } 31 | 32 | @Override 33 | protected RQLVariable arithmeticOperation(double n1, double n2) { 34 | return new DoubleRQLVariable(n1 % n2); 35 | } 36 | 37 | 38 | public Mod clone() { 39 | return new Mod(ex1.clone(), ex2.clone()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/Plus.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | 9 | public class Plus extends ArithmeticExpression 10 | { 11 | 12 | public Plus(Expression ex1, Expression ex2) 13 | { 14 | super(ex1, ex2); 15 | } 16 | 17 | @Override 18 | protected RQLVariable arithmeticOperation(long n1, long n2) { 19 | return new LongRQLVariable(n1 + n2); 20 | } 21 | 22 | @Override 23 | protected RQLVariable arithmeticOperation(long n1, double n2) { 24 | return new DoubleRQLVariable(n1 + n2); 25 | } 26 | 27 | @Override 28 | protected RQLVariable arithmeticOperation(double n1, long n2) { 29 | return new DoubleRQLVariable(n1 + n2); 30 | } 31 | 32 | @Override 33 | protected RQLVariable arithmeticOperation(double n1, double n2) { 34 | return new DoubleRQLVariable(n1 + n2); 35 | } 36 | 37 | 38 | public Plus clone() { 39 | return new Plus(ex1.clone(), ex2.clone()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/LessThanExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | 8 | public class LessThanExpression extends CompareExpression 9 | { 10 | 11 | public LessThanExpression(Expression ex1, Expression ex2) 12 | { 13 | super(ex1, ex2); 14 | } 15 | 16 | @Override 17 | protected boolean compareNums(Number n1, Number n2) { 18 | if (n1 instanceof Long && n2 instanceof Long) { 19 | return n1.longValue() < n2.longValue(); 20 | } 21 | return n1.doubleValue() < n2.doubleValue(); 22 | } 23 | 24 | @Override 25 | protected boolean compareStrings(String s1, String s2) { 26 | return s1.compareTo(s2) < 0; 27 | } 28 | 29 | @Override 30 | protected boolean compareSets(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 31 | throw new IllegalExpressionException("Less than is undefined for sets"); 32 | } 33 | 34 | public LessThanExpression clone() { 35 | return new LessThanExpression(ex1.clone(), ex2.clone()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/stackedexpression/ForEach.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.stackedexpression; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.IdentifierList; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class ForEach extends SetIteratingExpression { 10 | 11 | public ForEach(IdentifierList ids, Expression ex1, Expression ex2) { 12 | super(ids, ex1, ex2); 13 | } 14 | 15 | public ForEach(IteratingFunc aggregate) { 16 | this(aggregate.getIds(), aggregate.getEx1(), aggregate.getEx2()); 17 | } 18 | 19 | @Override 20 | public void evaluate() throws IllegalExpressionException { 21 | super.evaluate(); 22 | this.value = new LongRQLVariable(1); 23 | } 24 | 25 | @Override 26 | protected boolean checkExpressionVal(RQLSymbol exVal) { 27 | return false; 28 | } 29 | 30 | @Override 31 | public ForEach clone() { 32 | return new ForEach(getIds(), getEx1().clone(), getEx2().clone()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/Multiply.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | 4 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | 9 | public class Multiply extends ArithmeticExpression 10 | { 11 | 12 | public Multiply(Expression ex1, Expression ex2) 13 | { 14 | super(ex1, ex2); 15 | 16 | } 17 | 18 | @Override 19 | protected RQLVariable arithmeticOperation(long n1, long n2) { 20 | return new LongRQLVariable(n1 * n2); 21 | } 22 | 23 | @Override 24 | protected RQLVariable arithmeticOperation(long n1, double n2) { 25 | return new DoubleRQLVariable(n1 * n2); 26 | } 27 | 28 | @Override 29 | protected RQLVariable arithmeticOperation(double n1, long n2) { 30 | return new DoubleRQLVariable(n1 * n2); 31 | } 32 | 33 | @Override 34 | protected RQLVariable arithmeticOperation(double n1, double n2) { 35 | return new DoubleRQLVariable(n1 * n2); 36 | } 37 | 38 | 39 | public Multiply clone() { 40 | return new Multiply(ex1.clone(), ex2.clone()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Node.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.sets.RQLSet; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.syntaxtree.expression.ExpressionList; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | import java.util.Set; 10 | 11 | /** 12 | * Created by Aleksey on 1/21/2017. 13 | * 14 | */ 15 | public class Node extends RQLBuiltInFunction { 16 | 17 | public Node(ExpressionList params, EnvironmentStack stack) { 18 | super(params, stack); 19 | } 20 | 21 | public void evaluate() throws IllegalExpressionException { 22 | value = null; 23 | if (params.getList().size() == 1) { 24 | Set nodeIDs = params.getList().get(0).getValue().getNodeIDs(); 25 | RQLSet returnSet = new RQLSet(); 26 | for (long id: nodeIDs) { 27 | returnSet.add(new LongRQLVariable(id)); 28 | } 29 | this.value = returnSet; 30 | } else { 31 | throw new IllegalExpressionException("Node function is undefined for many arguments"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/ExpressionList.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * Created by ALEKS on 1/18/2017. 8 | * this class represents the list of RQL expressions 9 | */ 10 | public class ExpressionList implements Cloneable { 11 | 12 | private ArrayList list; 13 | 14 | public ExpressionList() { 15 | list = new ArrayList(); 16 | } 17 | 18 | public ExpressionList(Expression ex) { 19 | list = new ArrayList(); 20 | list.add(ex); 21 | } 22 | 23 | public ExpressionList(Expression ex, ExpressionList lst) { 24 | list = new ArrayList(); 25 | list.add(ex); 26 | list.addAll(lst.getList()); 27 | } 28 | 29 | public ExpressionList(ArrayList list) { 30 | this.list = list; 31 | } 32 | 33 | public ArrayList getList() { 34 | return list; 35 | } 36 | 37 | public ExpressionList clone() { 38 | ArrayList clonedEx = new ArrayList<>(); 39 | for (Expression ex: list) { 40 | clonedEx.add(ex.clone()); 41 | } 42 | return new ExpressionList(clonedEx); 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/Divide.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | 8 | public class Divide extends ArithmeticExpression 9 | { 10 | 11 | public Divide(Expression ex1, Expression ex2) 12 | { 13 | super(ex1, ex2); 14 | } 15 | 16 | @Override 17 | protected RQLVariable arithmeticOperation(long n1, long n2) { 18 | return new LongRQLVariable(n1 / n2); 19 | } 20 | 21 | @Override 22 | protected RQLVariable arithmeticOperation(long n1, double n2) { 23 | return new DoubleRQLVariable(n1 / n2); 24 | } 25 | 26 | @Override 27 | protected RQLVariable arithmeticOperation(double n1, long n2) { 28 | return new DoubleRQLVariable(n1 / n2); 29 | } 30 | 31 | @Override 32 | protected RQLVariable arithmeticOperation(double n1, double n2) { 33 | return new DoubleRQLVariable(n1 / n2); 34 | } 35 | 36 | public Divide clone() { 37 | return new Divide(ex1.clone(), ex2.clone()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/GreaterThanExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | 8 | public class GreaterThanExpression extends CompareExpression 9 | { 10 | public GreaterThanExpression(Expression ex1, Expression ex2) 11 | { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | protected boolean compareNums(Number n1, Number n2) { 17 | if (n1 instanceof Long && n2 instanceof Long) { 18 | return n1.longValue() > n2.longValue(); 19 | } 20 | return n1.doubleValue() > n2.doubleValue(); 21 | } 22 | 23 | @Override 24 | protected boolean compareStrings(String s1, String s2) { 25 | return s1.compareTo(s2) > 0; 26 | } 27 | 28 | @Override 29 | protected boolean compareSets(RQLSet s1, RQLSet s2) throws IllegalExpressionException { 30 | throw new IllegalExpressionException("Greater than is undefined for sets"); 31 | } 32 | 33 | public GreaterThanExpression clone() { 34 | return new GreaterThanExpression(ex1.clone(), ex2.clone()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /IgniteServer/src/main/java/retroscope/net/igniteserver/IgniteServer.java: -------------------------------------------------------------------------------- 1 | package retroscope.net.igniteserver; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.Ignition; 5 | import org.apache.ignite.configuration.IgniteConfiguration; 6 | import org.apache.log4j.Logger; 7 | import org.apache.log4j.PropertyConfigurator; 8 | 9 | public class IgniteServer { 10 | 11 | private Ignite ignite; 12 | private Logger logger = Logger.getLogger(IgniteServer.class); 13 | private String igniteConfigPath; 14 | 15 | public IgniteServer(String configPath) { 16 | this.igniteConfigPath = configPath; 17 | } 18 | 19 | private void ignite() { 20 | System.out.println("Starting Ignite Server with igniteConfigPath = " + igniteConfigPath); 21 | if (!igniteConfigPath.isEmpty()) { 22 | 23 | this.ignite = Ignition.start(igniteConfigPath); 24 | } else { 25 | this.ignite = Ignition.start(); 26 | } 27 | } 28 | 29 | public static void main(String[] args) { 30 | PropertyConfigurator.configure("log4j.config"); 31 | IgniteServer is; 32 | if (args.length == 0) { 33 | is = new IgniteServer(""); 34 | } else { 35 | is = new IgniteServer(args[0]); 36 | } 37 | is.ignite(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/SymbolAndSetOperator.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 8 | 9 | public abstract class SymbolAndSetOperator extends TwoOperandExpression { 10 | 11 | public SymbolAndSetOperator(Expression ex1, Expression ex2) { 12 | super(ex1, ex2); 13 | } 14 | 15 | @Override 16 | public void evaluate() throws IllegalExpressionException { 17 | evaluateOperands(); 18 | RQLSymbol ex1Val = ex1.getValue(); 19 | RQLSymbol ex2Val = ex2.getValue(); 20 | 21 | if (ex2Val instanceof RQLSet) { 22 | this.value = symbolAndSetOperation(ex1Val, (RQLSet)ex2Val); 23 | } else { 24 | throw new IllegalExpressionException("Cannot use set operators with " + ex1Val.getClass().getName() 25 | + " and " + ex2Val.getClass().getName()); 26 | } 27 | } 28 | 29 | protected abstract RQLSymbol symbolAndSetOperation(RQLSymbol s1, RQLSet s2) throws IllegalExpressionException; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/TwoOperandExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | import retroscope.rql.environment.EnvironmentStack; 4 | import retroscope.rql.syntaxtree.expression.literals.Variable; 5 | 6 | import java.util.ArrayList; 7 | 8 | public abstract class TwoOperandExpression extends Expression 9 | { 10 | protected Expression ex1, ex2; 11 | 12 | public TwoOperandExpression(Expression ex1, Expression ex2) 13 | { 14 | this.ex1 = ex1; 15 | this.ex2 = ex2; 16 | } 17 | 18 | public Expression getEx1() { 19 | return ex1; 20 | } 21 | 22 | public Expression getEx2() { 23 | return ex2; 24 | } 25 | 26 | public void setEnvironmentStack(EnvironmentStack stack) { 27 | this.stack = stack; 28 | ex1.setEnvironmentStack(stack); 29 | ex2.setEnvironmentStack(stack); 30 | } 31 | 32 | protected void evaluateOperands() throws IllegalExpressionException { 33 | if (dirty) { 34 | ex1.evaluate(); 35 | ex2.evaluate(); 36 | } 37 | } 38 | 39 | @Override 40 | public boolean computeDirty() 41 | { 42 | dirty = ex1.computeDirty() || ex2.computeDirty(); 43 | return dirty; 44 | } 45 | 46 | @Override 47 | public ArrayList findVars() { 48 | ArrayList v = new ArrayList<>(); 49 | v.addAll(ex1.findVars()); 50 | v.addAll(ex2.findVars()); 51 | return v; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/Minus.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.literals.IntegerLiteral; 8 | 9 | public class Minus extends ArithmeticExpression 10 | { 11 | public Minus(Expression ex1, Expression ex2) 12 | { 13 | super(ex1, ex2); 14 | } 15 | 16 | public Minus(Expression ex2) 17 | { 18 | super(new IntegerLiteral( 0), ex2); 19 | } 20 | 21 | @Override 22 | protected RQLVariable arithmeticOperation(long n1, long n2) { 23 | return new LongRQLVariable(n1 - n2); 24 | } 25 | 26 | @Override 27 | protected RQLVariable arithmeticOperation(long n1, double n2) { 28 | return new DoubleRQLVariable(n1 - n2); 29 | } 30 | 31 | @Override 32 | protected RQLVariable arithmeticOperation(double n1, long n2) { 33 | return new DoubleRQLVariable(n1 - n2); 34 | } 35 | 36 | @Override 37 | protected RQLVariable arithmeticOperation(double n1, double n2) { 38 | return new DoubleRQLVariable(n1 - n2); 39 | } 40 | 41 | 42 | public Minus clone() { 43 | return new Minus(ex1.clone(), ex2.clone()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/environment/SymbolTable.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.environment; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | 5 | import java.util.HashMap; 6 | import java.util.List; 7 | 8 | public class SymbolTable extends HashMap { 9 | 10 | 11 | public String toString() { 12 | StringBuilder sb = new StringBuilder(); 13 | 14 | for(String var : this.keySet()) { 15 | sb.append(this.get(var).toEmitRQLString()); 16 | } 17 | 18 | return sb.toString(); 19 | } 20 | 21 | public String toString(List params) { 22 | StringBuilder sb = new StringBuilder(); 23 | for(String var : this.keySet()) { 24 | if (params.contains(var)) { 25 | sb.append(this.get(var).toEmitRQLString()); 26 | sb.append(','); 27 | } 28 | } 29 | if (sb.length() > 0) { 30 | sb.deleteCharAt(sb.length() - 1); 31 | } 32 | return sb.toString(); 33 | } 34 | 35 | public GlobalCut toGlobalCut(List params, long cutTime) { 36 | StringBuilder sb = new StringBuilder(); 37 | for(String var : this.keySet()) { 38 | if (params.contains(var)) { 39 | sb.append(this.get(var).toEmitRQLString()); 40 | } 41 | } 42 | return new GlobalCut(cutTime, sb.toString()); 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/QueryEnd.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree; 2 | 3 | import retroscope.rql.syntaxtree.expression.Expression; 4 | 5 | /** 6 | * Created by Aleksey on 12/20/2016. 7 | * this class holds some query parameters and filters 8 | */ 9 | public class QueryEnd { 10 | 11 | private Expression conditions; 12 | private AtNodes nodeIds; 13 | private Expression timeEx1, timeEx2; 14 | private Expression computeScript; 15 | 16 | public QueryEnd(When w, AtNodes nodes, OnTime time) { 17 | this(null, w, nodes, time); 18 | } 19 | 20 | public QueryEnd(Expression computeScript, When w, AtNodes nodes, OnTime time) { 21 | if (w != null) { 22 | conditions = w.getConditions(); 23 | } 24 | nodeIds = nodes; 25 | this.computeScript = computeScript; 26 | 27 | if (time != null) { 28 | timeEx1 = time.getTimeEx1(); 29 | timeEx2 = time.getTimeEx2(); 30 | } 31 | } 32 | 33 | public Expression getConditions() { 34 | return conditions; 35 | } 36 | 37 | public AtNodes getNodeIds() { 38 | return nodeIds; 39 | } 40 | 41 | public Expression getTimeEx1() { 42 | return timeEx1; 43 | } 44 | 45 | public Expression getTimeEx2() { 46 | return timeEx2; 47 | } 48 | 49 | public Expression getComputeStatements() { 50 | return computeScript; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/stackedexpression/Exists.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.stackedexpression; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.environment.Environment; 6 | import retroscope.rql.syntaxtree.IdentifierList; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | 9 | public class Exists extends SetIteratingExpression { 10 | 11 | public Exists(IdentifierList ids, Expression ex1, Expression ex2) { 12 | super(ids, ex1, ex2); 13 | } 14 | 15 | public Exists(IteratingFunc aggregate) { 16 | this(aggregate.getIds(), aggregate.getEx1(), aggregate.getEx2()); 17 | } 18 | 19 | /** 20 | * 21 | * @param exVal the result of an expression. Needs to be a predicate 22 | * @return whether the check loop needs to be short-circuted 23 | */ 24 | 25 | @Override 26 | protected boolean checkExpressionVal(RQLSymbol exVal) { 27 | if (exVal instanceof LongRQLVariable) { 28 | if (((LongRQLVariable) exVal).getValue() != 0) { 29 | this.value = new LongRQLVariable(1); 30 | return true; 31 | } 32 | } 33 | return false; 34 | } 35 | 36 | @Override 37 | public Exists clone() { 38 | return new Exists(getIds(), getEx1().clone(), getEx2().clone()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/assign/OutExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.assign; 2 | 3 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 4 | import retroscope.rql.environment.EnvironmentStack; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | import retroscope.rql.syntaxtree.expression.literals.Variable; 8 | 9 | import java.util.ArrayList; 10 | 11 | public class OutExpression extends Expression { 12 | 13 | private Expression ex1; 14 | private boolean global = false; 15 | 16 | public OutExpression(Expression expression) { 17 | this.ex1 = expression; 18 | dirty = true; 19 | } 20 | 21 | @Override 22 | public void evaluate() throws IllegalExpressionException { 23 | ex1.evaluate(); 24 | getEnvironment().setSymbol("$out", ex1.getValue()); 25 | 26 | this.value = new LongRQLVariable(1); 27 | } 28 | 29 | public void setEnvironmentStack(EnvironmentStack stack) { 30 | this.stack = stack; 31 | ex1.setEnvironmentStack(stack); 32 | } 33 | 34 | @Override 35 | public Expression clone() { 36 | return new OutExpression(ex1.clone()); 37 | } 38 | 39 | @Override 40 | public boolean computeDirty() { 41 | return dirty; 42 | } 43 | 44 | @Override 45 | public ArrayList findVars() { 46 | return new ArrayList<>(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/errors/RQLRunTimeWarning.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.errors; 2 | 3 | /** 4 | * Created by ALEKS on 1/12/2017. 5 | * Warnings that arise during the runtime 6 | */ 7 | public class RQLRunTimeWarning { 8 | 9 | private String message; 10 | private WarningType type; 11 | private String warnId; 12 | public enum WarningType { 13 | VARIABLE_UNDEFINED, 14 | INCOMPATIBLE_TYPES, 15 | LOG_OUT_OF_TIME_BOUNDS, 16 | RETROSCOPE_EXCEPTION, 17 | AMBIGUOUS_TIME_EXPRESSION 18 | } 19 | 20 | public RQLRunTimeWarning(WarningType type, String warnId, String message){ 21 | this.message = message; 22 | this.type = type; 23 | this.warnId = warnId; 24 | } 25 | 26 | public WarningType getType() { 27 | return type; 28 | } 29 | 30 | public String getMessage() { 31 | return message; 32 | } 33 | 34 | public String getWarningId() { 35 | return warnId; 36 | } 37 | 38 | public boolean equals(Object o) { 39 | if (!(o instanceof RQLRunTimeWarning)) { 40 | return false; 41 | } 42 | if (o == this) { 43 | return true; 44 | } 45 | 46 | //actual comparison 47 | RQLRunTimeWarning wo = (RQLRunTimeWarning) o; 48 | if (type != wo.getType()) { 49 | return false; 50 | } 51 | if (!warnId.equals(wo.getWarningId())) { 52 | return false; 53 | } 54 | return true; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Subset.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.functions.RQLBuiltInFunction; 8 | import retroscope.rql.syntaxtree.expression.Expression; 9 | import retroscope.rql.syntaxtree.expression.ExpressionList; 10 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 11 | 12 | public class Subset extends RQLBuiltInFunction { 13 | 14 | public Subset(ExpressionList params, EnvironmentStack envStack) { 15 | super(params, envStack); 16 | } 17 | 18 | public void evaluate() throws IllegalExpressionException { 19 | if (params.getList().size() == 1) { 20 | Expression ex= params.getList().get(0); 21 | ex.evaluate(); 22 | RQLSymbol symb = ex.getValue(); 23 | if (symb instanceof RQLSet) { 24 | value = new RQLSet(); 25 | computeSubset((RQLSet) symb); 26 | } else { 27 | throw new IllegalExpressionException("Subset cannot be applied to " + ex.getValue().getClass().getName()); 28 | } 29 | } else { 30 | throw new IllegalExpressionException("Subset requires a single argument of type RQLSet"); 31 | } 32 | } 33 | 34 | private void computeSubset(RQLSet set) throws IllegalExpressionException { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/Expression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | import retroscope.datamodel.datastruct.Null; 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.rql.environment.Environment; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.parser.Valuable; 8 | import retroscope.rql.syntaxtree.expression.literals.Variable; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created by Aleksey on 12/20/2016. 14 | * 15 | */ 16 | public abstract class Expression implements Valuable, Cloneable{ 17 | 18 | //private Variable valID = null; 19 | protected RQLSymbol value; 20 | protected EnvironmentStack stack; 21 | protected boolean dirty = true; 22 | 23 | public Expression() {} 24 | 25 | public RQLSymbol getValue() { 26 | if (value == null) { 27 | value = new Null(); 28 | } 29 | return value; 30 | } 31 | 32 | public Environment getEnvironment() { 33 | return stack.peek(); 34 | } 35 | 36 | public EnvironmentStack getEnvironmentStack() { 37 | return stack; 38 | } 39 | 40 | public void setEnvironmentStack(EnvironmentStack stack) { 41 | this.stack = stack; 42 | } 43 | 44 | public abstract void evaluate() throws IllegalExpressionException; 45 | 46 | public abstract Expression clone(); 47 | 48 | public boolean isDirty() { 49 | return dirty; 50 | } 51 | 52 | public abstract boolean computeDirty(); 53 | 54 | public abstract ArrayList findVars(); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/variables/StringRQLVariable.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.variables; 2 | 3 | public class StringRQLVariable extends RQLVariable { 4 | 5 | public StringRQLVariable(String val) { 6 | super(); 7 | if (val.startsWith("\"") && val.endsWith("\"")) { 8 | val = val.substring(1, val.length() - 1); 9 | } 10 | this.setValue(val); 11 | } 12 | 13 | public StringRQLVariable(String name, String val) { 14 | super(name); 15 | if (val.startsWith("\"") && val.endsWith("\"")) { 16 | val = val.substring(1, val.length() - 1); 17 | } 18 | this.setValue(val); 19 | } 20 | 21 | public String toRQLString() { 22 | return this.getName() + ":\"" + value + "\""; 23 | } 24 | 25 | public String toEmitRQLString() { 26 | StringBuilder sb = new StringBuilder(); 27 | sb.append(this.getName()); 28 | sb.append('|'); 29 | for (Long n : getNodeIDs()) { 30 | sb.append(n); 31 | sb.append(','); 32 | } 33 | sb.deleteCharAt(sb.length() - 1); 34 | sb.append(':'); 35 | sb.append('"'); 36 | sb.append(value); 37 | sb.append('"'); 38 | return sb.toString(); 39 | } 40 | 41 | public StringRQLVariable clone() { 42 | StringRQLVariable clone = new StringRQLVariable(value); 43 | clone.setName(this.getName()); 44 | return clone; 45 | } 46 | 47 | @Override 48 | public void negate() { 49 | //do nothing 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/server/StatementProcessor.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import org.apache.ignite.Ignite; 4 | import retroscope.rql.syntaxtree.Query; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class StatementProcessor { 10 | 11 | public static List processStatements(List statements, String appName, String iconf) { 12 | List runners = new ArrayList<>(statements.size()); 13 | for (int i = 0; i < statements.size(); i++) { 14 | Query s = statements.get(i); 15 | DistributedQueryRunner qr = new DistributedQueryRunner(s, appName, iconf); 16 | runners.add(i, qr); 17 | } 18 | 19 | for (Runner r: runners) { 20 | if (r.isExplain()) { 21 | r.explain(); 22 | } else { 23 | r.execute(); 24 | } 25 | } 26 | 27 | return runners; 28 | } 29 | 30 | public static List processStatements(List statements, String appName, Ignite ignite) { 31 | List runners = new ArrayList<>(statements.size()); 32 | for (int i = 0; i < statements.size(); i++) { 33 | Query s = statements.get(i); 34 | DistributedQueryRunner qr = new DistributedQueryRunner(s, appName, ignite); 35 | runners.add(i, qr); 36 | 37 | } 38 | 39 | for (Runner r: runners) { 40 | if (r.isExplain()) { 41 | r.explain(); 42 | } else { 43 | r.execute(); 44 | } 45 | } 46 | 47 | return runners; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/parser/mTokens.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.parser;// Output created by jacc on Fri Nov 24 17:23:03 EST 2017 2 | 3 | public interface mTokens { 4 | int ENDINPUT = 0; 5 | int ALL_NODES = 1; 6 | int AND = 2; 7 | int ASSIGN = 3; 8 | int AT = 4; 9 | int COMPUTE = 5; 10 | int EQ = 6; 11 | int EXISTS = 7; 12 | int EXPLAIN = 8; 13 | int FALSE = 9; 14 | int FLOAT_LITERAL = 10; 15 | int FOR_ALL = 11; 16 | int FOR_EACH = 12; 17 | int FROM = 13; 18 | int GEQ = 14; 19 | int GLOBAL = 15; 20 | int IDENTIFIER = 16; 21 | int IN = 17; 22 | int INTEGER_LITERAL = 18; 23 | int INTERSECT = 19; 24 | int IS_PROPER_SUBSET = 20; 25 | int IS_SUBSET = 21; 26 | int LEQ = 22; 27 | int NEQ = 23; 28 | int NODES = 24; 29 | int NOT_IN = 25; 30 | int ON = 26; 31 | int OR = 27; 32 | int OUT = 28; 33 | int SAME_NODE = 29; 34 | int SELECT = 30; 35 | int STRING_LITERAL = 31; 36 | int TIME = 32; 37 | int TO = 34; 38 | int TRUE = 35; 39 | int UNION = 36; 40 | int VAR = 38; 41 | int WHEN = 39; 42 | int error = 48; 43 | // '!' (code=33) 44 | // '%' (code=37) 45 | // '(' (code=40) 46 | // ')' (code=41) 47 | // '*' (code=42) 48 | // '+' (code=43) 49 | // ',' (code=44) 50 | // '-' (code=45) 51 | // '.' (code=46) 52 | // '/' (code=47) 53 | // ':' (code=58) 54 | // ';' (code=59) 55 | // '<' (code=60) 56 | // '=' (code=61) 57 | // '>' (code=62) 58 | // '?' (code=63) 59 | // '[' (code=91) 60 | // '\\' (code=92) 61 | // ']' (code=93) 62 | // '{' (code=123) 63 | // '}' (code=125) 64 | } 65 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/stackedexpression/ForAll.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.stackedexpression; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.IdentifierList; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class ForAll extends SetIteratingExpression { 10 | 11 | private long nCompletionsDone; 12 | 13 | public ForAll(IdentifierList ids, Expression ex1, Expression ex2) { 14 | super(ids, ex1, ex2); 15 | } 16 | 17 | public ForAll(IteratingFunc aggregate) { 18 | this(aggregate.getIds(), aggregate.getEx1(), aggregate.getEx2()); 19 | } 20 | 21 | @Override 22 | public void evaluate() throws IllegalExpressionException { 23 | nCompletionsDone = 0; 24 | super.evaluate(); 25 | } 26 | 27 | @Override 28 | protected boolean checkExpressionVal(RQLSymbol exVal) { 29 | if (exVal instanceof LongRQLVariable) { 30 | if (((LongRQLVariable) exVal).getValue() == 1) { 31 | if (++nCompletionsDone == getMaxCombinations()) { 32 | this.value = new LongRQLVariable(1); 33 | } 34 | } else { 35 | return true; //we have a false, so FORALL does not hold, we can short-circuit 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | @Override 42 | public ForAll clone() { 43 | return new ForAll(getIds(), getEx1().clone(), getEx2().clone()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/assign/AssignExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.assign; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | import retroscope.rql.syntaxtree.expression.literals.Variable; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class AssignExpression extends Expression { 13 | 14 | private Variable identifier; 15 | private Expression val; 16 | 17 | public AssignExpression(Variable identifier, Expression val) { 18 | this.identifier = identifier; 19 | this.val = val; 20 | dirty = true; 21 | } 22 | 23 | @Override 24 | public void evaluate() throws IllegalExpressionException { 25 | val.evaluate(); 26 | RQLSymbol s = val.getValue(); 27 | s.setName(identifier.getName()); 28 | getEnvironment().assignToSymbol(identifier.getName(), s); 29 | this.value = new LongRQLVariable(1); 30 | } 31 | 32 | public void setEnvironmentStack(EnvironmentStack stack) { 33 | this.stack = stack; 34 | val.setEnvironmentStack(stack); 35 | } 36 | 37 | @Override 38 | public Expression clone() { 39 | return new AssignExpression(identifier.clone(), val.clone()); 40 | } 41 | 42 | @Override 43 | public boolean computeDirty() { 44 | return dirty; 45 | } 46 | 47 | @Override 48 | public ArrayList findVars() { 49 | return val.findVars(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/util/ByteArray.java: -------------------------------------------------------------------------------- 1 | package retroscope.util; 2 | 3 | import java.io.Serializable; 4 | import java.util.Arrays; 5 | import org.apache.commons.codec.binary.Base64; 6 | 7 | /** 8 | * Created by aleksey on 10/18/16. 9 | * This class is borrowed from project Voldemort 10 | */ 11 | /** 12 | * A byte array container that provides an equals and hashCode pair based on the 13 | * contents of the byte array. This is useful as a key for Maps. 14 | */ 15 | public final class ByteArray implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | public static final ByteArray EMPTY = new ByteArray(); 20 | 21 | private final byte[] underlying; 22 | 23 | public ByteArray(byte... underlying) { 24 | this.underlying = underlying; 25 | } 26 | 27 | public ByteArray(String base64) { 28 | this.underlying = Base64.decodeBase64(base64.getBytes()); 29 | } 30 | 31 | public byte[] get() { 32 | return underlying; 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return Arrays.hashCode(underlying); 38 | } 39 | 40 | @Override 41 | public boolean equals(Object obj) { 42 | if(this == obj) 43 | return true; 44 | if(!(obj instanceof ByteArray)) 45 | return false; 46 | ByteArray other = (ByteArray) obj; 47 | return Arrays.equals(underlying, other.underlying); 48 | } 49 | 50 | public int length() { 51 | return underlying.length; 52 | } 53 | 54 | public String toString() { 55 | //Base64 56 | byte[] encodedBytes = Base64.encodeBase64(underlying); 57 | return new String(encodedBytes); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Retroscope 2 | Retroscope is a comprehensive lightweight solution for monitoring and debugging of distributed systems. It allows users to query and reconstruct past consistent global states of an application. Retroscope achieves this by augmenting the system with Hybrid Logical Clocks (HLC) and streaming HLCstamped event logs to storage and processing, where HLC timestamps are used for constructing global (or nonlocal) snapshots upon request. Retroscope exposes a rich querying interface via query language (RQL) to facilitate searching for global/nonlocal predicates across past consistent states. Retroscope performs the search by advancing through global/nonlocal states in smallincremental steps, greatly reducing the amount of computation needed to arrive to each consistent state. Embarrassingly-parallel nature of Retroscope search algorithm allows it to use many distributed worker processes to handle a single query. 3 | 4 | Retroscope uses Apache Ignite as its backbone for streaming, storage and compute. 5 | 6 | **Structure of the project** 7 | - RetroLogServer - main library with HLC and log streaming APIs. Main class of the library is Retroscope. A library user can create an instance of Retroscope and use its methods to make HLC ticks and log changes in variables/states with Retroscope 8 | - RQLServer - server side of the Retroscope API. Parses the queries, schedules Ignite Compute workers. 9 | - IgniteServer - Just a wrapper against Apache Ignite with some Retroscope dependencies. Regualr Ignite with peer class loading can be used instead. 10 | - RQLBench - small RQL Client to run some queries repeatedly and collect some performance stats 11 | - RetroAppViewer - GUI to check on the properties of Retroscope apps 12 | - RetrscopeExample - Some examples 13 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/literals/SetLiteral.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.literals; 2 | 3 | 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.ExpressionList; 9 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class SetLiteral extends Expression 14 | { 15 | protected ExpressionList expressions; 16 | 17 | public SetLiteral(ExpressionList expList) 18 | { 19 | expressions = expList; 20 | } 21 | 22 | public void evaluate() throws IllegalExpressionException { 23 | RQLSet set = new RQLSet(); 24 | for (Expression ex1: expressions.getList()) { 25 | ex1.evaluate(); 26 | set.add(ex1.getValue()); 27 | } 28 | this.value = set; 29 | } 30 | 31 | public void setEnvironmentStack(EnvironmentStack stack) { 32 | this.stack = stack; 33 | for (Expression ex : expressions.getList()) { 34 | ex.setEnvironmentStack(stack); 35 | } 36 | } 37 | 38 | public SetLiteral clone() { 39 | return new SetLiteral(expressions); 40 | } 41 | 42 | @Override 43 | public boolean computeDirty() { 44 | dirty = false; 45 | for (Expression ex1: expressions.getList()) { 46 | if (ex1.computeDirty()) { 47 | dirty = true; 48 | } 49 | } 50 | return dirty; 51 | } 52 | 53 | @Override 54 | public ArrayList findVars() { 55 | ArrayList v = new ArrayList<>(); 56 | for (Expression ex1: expressions.getList()) { 57 | v.addAll(ex1.findVars()); 58 | } 59 | return v; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/assign/DeclareExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.assign; 2 | 3 | import retroscope.datamodel.datastruct.Null; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | import retroscope.rql.syntaxtree.expression.literals.Variable; 8 | 9 | import java.util.ArrayList; 10 | 11 | public class DeclareExpression extends Expression { 12 | 13 | private Variable identifier; 14 | private boolean global = false; 15 | 16 | public DeclareExpression(Variable identifier, boolean global) { 17 | this.identifier = identifier; 18 | this.global = global; 19 | dirty = true; 20 | } 21 | 22 | @Override 23 | public void evaluate() throws IllegalExpressionException { 24 | if (!global) { 25 | if (getEnvironment().getSymbolInThisEnv(identifier.getName()) == null) { 26 | getEnvironment().putSymbol(identifier.getName(), new Null()); 27 | } 28 | } else { 29 | if (getEnvironment().getGlobal().getSymbol(identifier.getName()) == null) { 30 | getEnvironment().getGlobal().putSymbol(identifier.getName(), new Null()); 31 | } 32 | } 33 | 34 | this.value = new LongRQLVariable(1); 35 | } 36 | 37 | @Override 38 | public Expression clone() { 39 | return new DeclareExpression(identifier.clone(), global); 40 | } 41 | 42 | @Override 43 | public boolean computeDirty() { 44 | return dirty; 45 | } 46 | 47 | @Override 48 | public ArrayList findVars() { 49 | return new ArrayList<>(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/parser/datamodel.flex: -------------------------------------------------------------------------------- 1 | //java -jar JFlex.jar D:\Dropbox\Retroscope++\retroscope-lib\RetroLogServer\src\main\java\retroscope\datamodel\parser\datamodel.flex 2 | package retroscope.datamodel.parser; 3 | %% 4 | 5 | %class DataScanner 6 | %implements dataTokens 7 | %unicode 8 | %int 9 | %debug 10 | 11 | %{ 12 | int token; 13 | Object semanticValue; 14 | int line(){return yyline;} 15 | int column(){return yycolumn;} 16 | %} 17 | 18 | LineTerminator=\r|\n|\r\n 19 | Space=[ \t\f] 20 | 21 | Comment={TraditionalComment}|{EndOfLineComment} 22 | 23 | TraditionalComment="/*" ~"*/" 24 | EndOfLineComment="#" ~{LineTerminator} 25 | 26 | Identifier=[:jletter:] [:jletterdigit:]* 27 | IntegerLiteral=0|[1-9][0-9]* 28 | 29 | %% 30 | 31 | "null" {return token=NIL;} 32 | 33 | {IntegerLiteral} {semanticValue=Long.parseLong(yytext());return token=INTEGER_LITERAL;} 34 | ([0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) {semanticValue=Double.parseDouble(yytext());return FLOAT_LITERAL;} 35 | 36 | L?\"(\.|[^\"])*\" {semanticValue=yytext(); return STRING_LITERAL;} 37 | 38 | {Identifier} {semanticValue=yytext();return token=IDENTIFIER;} 39 | 40 | \: {return token=':';} 41 | \; {return token=';';} 42 | \< {return token='<';} 43 | \> {return token='>';} 44 | \( {return token='(';} 45 | \) {return token=')';} 46 | \{ {return token='{';} 47 | \} {return token='}';} 48 | \[ {return token='[';} 49 | \] {return token=']';} 50 | \, {return token=',';} 51 | \- {return token='-';} 52 | \| {return token='|';} 53 | "..." {return token=APPEND;} 54 | "--" {return token=REMOVE;} 55 | 56 | 57 | 58 | {Space} {} 59 | {Comment} {} 60 | {LineTerminator} {} 61 | <> {return token=ENDINPUT;} 62 | . {throw new Error("unexpected"+yytext());} 63 | 64 | 65 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Cardinality.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.sets.RQLSet; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.environment.EnvironmentStack; 6 | import retroscope.rql.functions.RQLBuiltInFunction; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.ExpressionList; 9 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 10 | 11 | public class Cardinality extends RQLBuiltInFunction { 12 | 13 | public Cardinality(ExpressionList params, EnvironmentStack envStack) { 14 | super(params, envStack); 15 | } 16 | 17 | public void evaluate() throws IllegalExpressionException { 18 | if (params.getList().size() == 1) { 19 | Expression ex= params.getList().get(0); 20 | ex.evaluate(); 21 | if (ex.getValue() instanceof RQLSet) { 22 | // System.out.println(((RQLSet) ex.getValue()).size()); 23 | value = new LongRQLVariable(((RQLSet) ex.getValue()).size()); 24 | } else { 25 | if (ex.getValue() != null) { 26 | throw new IllegalExpressionException("Cardinality cannot be applied to " + ex.getValue().getClass().getName()); 27 | } 28 | } 29 | } else { 30 | RQLSet cardinalitySet = new RQLSet(); 31 | for (Expression ex: params.getList()) { 32 | ex.evaluate(); 33 | if (ex.getValue() instanceof RQLSet) { 34 | cardinalitySet.add(new LongRQLVariable(((RQLSet) ex.getValue()).size())); 35 | } else { 36 | throw new IllegalExpressionException("Cardinality cannot be applied to " + ex.getValue().getClass().getName()); 37 | } 38 | } 39 | value = cardinalitySet; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/logical/Or.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.logical; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 9 | 10 | public class Or extends TwoOperandExpression 11 | { 12 | 13 | public Or(Expression ex1, Expression ex2) 14 | { 15 | super(ex1, ex2); 16 | } 17 | 18 | @Override 19 | public void evaluate() throws IllegalExpressionException { 20 | ex1.evaluate(); 21 | RQLSymbol ex1Val = ex1.getValue(); 22 | Number n1 = null; 23 | if (ex1Val instanceof RQLVariable) { 24 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 25 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 26 | } 27 | boolean shortCircuit = false; 28 | if (n1 != null) { 29 | shortCircuit = (n1.intValue() != 0); 30 | } else { 31 | throw new IllegalExpressionException("Cannot apply logical operators to " + ex1Val.getClass().getName()); 32 | } 33 | 34 | if (shortCircuit) { 35 | value = new LongRQLVariable(1); 36 | } else { 37 | ex2.evaluate(); 38 | RQLSymbol ex2Val = ex2.getValue(); 39 | n1 = null; 40 | if (((RQLVariable) ex2Val).getValue() instanceof Number) { 41 | n1 = (Number) ((RQLVariable) ex2Val).getValue(); 42 | } 43 | if (n1 != null) { 44 | shortCircuit = (n1.intValue() != 0); 45 | } else { 46 | throw new IllegalExpressionException("Cannot apply logical operators to " + ex1Val.getClass().getName() 47 | + " and " + ex2Val.getClass().getName()); 48 | } 49 | 50 | value = new LongRQLVariable(shortCircuit ? 1 : 0); 51 | } 52 | } 53 | } 54 | 55 | public Or clone() { 56 | return new Or(ex1.clone(), ex2.clone()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/net/ignite/NodeMeta.java: -------------------------------------------------------------------------------- 1 | package retroscope.net.ignite; 2 | 3 | import retroscope.hlc.HLC; 4 | import retroscope.hlc.Timestamp; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Aleksey on 7/23/2017. 10 | * this class represents teh node meta data to be stored in KV meta store, such as ignite 11 | */ 12 | public class NodeMeta { 13 | 14 | private int nodeId; 15 | private String appName; 16 | private long timestamp; 17 | private long seqSize; 18 | private long hotTime; 19 | 20 | 21 | public NodeMeta(String appName) { 22 | this.appName = appName; 23 | } 24 | 25 | public String getAppName() { 26 | return appName; 27 | } 28 | 29 | public NodeMeta setAppName(String appName) { 30 | this.appName = appName; 31 | return this; 32 | } 33 | 34 | public NodeMeta setNodeId(int nodeId) { 35 | this.nodeId = nodeId; 36 | return this; 37 | } 38 | 39 | public NodeMeta setTimestamp(long timestamp) { 40 | this.timestamp = timestamp; 41 | return this; 42 | } 43 | 44 | public int getNodeId() { 45 | return nodeId; 46 | } 47 | 48 | public long getTimestamp() { 49 | return timestamp; 50 | } 51 | 52 | public long getSeqSize() { 53 | return seqSize; 54 | } 55 | 56 | public NodeMeta setSeqSize(long seqSize) { 57 | this.seqSize = seqSize; 58 | return this; 59 | } 60 | 61 | public long getHotTime() { 62 | return hotTime; 63 | } 64 | 65 | public NodeMeta setHotTime(long hotTime) { 66 | this.hotTime = hotTime; 67 | return this; 68 | } 69 | 70 | public String toString() { 71 | StringBuilder sb = new StringBuilder(); 72 | sb.append("Node Mata: app = "); 73 | sb.append(this.appName); 74 | sb.append("; id = "); 75 | sb.append(this.nodeId); 76 | sb.append("; hlc = "); 77 | sb.append(this.timestamp); 78 | return sb.toString(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/condition/Condition.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.condition; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.expression.Expression; 6 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 7 | import retroscope.rql.syntaxtree.expression.literals.Variable; 8 | 9 | import java.util.ArrayList; 10 | 11 | public class Condition extends Expression { 12 | 13 | private Expression condition; 14 | private Ternary options; 15 | 16 | public Condition(Expression condition, Ternary options) { 17 | this.condition = condition; 18 | this.options = options; 19 | } 20 | 21 | @Override 22 | public void evaluate() throws IllegalExpressionException { 23 | condition.evaluate(); 24 | RQLSymbol condVal = condition.getValue(); 25 | if (condVal instanceof LongRQLVariable) { 26 | if (((LongRQLVariable) condVal).getValue() != 0) { 27 | options.getChoice1().evaluate(); 28 | value = options.getChoice1().getValue(); 29 | } else if (options.getChoice2() != null) { 30 | options.getChoice2().evaluate(); 31 | value = options.getChoice2().getValue(); 32 | } else { 33 | 34 | //skip action treated like TRUE 35 | this.value = new LongRQLVariable(1); 36 | } 37 | } 38 | } 39 | 40 | @Override 41 | public Expression clone() { 42 | return new Condition(condition.clone(), options); 43 | } 44 | 45 | @Override 46 | public boolean computeDirty() { 47 | dirty = condition.computeDirty(); 48 | return dirty; 49 | } 50 | 51 | @Override 52 | public ArrayList findVars() { 53 | ArrayList v = new ArrayList<>(); 54 | v.addAll(condition.findVars()); 55 | return v; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /retroscope-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 172.31.30.184 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/sets/SetOperator.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.sets; 2 | 3 | import retroscope.datamodel.datastruct.Null; 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.datamodel.datastruct.sets.RQLSet; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 9 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 10 | import retroscope.rql.syntaxtree.expression.literals.Variable; 11 | 12 | public abstract class SetOperator extends TwoOperandExpression { 13 | 14 | public SetOperator(Expression ex1, Expression ex2) { 15 | super(ex1, ex2); 16 | } 17 | 18 | @Override 19 | public void evaluate() throws IllegalExpressionException { 20 | evaluateOperands(); 21 | RQLSymbol ex1Val = ex1.getValue(); 22 | RQLSymbol ex2Val = ex2.getValue(); 23 | 24 | if (ex1Val instanceof Null) { 25 | ex1Val = resolveNull(ex1Val, ex1); 26 | } 27 | 28 | if (ex2Val instanceof Null) { 29 | ex2Val = resolveNull(ex2Val, ex2); 30 | } 31 | 32 | if (ex1Val instanceof RQLSet && ex2Val instanceof RQLSet) { 33 | this.value = setOperation((RQLSet)ex1Val, (RQLSet)ex2Val); 34 | } else { 35 | throw new IllegalExpressionException("Cannot use set operators with " + ex1Val.getClass().getName() 36 | + " and " + ex2Val.getClass().getName()); 37 | } 38 | } 39 | 40 | private RQLSymbol resolveNull(RQLSymbol exVal, Expression ex) { 41 | RQLSymbol retSym = exVal; 42 | if (ex instanceof Variable) { 43 | retSym = new RQLSet(); 44 | getEnvironment().assignToSymbol(((Variable) ex).getName(), retSym); 45 | } 46 | return retSym; 47 | } 48 | 49 | protected abstract RQLSymbol setOperation(RQLSet s1, RQLSet s2) throws IllegalExpressionException; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/logical/LogicalExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.logical; 2 | 3 | 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 9 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 10 | 11 | public abstract class LogicalExpression extends TwoOperandExpression 12 | { 13 | public LogicalExpression(Expression ex1, Expression ex2) 14 | { 15 | super(ex1, ex2); 16 | } 17 | 18 | public void evaluate() throws IllegalExpressionException { 19 | /*ex1.evaluate(); 20 | RQLSymbol ex1Val = ex1.getValue(); 21 | Number n1 = null; 22 | if (ex1Val instanceof RQLVariable) { 23 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 24 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 25 | } 26 | boolean shortCircuit 27 | } 28 | ex2.evaluate(); 29 | RQLSymbol ex2Val = ex2.getValue(); 30 | 31 | if (ex1Val instanceof RQLVariable && ex2Val instanceof RQLVariable) { 32 | Number n1 = null; 33 | Number n2 = null; 34 | boolean cmp = false; 35 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 36 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 37 | } 38 | if (((RQLVariable) ex2Val).getValue() instanceof Number) { 39 | n2 = (Number) ((RQLVariable) ex2Val).getValue(); 40 | } 41 | if (n1 != null && n2 != null) { 42 | cmp = logicalAction(n1, n2); 43 | } else { 44 | throw new IllegalExpressionException("Cannot apply logical operators String values"); 45 | } 46 | 47 | value = new LongRQLVariable(cmp ? 1 : 0); 48 | } else { 49 | throw new IllegalExpressionException("Cannot apply logical operators to " + ex1Val.getClass().getName() 50 | + " and " + ex2Val.getClass().getName()); 51 | }*/ 52 | } 53 | 54 | protected abstract boolean logicalAction(Number n1, Number n2); 55 | 56 | protected abstract boolean op1ShortCircuit(Number n1); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/RQLSymbol.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct; 2 | 3 | import retroscope.datamodel.datastruct.misc.IdList; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * Created by Aleksey on 11/1/2017. 12 | * 13 | */ 14 | public abstract class RQLSymbol implements RQLDataStructure { 15 | 16 | private String name = null; 17 | private Set nodeIDs = new HashSet<>(); 18 | 19 | private boolean dirty = true; 20 | 21 | public RQLSymbol() {} 22 | 23 | public RQLSymbol(String name) { 24 | this.name = name; 25 | } 26 | 27 | public void addNodeIDs(IdList list) { 28 | if (list != null) { 29 | this.nodeIDs = list.getIds(); 30 | } 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public boolean isComplete() { 43 | return name != null; 44 | } 45 | 46 | public abstract void merge(RQLSymbol mergeSymbol); 47 | 48 | public Set getNodeIDs() { 49 | return nodeIDs; 50 | } 51 | 52 | public String getNodeIDsStr() { 53 | StringBuilder sb = new StringBuilder(); 54 | for (Long l: nodeIDs) { 55 | sb.append(l); 56 | sb.append(','); 57 | } 58 | if (sb.length() > 0) { 59 | sb.deleteCharAt(sb.length() - 1); 60 | } 61 | return sb.toString(); 62 | } 63 | 64 | public void addNodeID(long nodeID) { 65 | this.nodeIDs.add(nodeID); 66 | } 67 | 68 | public void addNodeIDs(Collection nodeIDs) { 69 | this.nodeIDs.addAll(nodeIDs); 70 | } 71 | 72 | public void stain() { 73 | dirty = true; 74 | } 75 | public void clean() { dirty = false; } 76 | 77 | public boolean isDirty() { 78 | return dirty; 79 | } 80 | 81 | public abstract RQLSymbol clone(); 82 | 83 | public abstract String toEmitRQLString(); 84 | 85 | public abstract String toValueString(); 86 | 87 | 88 | 89 | } 90 | -------------------------------------------------------------------------------- /RetroAppViewer/src/main/java/retroscope/appviewer/AppData.java: -------------------------------------------------------------------------------- 1 | package retroscope.appviewer; 2 | 3 | 4 | public class AppData { 5 | 6 | private String appName; 7 | private int maxId; 8 | private int heartbeatInterval; 9 | private int maxMissedHeartbeats; 10 | private int blockSize; 11 | 12 | private int bufSize; 13 | private int bufFlushRate; 14 | 15 | private int numNodes = 0; 16 | private int numBlocks = 0; 17 | 18 | public AppData(String appName) { 19 | this.appName = appName; 20 | } 21 | 22 | public String getAppName() { 23 | return appName; 24 | } 25 | 26 | public int getMaxId() { 27 | return maxId; 28 | } 29 | 30 | public int getHeartbeatInterval() { 31 | return heartbeatInterval; 32 | } 33 | 34 | public int getMaxMissedHeartbeats() { 35 | return maxMissedHeartbeats; 36 | } 37 | 38 | public int getBlockSize() { 39 | return blockSize; 40 | } 41 | 42 | 43 | public int getNumNodes() { 44 | return numNodes; 45 | } 46 | 47 | public int getNumBlocks() { 48 | return numBlocks; 49 | } 50 | 51 | public void setMaxId(int maxId) { 52 | this.maxId = maxId; 53 | } 54 | 55 | public void setHeartbeatInterval(int heartbeatInterval) { 56 | this.heartbeatInterval = heartbeatInterval; 57 | } 58 | 59 | public void setMaxMissedHeartbeats(int maxMissedHeartbeats) { 60 | this.maxMissedHeartbeats = maxMissedHeartbeats; 61 | } 62 | 63 | public void setBlockSize(int blockSize) { 64 | this.blockSize = blockSize; 65 | } 66 | 67 | public void setNumNodes(int numNodes) { 68 | this.numNodes = numNodes; 69 | } 70 | 71 | public void setNumBlocks(int numBlocks) { 72 | this.numBlocks = numBlocks; 73 | } 74 | 75 | public int getBufSize() { 76 | return bufSize; 77 | } 78 | 79 | public void setBufSize(int bufSize) { 80 | this.bufSize = bufSize; 81 | } 82 | 83 | public int getBufFlushRate() { 84 | return bufFlushRate; 85 | } 86 | 87 | public void setBufFlushRate(int bufFlushRate) { 88 | this.bufFlushRate = bufFlushRate; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /RQLBench/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | RQLBench 13 | 14 | 15 | 16 | 17 | org.retroscope 18 | RetroLogServer 19 | 1.0-SNAPSHOT 20 | 21 | 22 | org.retroscope 23 | RQLServer 24 | 1.0-SNAPSHOT 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-assembly-plugin 34 | 35 | 36 | package 37 | 38 | single 39 | 40 | 41 | 42 | 43 | 44 | retroscope.bench.BenchRQLClient 45 | 46 | 47 | 48 | 49 | jar-with-dependencies 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/parser/RQLData.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.parser; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.hlc.Timestamp; 5 | 6 | import java.util.*; 7 | 8 | public class RQLData { 9 | 10 | private ArrayList dataItems; 11 | private Timestamp timestamp; 12 | private String logName; 13 | private int nodeId; 14 | 15 | public RQLData() { 16 | dataItems = new ArrayList<>(); 17 | } 18 | 19 | public String getLogName() { 20 | return logName; 21 | } 22 | 23 | public void setLogName(String logName) { 24 | this.logName = logName; 25 | } 26 | 27 | public ArrayList getDataItems() { 28 | return dataItems; 29 | } 30 | 31 | public Timestamp getTimestamp() { 32 | return timestamp; 33 | } 34 | 35 | public void setTimestamp(Timestamp timestamp) { 36 | this.timestamp = timestamp; 37 | } 38 | 39 | public void setTimestamp(long hlc) { 40 | setTimestamp(new Timestamp(hlc)); 41 | } 42 | 43 | 44 | public void appendDataItem(RQLSymbol dataItem) { 45 | dataItems.add(dataItem); 46 | } 47 | 48 | public void setDataItems(ArrayList dataItems) { 49 | this.dataItems = dataItems; 50 | } 51 | 52 | public int getNodeId() { 53 | return nodeId; 54 | } 55 | 56 | public void setNodeId(long nodeId) { 57 | setNodeId((int) nodeId); 58 | } 59 | 60 | public void setNodeId(int nodeId) { 61 | //if we set node it for this data object then all symbols in this RQLData are form the same node 62 | this.nodeId = nodeId; 63 | for (RQLSymbol s : dataItems) { 64 | s.addNodeID(nodeId); 65 | } 66 | } 67 | 68 | public void restrict(ArrayList params) { 69 | Iterator iterator = dataItems.iterator(); 70 | while (iterator.hasNext()) { 71 | RQLSymbol entry = iterator.next(); 72 | if (!params.contains(entry.getName())) { 73 | //System.out.println("Restricting: removing key " + entry.getKey()); 74 | iterator.remove(); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /RQLServer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | RQLServer 13 | 14 | 15 | 16 | 17 | org.retroscope 18 | RetroLogServer 19 | 1.0-SNAPSHOT 20 | 21 | 22 | org.retroscope 23 | RetrscopeExample 24 | 1.0-SNAPSHOT 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-assembly-plugin 34 | 35 | 36 | package 37 | 38 | single 39 | 40 | 41 | 42 | 43 | 44 | retroscope.rql.console.Console 45 | 46 | 47 | 48 | 49 | jar-with-dependencies 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /IgniteServer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | IgniteServer 13 | 14 | 15 | 16 | 17 | org.retroscope 18 | RetroLogServer 19 | 1.0-SNAPSHOT 20 | 21 | 22 | 23 | org.retroscope 24 | RQLServer 25 | 1.0-SNAPSHOT 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-assembly-plugin 35 | 36 | 37 | package 38 | 39 | single 40 | 41 | 42 | 43 | 44 | 45 | retroscope.net.igniteserver.IgniteServer 46 | 47 | 48 | 49 | 50 | jar-with-dependencies 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/server/SearchJobCallable.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import org.apache.ignite.IgniteCache; 4 | import org.apache.ignite.lang.IgniteCallable; 5 | import retroscope.hlc.Timestamp; 6 | import retroscope.net.ignite.StateSequence; 7 | import retroscope.rql.environment.GlobalCut; 8 | import retroscope.rql.parser.RQLSearchParam; 9 | import retroscope.rql.worker.QueryWorker; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Collection; 13 | 14 | 15 | public class SearchJobCallable implements IgniteCallable> { 16 | 17 | private long seqTime; 18 | private String[] logIds; 19 | private RQLSearchParam rqlSearchParam; 20 | private Collection> remoteCaches; 21 | private IgniteCache localCache; 22 | 23 | public SearchJobCallable( 24 | long seqTime, 25 | String[] logIds, 26 | RQLSearchParam rqlSearchParam, 27 | Collection> remoteCaches 28 | ) { 29 | this.seqTime = seqTime; 30 | this.logIds = logIds; 31 | this.rqlSearchParam = rqlSearchParam; 32 | this.remoteCaches = remoteCaches; 33 | } 34 | 35 | public SearchJobCallable( 36 | long seqTime, 37 | String[] logIds, 38 | RQLSearchParam rqlSearchParam, 39 | Collection> remoteCaches, 40 | IgniteCache localCache 41 | ) { 42 | this.seqTime = seqTime; 43 | this.logIds = logIds; 44 | this.rqlSearchParam = rqlSearchParam; 45 | this.remoteCaches = remoteCaches; 46 | this.localCache = localCache; 47 | } 48 | 49 | @Override 50 | public ArrayList call() throws Exception { 51 | QueryWorker qw = new QueryWorker(rqlSearchParam, new Timestamp(getSeqTime(), (short)0)); 52 | qw.setRemoteCaches(remoteCaches); 53 | qw.setLocalCache(localCache); 54 | return qw.runWorker(); 55 | } 56 | 57 | public long getSeqTime() { 58 | return seqTime; 59 | } 60 | 61 | public IgniteCache getLocalCache() { 62 | return localCache; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /RetroAppViewer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | RetroAppViewer 13 | 14 | 15 | 16 | 17 | org.retroscope 18 | RetroLogServer 19 | 1.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | jfree 25 | jfreechart 26 | 1.0.13 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-assembly-plugin 35 | 36 | 37 | package 38 | 39 | single 40 | 41 | 42 | 43 | 44 | 45 | retroscope.appviewer.RetroAppViewer 46 | 47 | 48 | 49 | 50 | jar-with-dependencies 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /RetrscopeExample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | retroscope-lib 7 | org.retroscope 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | RetrscopeExample 13 | 14 | 15 | 16 | 17 | org.retroscope 18 | RetroLogServer 19 | 1.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | io.netty 25 | netty-all 26 | 4.1.5.Final 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-assembly-plugin 37 | 38 | 39 | package 40 | 41 | single 42 | 43 | 44 | 45 | 46 | 47 | examples.SimpleMultiNode 48 | 49 | 50 | 51 | 52 | jar-with-dependencies 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/logical/NotExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.logical; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 9 | import retroscope.rql.syntaxtree.expression.literals.Variable; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class NotExpression extends Expression 14 | { 15 | private Expression ex1; 16 | public NotExpression(Expression ex1) 17 | { 18 | this.ex1 = ex1; 19 | } 20 | 21 | 22 | public void evaluate() throws IllegalExpressionException { 23 | if (dirty) { 24 | ex1.evaluate(); 25 | 26 | RQLSymbol ex1Val = ex1.getValue(); 27 | 28 | if (ex1Val instanceof RQLVariable) { 29 | Number n1 = null; 30 | boolean cmp = false; 31 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 32 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 33 | } 34 | if (n1 != null) { 35 | cmp = n1.intValue() == 0; 36 | } else { 37 | throw new IllegalExpressionException("Cannot apply logical NOT to String value"); 38 | } 39 | 40 | value = new LongRQLVariable(cmp ? 1 : 0); 41 | } else { 42 | throw new IllegalExpressionException("Cannot apply logical NOT to " + ex1Val.getClass().getName()); 43 | } 44 | } 45 | } 46 | 47 | public NotExpression clone() { 48 | return new NotExpression(this.ex1.clone()); 49 | } 50 | 51 | @Override 52 | public boolean computeDirty() { 53 | dirty = ex1.computeDirty(); 54 | return dirty; 55 | } 56 | 57 | @Override 58 | public ArrayList findVars() { 59 | ArrayList v = new ArrayList<>(); 60 | v.addAll(ex1.findVars()); 61 | return v; 62 | } 63 | 64 | public void setEnvironmentStack(EnvironmentStack stack) { 65 | this.stack = stack; 66 | ex1.setEnvironmentStack(stack); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/stackedexpression/ForSome.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.stackedexpression; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.rql.syntaxtree.IdentifierList; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | 9 | public class ForSome extends SetIteratingExpression { 10 | 11 | protected long nCompletions; 12 | private long nCompletionsDone; 13 | private Expression exCompletions; 14 | 15 | public ForSome(IdentifierList ids, Expression ex1, Expression ex2, Expression ex3) { 16 | super(ids, ex1, ex2); 17 | exCompletions = ex3; 18 | } 19 | 20 | public ForSome(IdentifierList ids, Expression ex1, Expression ex2, long nCompletions) { 21 | super(ids, ex1, ex2); 22 | this.nCompletions = nCompletions; 23 | } 24 | 25 | @Override 26 | public void evaluate() throws IllegalExpressionException { 27 | nCompletionsDone = 0; 28 | if (exCompletions != null) { 29 | exCompletions.evaluate(); 30 | if (exCompletions.getValue() instanceof LongRQLVariable) { 31 | nCompletions = ((LongRQLVariable) exCompletions.getValue()).getValue(); 32 | } else { 33 | throw new IllegalExpressionException("Number of completions must be an integer"); 34 | } 35 | } 36 | super.evaluate(); 37 | } 38 | 39 | @Override 40 | protected boolean checkExpressionVal(RQLSymbol exVal) { 41 | if (exVal instanceof LongRQLVariable) { 42 | if (((LongRQLVariable) exVal).getValue() == 1) { 43 | if (++nCompletionsDone >= nCompletions) { 44 | this.value = new LongRQLVariable(1); 45 | return true; 46 | } 47 | } 48 | } 49 | return false; 50 | } 51 | 52 | @Override 53 | public ForSome clone() { 54 | if (exCompletions != null) { 55 | return new ForSome(getIds(), getEx1(), getEx2(), exCompletions); 56 | } else { 57 | return new ForSome(getIds(), getEx1(), getEx2(), nCompletions); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/logical/And.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.logical; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 5 | import retroscope.datamodel.datastruct.variables.RQLVariable; 6 | import retroscope.rql.syntaxtree.expression.Expression; 7 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 8 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 9 | 10 | public class And extends TwoOperandExpression { 11 | 12 | public And(Expression ex1, Expression ex2) { 13 | super(ex1, ex2); 14 | } 15 | 16 | @Override 17 | public void evaluate() throws IllegalExpressionException { 18 | ex1.evaluate(); 19 | RQLSymbol ex1Val = ex1.getValue(); 20 | Number n1 = null; 21 | if (ex1Val instanceof RQLVariable) { 22 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 23 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 24 | } 25 | boolean shortCircuit = false; 26 | if (n1 != null) { 27 | shortCircuit = (n1.intValue() == 0); 28 | } else { 29 | throw new IllegalExpressionException("Cannot apply logical operators to " + ex1Val.getClass().getName()); 30 | } 31 | 32 | if (shortCircuit) { 33 | value = new LongRQLVariable(0); 34 | } else { 35 | ex2.evaluate(); 36 | RQLSymbol ex2Val = ex2.getValue(); 37 | n1 = null; 38 | if (((RQLVariable) ex2Val).getValue() instanceof Number) { 39 | n1 = (Number) ((RQLVariable) ex2Val).getValue(); 40 | } 41 | if (n1 != null) { 42 | shortCircuit = (n1.intValue() == 0); 43 | } else { 44 | throw new IllegalExpressionException("Cannot apply logical operators to " + ex1Val.getClass().getName() 45 | + " and " + ex2Val.getClass().getName()); 46 | } 47 | 48 | value = new LongRQLVariable(shortCircuit ? 0 : 1); 49 | } 50 | } 51 | } 52 | 53 | public And clone() { 54 | return new And(ex1.clone(), ex2.clone()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/variables/RQLVariable.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.variables; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.RQLType; 5 | 6 | public abstract class RQLVariable extends RQLSymbol { 7 | 8 | V value; 9 | 10 | public RQLVariable() { 11 | super(); 12 | } 13 | 14 | public RQLVariable(String name) { 15 | super(name); 16 | } 17 | 18 | public RQLVariable(String name, V val) { 19 | super(name); 20 | this.value = val; 21 | } 22 | 23 | public V getValue() { 24 | return value; 25 | } 26 | 27 | public void setValue(V value) { 28 | this.value = value; 29 | } 30 | 31 | public String toRQLString() { 32 | if (this.getName() != null) { 33 | return this.getName() + ":" + value; 34 | } 35 | return value.toString(); 36 | } 37 | 38 | public String toValueString() { 39 | return value.toString(); 40 | } 41 | 42 | public abstract void negate(); 43 | 44 | public String toEmitRQLString() { 45 | StringBuilder sb = new StringBuilder(); 46 | if (this.getName() != null) { 47 | sb.append(this.getName()); 48 | } 49 | sb.append('|'); 50 | int l1 = sb.length() - 1; 51 | for (Long n : getNodeIDs()) { 52 | sb.append(n); 53 | sb.append(','); 54 | } 55 | sb.deleteCharAt(sb.length() - 1); 56 | if (l1 != sb.length() || this.getName() != null) { 57 | sb.append(':'); 58 | } 59 | sb.append(value); 60 | return sb.toString(); 61 | } 62 | 63 | @Override 64 | public void merge(RQLSymbol mergeSymbol) { 65 | if (mergeSymbol instanceof RQLVariable) { 66 | this.value = ((RQLVariable) mergeSymbol).value; 67 | } 68 | } 69 | 70 | 71 | /* 72 | * Equality is based on the value only and not on additional meta-data, such as name or nodeID 73 | */ 74 | public boolean equals(Object obj) { 75 | return obj != null 76 | && obj instanceof RQLVariable 77 | && value.equals(((RQLVariable)obj).getValue()); 78 | } 79 | 80 | public int hashCode(){ 81 | return value.hashCode(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/datamodel/datastruct/sets/TimerRQLSet.java: -------------------------------------------------------------------------------- 1 | package retroscope.datamodel.datastruct.sets; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | 5 | import java.util.*; 6 | 7 | public class TimerRQLSet extends RQLSet { 8 | 9 | private TreeMap expiryMap; 10 | private long expireTime; 11 | 12 | public TimerRQLSet() { 13 | this.expiryMap = new TreeMap<>(); 14 | this.expireTime = 100; 15 | } 16 | 17 | public TimerRQLSet(String name, long expireTime) { 18 | super(name); 19 | this.expiryMap = new TreeMap<>(); 20 | this.expireTime = expireTime; 21 | } 22 | 23 | public void add(RQLSymbol s) { 24 | super.add(s); 25 | //use system time instead of HLC to make sure we properly keep track of expiration time 26 | long t = System.currentTimeMillis(); 27 | ExpiryBucket b = expiryMap.get(t); 28 | if (b == null) { 29 | b = new ExpiryBucket(); 30 | expiryMap.put(t, b); 31 | } 32 | b.addSymbol(s); 33 | } 34 | 35 | public void addAll(HashSet set) { 36 | for (RQLSymbol symb: set) { 37 | add(symb); 38 | } 39 | } 40 | 41 | public void addAll(RQLSet set) { 42 | for (RQLSymbol symb: set.getSet()) { 43 | add(symb); 44 | } 45 | } 46 | 47 | public RemoveRQLSet expireItems() { 48 | RemoveRQLSet rset = new RemoveRQLSet(this.getName()); 49 | 50 | long t = System.currentTimeMillis(); 51 | Iterator> iterator = expiryMap.entrySet().iterator(); 52 | boolean old = true; 53 | while (iterator.hasNext() && old) { 54 | Map.Entry entry = iterator.next(); 55 | if (entry.getKey() + expireTime < t) { 56 | for (RQLSymbol s: entry.getValue().getSymbols()) { 57 | rset.add(s); 58 | } 59 | iterator.remove(); 60 | } else { 61 | old = false; 62 | } 63 | } 64 | 65 | return rset; 66 | } 67 | 68 | class ExpiryBucket { 69 | ArrayList symbols; 70 | 71 | public ExpiryBucket() { 72 | symbols = new ArrayList<>(); 73 | } 74 | 75 | public void addSymbol(RQLSymbol s) { 76 | symbols.add(s); 77 | } 78 | 79 | public ArrayList getSymbols() { 80 | return symbols; 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/compare/CompareExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.compare; 2 | 3 | 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.datamodel.datastruct.sets.RQLSet; 6 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 7 | import retroscope.datamodel.datastruct.variables.RQLVariable; 8 | import retroscope.rql.syntaxtree.expression.Expression; 9 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 10 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 11 | 12 | public abstract class CompareExpression extends TwoOperandExpression 13 | { 14 | public CompareExpression(Expression ex1, Expression ex2) 15 | { 16 | super(ex1, ex2); 17 | } 18 | 19 | public void evaluate() throws IllegalExpressionException { 20 | evaluateOperands(); 21 | RQLSymbol ex1Val = ex1.getValue(); 22 | RQLSymbol ex2Val = ex2.getValue(); 23 | 24 | if (ex1Val instanceof RQLVariable && ex2Val instanceof RQLVariable) { 25 | Number n1 = null; 26 | Number n2 = null; 27 | boolean cmp = false; 28 | if (((RQLVariable) ex1Val).getValue() instanceof Number) { 29 | n1 = (Number) ((RQLVariable) ex1Val).getValue(); 30 | } 31 | if (((RQLVariable) ex2Val).getValue() instanceof Number) { 32 | n2 = (Number) ((RQLVariable) ex2Val).getValue(); 33 | } 34 | if (n1 != null && n2 != null) { 35 | cmp = compareNums(n1, n2); 36 | } else if (n1 == null && n2 == null) { 37 | //dealing with strings 38 | String str1 = (String) ((RQLVariable) ex1Val).getValue(); 39 | String str2 = (String) ((RQLVariable) ex2Val).getValue(); 40 | cmp = compareStrings(str1, str2); 41 | } 42 | value = new LongRQLVariable(cmp ? 1 : 0); 43 | } else if (ex1Val instanceof RQLSet && ex2Val instanceof RQLSet) { 44 | value = new LongRQLVariable(compareSets((RQLSet) ex1Val, (RQLSet) ex1Val) ? 1 : 0); 45 | } else { 46 | String ex1Type = "NULL"; 47 | String ex2Type = "NULL"; 48 | if (ex1Val != null) { 49 | ex1Type = ex1Val.getClass().getName(); 50 | } 51 | if (ex2Val != null) { 52 | ex2Type = ex2Val.getClass().getName(); 53 | } 54 | System.out.println("Cannot compare " +ex1Type + " and " + ex2Type); 55 | throw new IllegalExpressionException("Cannot compare " +ex1Type + " and " + ex2Type); 56 | } 57 | } 58 | 59 | protected abstract boolean compareNums(Number n1, Number n2); 60 | 61 | protected abstract boolean compareStrings(String s1, String s2); 62 | 63 | protected abstract boolean compareSets(RQLSet s1, RQLSet s2) throws IllegalExpressionException; 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/Flatten.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.struct.RQLStruct; 6 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 7 | import retroscope.datamodel.datastruct.variables.RQLVariable; 8 | import retroscope.rql.environment.EnvironmentStack; 9 | import retroscope.rql.functions.RQLBuiltInFunction; 10 | import retroscope.rql.syntaxtree.expression.Expression; 11 | import retroscope.rql.syntaxtree.expression.ExpressionList; 12 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 13 | 14 | public class Flatten extends RQLBuiltInFunction { 15 | 16 | public Flatten(ExpressionList params, EnvironmentStack envStack) { 17 | super(params, envStack); 18 | } 19 | 20 | public void evaluate() throws IllegalExpressionException { 21 | value = new RQLSet(); 22 | if (params.getList().size() == 1) { 23 | Expression ex= params.getList().get(0); 24 | ex.evaluate(); 25 | RQLSymbol symb = ex.getValue(); 26 | if (symb instanceof RQLSet) { 27 | recursiveFlatten((RQLSet) symb); 28 | } else { 29 | throw new IllegalExpressionException("Flatten cannot be applied to " + ex.getValue().getClass().getName()); 30 | } 31 | } else { 32 | for (Expression ex: params.getList()) { 33 | ex.evaluate(); 34 | RQLSymbol symb = ex.getValue(); 35 | if (symb instanceof RQLSet) { 36 | recursiveFlatten((RQLSet) symb); 37 | } else if (symb instanceof RQLVariable) { 38 | ((RQLSet) value).add(symb); 39 | } else { 40 | throw new IllegalExpressionException("Flatten cannot be applied to " + ex.getValue().getClass().getName()); 41 | } 42 | } 43 | } 44 | //System.out.println("Flatten"); 45 | } 46 | 47 | private void recursiveFlatten(RQLSet set) throws IllegalExpressionException { 48 | for (RQLSymbol s: set.getSet()) { 49 | if (s instanceof RQLVariable || s instanceof RQLStruct) { 50 | ((RQLSet) value).add(s); 51 | } else if (s instanceof RQLSet) { 52 | recursiveFlatten((RQLSet) s); 53 | } else { 54 | throw new IllegalExpressionException("Flatten cannot be applied to " + s.getClass().getName()); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/functions/AbstractMathFunc.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.functions; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.datamodel.datastruct.sets.RQLSet; 5 | import retroscope.datamodel.datastruct.variables.DoubleRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 7 | import retroscope.rql.environment.EnvironmentStack; 8 | import retroscope.rql.functions.RQLBuiltInFunction; 9 | import retroscope.rql.syntaxtree.expression.Expression; 10 | import retroscope.rql.syntaxtree.expression.ExpressionList; 11 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 12 | 13 | /** 14 | * Created by Aleksey on 1/21/2017. 15 | * 16 | */ 17 | public abstract class AbstractMathFunc extends RQLBuiltInFunction { 18 | 19 | public AbstractMathFunc(ExpressionList params, EnvironmentStack stack) { 20 | super(params, stack); 21 | } 22 | 23 | public void evaluate() throws IllegalExpressionException { 24 | if (params.getList().size() == 1){ 25 | Expression ex = params.getList().get(0); 26 | ex.evaluate(); 27 | if (ex.getValue() instanceof LongRQLVariable) { 28 | this.value = longVarOperation(((LongRQLVariable) ex.getValue()).getValue()); 29 | } else if (ex.getValue() instanceof DoubleRQLVariable) { 30 | this.value = doubleVarOperation(((DoubleRQLVariable) ex.getValue()).getValue()); 31 | } else if (ex.getValue() instanceof RQLSet) { 32 | this.value = setProc((RQLSet) ex.getValue()); 33 | } else { 34 | throw new IllegalExpressionException("Function Abs is not defined for this type (String?)"); 35 | } 36 | } 37 | } 38 | 39 | protected abstract RQLSymbol longVarOperation(long val); 40 | 41 | protected abstract RQLSymbol doubleVarOperation(double val); 42 | 43 | 44 | private RQLSet setProc(RQLSet set) throws IllegalExpressionException { 45 | RQLSet retSet = new RQLSet(); 46 | for (RQLSymbol s: set.getSet()) { 47 | if (s instanceof LongRQLVariable) { 48 | retSet.add(longVarOperation(((LongRQLVariable) s).getValue())); 49 | } else if (s instanceof DoubleRQLVariable) { 50 | retSet.add(doubleVarOperation(((DoubleRQLVariable) s).getValue())); 51 | } else if (s instanceof RQLSet) { 52 | retSet.add(setProc((RQLSet)s)); 53 | } else { 54 | throw new IllegalExpressionException("Function Abs is not defined for this type (String?)"); 55 | } 56 | } 57 | return retSet; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/arithmetic/ArithmeticExpression.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.arithmetic; 2 | 3 | 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.datamodel.datastruct.variables.LongRQLVariable; 6 | import retroscope.datamodel.datastruct.variables.RQLVariable; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 9 | import retroscope.rql.syntaxtree.expression.TwoOperandExpression; 10 | 11 | public abstract class ArithmeticExpression extends TwoOperandExpression 12 | { 13 | public ArithmeticExpression(Expression ex1, Expression ex2) 14 | { 15 | super(ex1, ex2); 16 | } 17 | 18 | public void evaluate() throws IllegalExpressionException { 19 | evaluateOperands(); 20 | RQLSymbol ex1Val = ex1.getValue(); 21 | RQLSymbol ex2Val = ex2.getValue(); 22 | 23 | if (ex1Val instanceof RQLVariable && ex2Val instanceof RQLVariable) { 24 | Long l1 = null; 25 | Long l2 = null; 26 | Double d1 = null; 27 | Double d2 = null; 28 | RQLVariable opResult; 29 | if (((RQLVariable) ex1Val).getValue() instanceof Long) { 30 | l1 = (Long) ((RQLVariable) ex1Val).getValue(); 31 | } 32 | if (((RQLVariable) ex2Val).getValue() instanceof Long) { 33 | l2 = (Long) ((RQLVariable) ex2Val).getValue(); 34 | } 35 | if (((RQLVariable) ex1Val).getValue() instanceof Double) { 36 | d1 = (Double) ((RQLVariable) ex1Val).getValue(); 37 | } 38 | if (((RQLVariable) ex2Val).getValue() instanceof Double) { 39 | d2 = (Double) ((RQLVariable) ex2Val).getValue(); 40 | } 41 | 42 | if (l1 != null && l2 != null) { 43 | opResult = arithmeticOperation(l1, l2); 44 | } else if (d1 != null && d2 != null) { 45 | opResult = arithmeticOperation(d1, d2); 46 | } else if (l1 != null && d2 != null) { 47 | opResult = arithmeticOperation(l1, d2); 48 | } else if (d1 != null && l2 != null) { 49 | opResult = arithmeticOperation(d1, l2); 50 | } else { 51 | throw new IllegalExpressionException("Cannot do math with strings!"); 52 | } 53 | 54 | if (opResult != null) { 55 | value = opResult; 56 | } else { 57 | throw new IllegalExpressionException("Something went wrong while computing stuff"); 58 | } 59 | 60 | } else { 61 | throw new IllegalExpressionException("Cannot use arithmetic operators with " + ex1Val.getClass().getName() 62 | + " and " + ex2Val.getClass().getName()); 63 | } 64 | } 65 | 66 | protected abstract RQLVariable arithmeticOperation(long n1, long n2); 67 | 68 | protected abstract RQLVariable arithmeticOperation(long n1, double n2); 69 | 70 | protected abstract RQLVariable arithmeticOperation(double n1, long n2); 71 | 72 | protected abstract RQLVariable arithmeticOperation(double n1, double n2); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /RQLServer/src/test/java/retroscope/rql/server/DistributedQueryStructTest.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.Ignition; 5 | import org.apache.ignite.configuration.IgniteConfiguration; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import retroscope.Retroscope; 10 | import retroscope.datamodel.datastruct.struct.RQLStruct; 11 | import retroscope.log.RetroscopeLog; 12 | import retroscope.rql.environment.GlobalCut; 13 | import retroscope.rql.parser.Scanner; 14 | import retroscope.rql.parser.rqlParser; 15 | 16 | import java.io.StringReader; 17 | import java.util.List; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | public class DistributedQueryStructTest { 22 | 23 | private static final int LEN = 30; 24 | 25 | private Retroscope retroscope; 26 | private Ignite ignite; 27 | 28 | 29 | @Before 30 | public void setUp() throws Exception { 31 | 32 | IgniteConfiguration ic = new IgniteConfiguration(); 33 | //ic.setDataStreamerThreadPoolSize(1); 34 | ignite = Ignition.start(ic); 35 | retroscope = new Retroscope("testapp"); 36 | retroscope.connectIgnite(ignite); 37 | RetroscopeLog log = retroscope.getLog("testlog"); 38 | for (int i = 0; i < LEN; i++) { 39 | RQLStruct s = log.createStruct("struct").addValue("var1", i*i).addValue("var2", i); 40 | log.setVariable(s).commit(); 41 | } 42 | retroscope.flushStreams(); 43 | Thread.sleep(2000); 44 | } 45 | 46 | 47 | @After 48 | public void tearDown() throws Exception { 49 | ignite.close(); 50 | } 51 | 52 | 53 | @Test 54 | public void testSimpleDistributedQuery() throws Exception { 55 | StringReader q1 = new StringReader("SELECT struct FROM testlog WHEN EXISTS s IN struct : (s.var1 > 16);"); 56 | long startTime = System.currentTimeMillis(); 57 | Scanner scanner = new Scanner(q1); 58 | scanner.yylex(); 59 | 60 | rqlParser parser = new rqlParser(scanner); 61 | parser.parse(); 62 | 63 | List runners = StatementProcessor.processStatements( 64 | parser.getQueries(), 65 | "testapp", 66 | ignite 67 | ); 68 | 69 | int totalCuts = 0; 70 | for (Runner s: runners) { 71 | for (GlobalCut cut : s.getEmittedCuts()) { 72 | System.out.println(cut); 73 | } 74 | //System.out.println("out \n" + s.); 75 | totalCuts += s.getEmittedCuts().size(); 76 | 77 | long endEndTime = System.currentTimeMillis(); 78 | System.out.println("Query executed in: " + (endEndTime - startTime) + " ms for " + s.getEmittedCuts().size() + " cuts"); 79 | } 80 | 81 | assertTrue(totalCuts == LEN - 5); 82 | 83 | } 84 | } -------------------------------------------------------------------------------- /RQLServer/src/test/java/retroscope/rql/server/DistributedQuerySetStructTest.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import org.apache.ignite.Ignite; 4 | import org.apache.ignite.Ignition; 5 | import org.apache.ignite.configuration.IgniteConfiguration; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import retroscope.Retroscope; 10 | import retroscope.datamodel.datastruct.struct.RQLStruct; 11 | import retroscope.log.RetroscopeLog; 12 | import retroscope.rql.environment.GlobalCut; 13 | import retroscope.rql.parser.Scanner; 14 | import retroscope.rql.parser.rqlParser; 15 | 16 | import java.io.StringReader; 17 | import java.util.List; 18 | 19 | import static org.junit.Assert.assertTrue; 20 | 21 | public class DistributedQuerySetStructTest { 22 | 23 | private static final int LEN = 30; 24 | 25 | private Retroscope retroscope; 26 | private Ignite ignite; 27 | 28 | 29 | @Before 30 | public void setUp() throws Exception { 31 | 32 | IgniteConfiguration ic = new IgniteConfiguration(); 33 | //ic.setDataStreamerThreadPoolSize(1); 34 | ignite = Ignition.start(ic); 35 | retroscope = new Retroscope("testapp"); 36 | retroscope.connectIgnite(ignite); 37 | RetroscopeLog log = retroscope.getLog("testlog"); 38 | for (int i = 0; i < LEN; i++) { 39 | RQLStruct s = log.createStruct().addValue("var1", i*i).addValue("var2", i); 40 | log.addToSet("struct", s).commit(); 41 | } 42 | retroscope.flushStreams(); 43 | Thread.sleep(2000); 44 | } 45 | 46 | 47 | @After 48 | public void tearDown() throws Exception { 49 | ignite.close(); 50 | } 51 | 52 | 53 | @Test 54 | public void testSimpleDistributedQuery() throws Exception { 55 | StringReader q1 = new StringReader("SELECT struct FROM testlog WHEN EXISTS s IN Flatten(struct) : (s.var1 > 16);"); 56 | long startTime = System.currentTimeMillis(); 57 | Scanner scanner = new Scanner(q1); 58 | scanner.yylex(); 59 | 60 | rqlParser parser = new rqlParser(scanner); 61 | parser.parse(); 62 | 63 | List runners = StatementProcessor.processStatements( 64 | parser.getQueries(), 65 | "testapp", 66 | ignite 67 | ); 68 | 69 | int totalCuts = 0; 70 | for (Runner s: runners) { 71 | for (GlobalCut cut : s.getEmittedCuts()) { 72 | System.out.println(cut); 73 | } 74 | //System.out.println("out \n" + s.); 75 | totalCuts += s.getEmittedCuts().size(); 76 | 77 | long endEndTime = System.currentTimeMillis(); 78 | System.out.println("Query executed in: " + (endEndTime - startTime) + " ms for " + s.getEmittedCuts().size() + " cuts"); 79 | } 80 | 81 | assertTrue(totalCuts == LEN - 5); 82 | 83 | } 84 | } -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/environment/GlobalCut.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.environment; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import retroscope.datamodel.datastruct.variables.RQLVariable; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | 9 | public class GlobalCut implements Comparable { 10 | 11 | private ArrayList cutTimes; 12 | private String cut; 13 | 14 | public GlobalCut(long cutTime, String cut) { 15 | cutTimes = new ArrayList<>(); 16 | this.cutTimes.add(cutTime); 17 | this.cut = cut; 18 | } 19 | 20 | public void addCutTimes(Collection times) { 21 | cutTimes.addAll(times); 22 | } 23 | 24 | public void addCutTime(long time) { 25 | cutTimes.add(time); 26 | } 27 | 28 | public ArrayList getCutTimes() { 29 | return cutTimes; 30 | } 31 | 32 | public String getCut() { 33 | return cut; 34 | } 35 | 36 | public String toOneString() { 37 | StringBuilder sb = new StringBuilder(); 38 | 39 | if (cutTimes.size() > 0) { 40 | sb.append('<'); 41 | sb.append(cutTimes.get(0)); 42 | sb.append('>'); 43 | sb.append(':'); 44 | sb.append(cut); 45 | sb.append(System.lineSeparator()); 46 | } 47 | 48 | return sb.toString(); 49 | 50 | } 51 | 52 | public String toString() { 53 | StringBuilder sb = new StringBuilder(); 54 | 55 | for (long time: cutTimes) { 56 | sb.append('<'); 57 | sb.append(time); 58 | sb.append('>'); 59 | sb.append(':'); 60 | sb.append(cut); 61 | sb.append(System.lineSeparator()); 62 | } 63 | 64 | return sb.toString(); 65 | 66 | } 67 | 68 | /* 69 | * Equality is based on the value only and not on additional meta-data, such as name or nodeID 70 | */ 71 | public boolean equals(Object obj) { 72 | return obj != null 73 | && obj instanceof RQLVariable 74 | && cut.equals(((GlobalCut)obj).getCut()); 75 | } 76 | 77 | public int hashCode(){ 78 | return cut.hashCode(); 79 | } 80 | 81 | 82 | @Override 83 | public int compareTo(@NotNull GlobalCut o) { 84 | 85 | if (this.getCutTimes().size() > 0 && o.getCutTimes().size() > 0) { 86 | int c1 = this.cutTimes.get(this.getCutTimes().size() - 1).compareTo(o.getCutTimes().get(0)); 87 | if (c1 < 0) { 88 | return - 1; 89 | } else { 90 | int c2 = this.cutTimes.get(0).compareTo(o.getCutTimes().get(o.getCutTimes().size() - 1)); 91 | if (c2 > 0) { 92 | return 1; 93 | } 94 | } 95 | } 96 | return 0; 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/literals/Variable.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression.literals; 2 | 3 | import retroscope.datamodel.datastruct.Null; 4 | import retroscope.datamodel.datastruct.RQLSymbol; 5 | import retroscope.datamodel.datastruct.struct.RQLStruct; 6 | import retroscope.rql.environment.EnvironmentStack; 7 | import retroscope.rql.syntaxtree.expression.Expression; 8 | import retroscope.rql.syntaxtree.expression.IllegalExpressionException; 9 | 10 | import java.util.ArrayList; 11 | 12 | public class Variable extends Expression 13 | { 14 | private String name; 15 | private int id = -1; 16 | private Variable nested; 17 | 18 | RQLSymbol val; 19 | 20 | public Variable(String name) 21 | { 22 | this.name = name; 23 | } 24 | 25 | public Variable(String name, Variable nested) 26 | { 27 | this.name = name; 28 | this.nested = nested; 29 | } 30 | 31 | @Override 32 | public void setEnvironmentStack(EnvironmentStack stack) { 33 | super.setEnvironmentStack(stack); 34 | } 35 | 36 | public RQLSymbol getValue() { 37 | return this.value; 38 | } 39 | 40 | private RQLSymbol recursiveFind(RQLSymbol symb, Variable nestedVar) { 41 | if (nestedVar == null) { 42 | return symb; 43 | } 44 | if (symb instanceof RQLStruct) { 45 | return recursiveFind(((RQLStruct) symb).getElement(nestedVar.getName()), nestedVar.getNested()); 46 | } 47 | return new Null(); 48 | } 49 | 50 | public void evaluate() throws IllegalExpressionException { 51 | if (dirty) { 52 | retrieveValFromEnv(); 53 | if (nested == null) { 54 | this.value = val; 55 | } else { 56 | this.value = recursiveFind(val, nested); 57 | } 58 | } 59 | } 60 | 61 | private void retrieveValFromEnv() { 62 | val = getEnvironment().getSymbol(this.name); 63 | if (val == null) { 64 | val = new Null(); 65 | } 66 | } 67 | @Override 68 | public boolean computeDirty() { 69 | 70 | retrieveValFromEnv(); 71 | dirty = val.isDirty(); 72 | return dirty; 73 | } 74 | 75 | public String getName() { 76 | return name; 77 | } 78 | 79 | public Variable getNested() { 80 | return nested; 81 | } 82 | 83 | public Variable clone() { 84 | Variable nc = null; 85 | if (nested != null) { 86 | nc = nested.clone(); 87 | } 88 | Variable clone = new Variable(name, nc); 89 | clone.id = this.id; 90 | return clone; 91 | } 92 | 93 | @Override 94 | public ArrayList findVars() { 95 | ArrayList v = new ArrayList<>(); 96 | v.add(this); 97 | return v; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /retroscope.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /RetroLogServer/RetroLogServer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/java/retroscope/hlc/Timestamp.java: -------------------------------------------------------------------------------- 1 | package retroscope.hlc; 2 | 3 | /** 4 | * Created by aleksey on 10/15/16. 5 | * Timestamp is an HLC time with physical (wallTime) and logical components 6 | */ 7 | 8 | public class Timestamp implements Comparable, Cloneable { 9 | 10 | private long wallTime; 11 | private short logical; 12 | 13 | public Timestamp() { 14 | this(System.currentTimeMillis(), (short)0); 15 | } 16 | 17 | public Timestamp(long wallTime, short logical) { 18 | this.wallTime = wallTime; 19 | this.logical = logical; 20 | } 21 | 22 | 23 | /** 24 | * creates a timestamp from 64 bit representation of HLC 25 | * @param t - long representation of an HLC 26 | * @return Timestamp object that has been reconstructed from a 64 bit integer 27 | * 28 | */ 29 | public Timestamp(long t) 30 | { 31 | wallTime = t >> 16; 32 | logical = (short)(t & 0x00000000000000FFFFL); 33 | } 34 | 35 | public Timestamp clone() { 36 | return new Timestamp(this.wallTime, this.logical); 37 | } 38 | 39 | public Timestamp add(Timestamp t) { 40 | return new Timestamp(this.wallTime + t.wallTime, (short)(this.logical + t.logical)); 41 | } 42 | 43 | public Timestamp add(long wallTime, short logical) { 44 | return new Timestamp(this.wallTime + wallTime, (short)(this.logical + logical)); 45 | } 46 | 47 | 48 | public long getWallTime() { 49 | return wallTime; 50 | } 51 | 52 | public void setWallTime(long wallTime) { 53 | this.wallTime = wallTime; 54 | } 55 | 56 | public short getLogical() { 57 | return logical; 58 | } 59 | 60 | public void setLogical(short logical) { 61 | this.logical = logical; 62 | } 63 | 64 | public void incrementLogical() 65 | { 66 | this.logical++; 67 | } 68 | 69 | public void resetLogical() 70 | { 71 | this.logical = 0; 72 | } 73 | 74 | /** 75 | * toLong packs an HLC into a 64 bit integer 76 | * First 48 bits are for physical time 77 | * last 16 bits are for logical component 78 | */ 79 | public long toLong() 80 | { 81 | long longRepresentation = this.wallTime; 82 | longRepresentation = longRepresentation << 16; 83 | //longRepresentation = (longRepresentation & 0xFFFFFFFFFFFF0000L); 84 | longRepresentation = (longRepresentation | (long)this.logical); 85 | return longRepresentation; 86 | } 87 | 88 | public int compareTo(Timestamp o) { 89 | if (this.wallTime < o.wallTime 90 | || (this.wallTime == o.wallTime && this.logical < o.logical)) { 91 | return -1; 92 | } else if (this.wallTime > o.wallTime 93 | || (this.wallTime == o.wallTime && this.logical > o.logical)) { 94 | return 1; 95 | } 96 | return 0; 97 | } 98 | 99 | public String toString() 100 | { 101 | return this.wallTime + ", " + this.logical; 102 | } 103 | 104 | } 105 | 106 | -------------------------------------------------------------------------------- /RetrscopeExample/RetrscopeExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /RQLServer/RQLServer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /RQLBench/RQLBench.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /IgniteServer/IgniteServer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /RetroLogServer/src/main/protoc/protocol.proto: -------------------------------------------------------------------------------- 1 | // Please use protoc 2.6.1 to recompile 2 | // $ protoc -I=retroscope-library\src\main\protoc\ --java_out=retroscope-library\src\main\java\ retroscope-library\src\main\protoc\protocol.proto 3 | option java_package = "retroscope.net.protocol"; 4 | 5 | //Message from Retroscope Server 6 | message RetroServerMsg { 7 | optional int64 RID = 1; 8 | optional ConnectMsgResponse connectResponse = 2; 9 | optional GetLogNames logNamesRequest = 3; 10 | optional GetData dataRequest = 4; 11 | optional GetLog logSliceRequest = 5; 12 | optional DisconnectMsgResponse disconnectResponse = 6; 13 | optional int32 heartbeat = 7; 14 | optional TakeSnapshot snapshotRequest= 13; 15 | optional RollSnapshot rollSnapsotRequest = 14; 16 | optional int32 errorCode = 15; 17 | 18 | } 19 | 20 | message ConnectMsgResponse { 21 | required int32 retroscopeVersion = 1; 22 | required int32 nodeID = 2; 23 | } 24 | 25 | message DisconnectMsgResponse { 26 | required int32 nodeID = 1; 27 | } 28 | 29 | 30 | // Commands to Nodes 31 | message GetLogNames { 32 | 33 | } 34 | 35 | message GetData { 36 | required string logName = 1; 37 | optional int64 hlcTime = 2; 38 | repeated bytes keys = 3; 39 | } 40 | 41 | message GetLog { 42 | required string logName = 1; 43 | optional int64 HLCstartTime = 2; 44 | optional int64 HLCendTime = 3; 45 | repeated bytes parameterNames = 4; 46 | } 47 | 48 | message TakeSnapshot { 49 | required string logName = 1; 50 | } 51 | 52 | message RollSnapshot { 53 | required string logName = 1; 54 | required int64 hlcTime = 2; 55 | } 56 | // message from Retroscope Node 57 | message RetroNodeMsg { 58 | optional int64 RID = 1; 59 | optional ConnectMsg connectMsg = 2; 60 | optional DataMap data = 3; 61 | repeated LogMeta logs = 4; 62 | optional Log log = 5; 63 | optional DisconnectMsg disconnectMsg = 6; 64 | optional int32 hearbeatResponse = 7; 65 | optional int32 snapshotId = 10; 66 | 67 | optional int32 nodeId = 14; 68 | optional int32 errorCode = 15; 69 | 70 | } 71 | 72 | message ConnectMsg { 73 | required int32 retroscopeVersion = 1; 74 | optional int32 nodeId = 2; 75 | } 76 | 77 | message DisconnectMsg { 78 | required int32 nodeId = 1; 79 | } 80 | 81 | // DataMap messages 82 | message DataMap { 83 | required string name = 1; 84 | repeated DataItem items = 2; 85 | required int64 hlcTime = 3; 86 | } 87 | 88 | message DataItem { 89 | required bytes key = 1; 90 | optional bytes value = 2; // values can be null 91 | optional int64 hlcTime = 3; // values can be null 92 | } 93 | 94 | //Log Messages 95 | message Log { 96 | required string name = 1; 97 | required int64 maxLengthMillis = 2; 98 | required int64 logCheckpointIntervalMillis = 3; 99 | repeated LogItem items = 4; 100 | optional DataMap dataMap = 5; 101 | } 102 | 103 | message LogItem { 104 | required bytes key = 1; 105 | required int64 hlcTime = 2; 106 | optional bytes valueFrom = 3; // values can be null 107 | optional bytes valueTo = 4; // values can be null 108 | } 109 | 110 | message LogMeta { 111 | required string logName = 1; 112 | required int64 logStart = 2; 113 | required bool isDataMapLog = 3; 114 | } -------------------------------------------------------------------------------- /RetroAppViewer/RetroAppViewer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /RQLServer/src/main/java/retroscope/rql/syntaxtree/expression/FuncCall.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.syntaxtree.expression; 2 | 3 | import retroscope.datamodel.datastruct.RQLSymbol; 4 | import retroscope.rql.environment.EnvironmentStack; 5 | import retroscope.rql.errors.RQLRunTimeException; 6 | import retroscope.rql.functions.RQLBuiltInFunction; 7 | import retroscope.rql.syntaxtree.expression.assign.AssignExpression; 8 | import retroscope.rql.syntaxtree.expression.assign.DeclareExpression; 9 | import retroscope.rql.syntaxtree.expression.literals.Variable; 10 | 11 | import java.lang.reflect.Constructor; 12 | import java.lang.reflect.InvocationTargetException; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by Aleksey on 12/20/2016. 17 | * 18 | */ 19 | public class FuncCall extends Expression { 20 | 21 | private ExpressionList params; 22 | private String name; 23 | private RQLBuiltInFunction thisFunc; 24 | 25 | public FuncCall(String name, ExpressionList params) 26 | { 27 | this.params = params; 28 | this.name = name; 29 | findFunc(); 30 | } 31 | 32 | private void findFunc() { 33 | //reflection to invoke built-in flat functions. These functions are not placed on the stack and instead 34 | //simply produce the results in the current environment 35 | 36 | try { 37 | Class clazz = Class.forName("retroscope.rql.functions." + name); 38 | Constructor constructor = clazz.getConstructor(ExpressionList.class, EnvironmentStack.class); 39 | Object func = constructor.newInstance(params, stack); 40 | if (func instanceof RQLBuiltInFunction) { 41 | thisFunc = (RQLBuiltInFunction) func; 42 | } 43 | } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { 44 | //getEnvironment().addRunTimeException(new RQLRunTimeException("No function " + name + " is defined")); 45 | e.printStackTrace(); 46 | } 47 | } 48 | 49 | public RQLSymbol getValue() { 50 | return thisFunc.getValue(); 51 | } 52 | 53 | 54 | public void evaluate() throws IllegalExpressionException { 55 | /* 56 | Here we evaluate the function. 57 | First we need to find the function in the list of registered functions for current Environment 58 | Second we check if parameters needed to function match what we have 59 | Third, we execute the function (built it function for RQL only at this time) 60 | */ 61 | 62 | thisFunc.evaluate(); 63 | } 64 | 65 | public void setEnvironmentStack(EnvironmentStack stack) { 66 | this.stack = stack; 67 | thisFunc.setEnvironmentStack(stack); 68 | 69 | } 70 | 71 | public FuncCall clone() { 72 | ExpressionList clonedParams = params.clone(); 73 | return new FuncCall(name, clonedParams); 74 | } 75 | 76 | @Override 77 | public boolean computeDirty() { 78 | dirty = false; 79 | for (Expression ex1: params.getList()) { 80 | if (ex1.computeDirty()) { 81 | dirty = true; 82 | } 83 | } 84 | return dirty; 85 | } 86 | 87 | @Override 88 | public ArrayList findVars() { 89 | ArrayList v = new ArrayList<>(); 90 | for (Expression ex1: params.getList()) { 91 | v.addAll(ex1.findVars()); 92 | } 93 | return v; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.retroscope 8 | retroscope-lib 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 1.8 14 | ${java.version} 15 | ${java.version} 16 | 17 | 18 | 19 | 20 | RetroLogServer 21 | RetroAppViewer 22 | IgniteServer 23 | RQLServer 24 | RetrscopeExample 25 | RQLBench 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | log4j 35 | log4j 36 | 1.2.16 37 | 38 | 39 | 40 | 41 | 42 | org.apache.ignite 43 | ignite-core 44 | 2.0.0 45 | 46 | 53 | 54 | 55 | 56 | junit 57 | junit 58 | 4.11 59 | 60 | 61 | 62 | org.apache.ignite 63 | ignite-spring 64 | 2.0.0 65 | 66 | 67 | 68 | org.apache.ignite 69 | ignite-indexing 70 | 2.0.0 71 | 72 | 73 | 74 | 75 | io.netty 76 | netty-all 77 | 4.1.5.Final 78 | 79 | 80 | 81 | 82 | com.google.protobuf 83 | protobuf-java 84 | 2.6.1 85 | 86 | 87 | 88 | 89 | commons-codec 90 | commons-codec 91 | 1.9 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /RQLServer/src/test/java/retroscope/rql/server/LocalQueryRunnerStringsTest.java: -------------------------------------------------------------------------------- 1 | package retroscope.rql.server; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import retroscope.datamodel.datastruct.variables.StringRQLVariable; 6 | import retroscope.hlc.Timestamp; 7 | import retroscope.net.ignite.EventStreamEntry; 8 | import retroscope.rql.environment.GlobalCut; 9 | import retroscope.rql.log.RQLStateSequence; 10 | import retroscope.rql.parser.Scanner; 11 | import retroscope.rql.parser.rqlParser; 12 | import retroscope.rql.syntaxtree.Query; 13 | 14 | import java.io.StringReader; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | 18 | public class LocalQueryRunnerStringsTest { 19 | 20 | private RQLStateSequence stateSequence; 21 | private static final int SEQ_LEN = 150; 22 | 23 | @Before 24 | public void setUp() throws Exception { 25 | Timestamp t = new Timestamp(); 26 | stateSequence = new RQLStateSequence(t); 27 | 28 | for (int i = 0; i < SEQ_LEN; i++) { 29 | t = t.add(1, (short) 0); 30 | StringRQLVariable v = new StringRQLVariable("a", "\"val_"+(i*i)+"\""); 31 | String var = ":" + v.toRQLString(); 32 | EventStreamEntry entry = new EventStreamEntry(t.toLong(), var); 33 | stateSequence.appendItem(entry); 34 | 35 | v = new StringRQLVariable("a", "\"val_"+(i+i)+"\""); 36 | var = ":" + v.toRQLString(); 37 | entry = new EventStreamEntry(t.toLong(), var); 38 | stateSequence.appendItem(entry); 39 | } 40 | } 41 | 42 | @Test 43 | public void testSimpleQueryCard() throws Exception { 44 | StringReader q1 = new StringReader("SELECT a FROM testlog WHEN Cardinality(a) > 1;"); 45 | Scanner scanner = new Scanner(q1); 46 | scanner.yylex(); 47 | 48 | rqlParser rql = new rqlParser(scanner); 49 | rql.parse(); 50 | LocalQueryRunner qr = new LocalQueryRunner((Query) rql.getQueries().get(0), stateSequence); 51 | qr.execute(); 52 | System.out.println(qr.getEmittedCuts().size()); 53 | 54 | for (GlobalCut cut: qr.getEmittedCuts()) { 55 | System.out.println(cut.toOneString()); 56 | } 57 | 58 | assertTrue(qr.getEmittedCuts().size() + 2 == SEQ_LEN); 59 | } 60 | 61 | 62 | @Test 63 | public void testSimpleQueryExists() throws Exception { 64 | StringReader q1 = new StringReader("SELECT a FROM testlog WHEN EXISTS aa IN a : (aa = \"val_16\");"); 65 | Scanner scanner = new Scanner(q1); 66 | scanner.yylex(); 67 | 68 | rqlParser rql = new rqlParser(scanner); 69 | rql.parse(); 70 | LocalQueryRunner qr = new LocalQueryRunner((Query) rql.getQueries().get(0), stateSequence); 71 | qr.execute(); 72 | System.out.println(qr.getEmittedCuts().size()); 73 | assertTrue(qr.getEmittedCuts().size() == 2); 74 | } 75 | 76 | 77 | @Test 78 | public void testSimpleQueryForAll() throws Exception { 79 | StringReader q1 = new StringReader("SELECT a FROM testlog WHEN FORALL aa IN a : (aa = \"val_4\");"); 80 | Scanner scanner = new Scanner(q1); 81 | scanner.yylex(); 82 | 83 | rqlParser rql = new rqlParser(scanner); 84 | rql.parse(); 85 | LocalQueryRunner qr = new LocalQueryRunner((Query) rql.getQueries().get(0), stateSequence); 86 | qr.execute(); 87 | System.out.println(qr.getEmittedCuts().size()); 88 | assertTrue(qr.getEmittedCuts().size() == 1); 89 | } 90 | 91 | } --------------------------------------------------------------------------------