Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What Reika Taught us

197 views

Published on

Lessons learned from building a DSL for time series database

Published in: Software
  • Be the first to comment

  • Be the first to like this

What Reika Taught us

  1. 1. What Reika Taught us Lessons learned from building Reika, a DSL for TSDB Pinglei Guo & Chujiao Hou
  2. 2. Agenda ● What is Reika ● What is Time Series and Time Series Database (03/21 if interested CMPS 278) ● Design Goal ● Staging achievements ● Implementation detail ● Lessons learned ● Acknowledgement
  3. 3. What is Reika - General language + Query language - Built in function for running SQL like query on various Time Series Databases - Depend on TSDB-Proxy for execution
  4. 4. Design Goal - SQL like syntax - Support various backend
  5. 5. Staging achievement - Only the general programming language part is implemented - written in Java (1500 + 1000 (generated by ANTLR) ) - REPL - Editor support (vscode)
  6. 6. REPL (Read Eval Print Loop)
  7. 7. VS Code Editor Plugin
  8. 8. Implementation Detail - Lexer and Parser using ANTLR4 (ANother Tool for Language Recognition) - Build AST from parse tree with symbol and type checking - Static typing - Interpreter & Shell in Java
  9. 9. ANTLR Grammar prog : stat+ ; type : 'int' | 'double' | 'bool' | 'string' | 'date'; varDeclare : type ID '=' expr ';'; varAssign : ID '=' expr ';'; stat : varDeclare | varAssign | expr ';' ; ● http://www.antlr.org/ ● From a grammar, ANTLR generates a parser that can build and walk parse trees Grammar: Program & Statements
  10. 10. ANTLR Grammar expr : INT | DOUBLE | BOOL | STRING | ID '(' exprList? ')' | ID | expr MULT expr | expr DIV expr | expr ADD expr | expr MINUS expr | expr AND expr | expr OR expr ; exprList : expr (',' expr)* ; Grammar: expression & expression list
  11. 11. ANTLR Grammar INT : [0-9]+ ; DOUBLE: [0-9]+ '.' [0-9]+ ; BOOL : 'true' | 'false' ; STRING: '"' (ESC|.)*? '"'; ESC : '"' | '' ; ID : LETTER (LETTER | [0-9])* ; LETTER : [a-zA-Z] ; ADD : '+'; MINUS: '-'; MULT: '*'; DIV: '/'; AND : '&&'; OR : '||' ; Grammar: Token
  12. 12. WS : [ tnr]+ -> channel(HIDDEN) ; COMMENT : '/*' .*? '*/' -> channel(HIDDEN) ; SL_COMMENT : '//' .*? 'n' -> channel(HIDDEN); ANTLR Grammar Grammar: Token (ignored)
  13. 13. Symbol Checking ● Undefined variable x = 1; ● Duplicate definition int x = 1; double x = 2.0; ● 1 is int -> x is int (type inference) int x = 1; ● Replace the old one with new one in symbol table double x = 2.0; Error Recovery Recovery != Recovered AST node should be passed to next step ( interpreter etc.)
  14. 14. Type Checking Error Recovery ● Incompatible assign string chinaMobile = 10086; ● incompatible type "elder" + 1; ● unsupported operation "elder" - "1s"; ● Use lhs type string chinaMobile = “” ● Use Any Type ● Use Any Type
  15. 15. Symbol & Type checking example
  16. 16. You often don't really understand the problem until after the first time you implement a solution - The Cathedral and the Bazaar Lessons
  17. 17. Lessons Check the library's source before you use it When shit things happen, they happen recursively
  18. 18. ANTLR Golang runtime It’s Run Time
  19. 19. The original Reika repository, written in Golang
  20. 20. Related work ● InfluxQL & Tick Script ● HeroicQL ● Juttle ● SparkQL ● LINQ
  21. 21. Acknowledgement ● Zheyuan Chen & Prof. Alvaro in CMPS 232
  22. 22. Thank You! Source code: https://github.com/xephonhq/tsdb-proxy-java Authors: Pinglei Guo piguo@ucsc.edu Chujiao Hou chou8@ucsc.edu

×