Skip to content

TsqlRfc

MichaelGoodman edited this page Oct 6, 2018 · 4 revisions

TSQL: Test Suite Query Language

TSQL is a query language for selecting data from [incr tsdb()] test suites partially described in TSNLP User Manual (Volume 2).

TSQL Syntax

   1 Query        := ( Info | Set | Retrieve | Insert ) ( '.' | $ )
   2 Info         := 'info' ( 'all' | 'relations' | Relation | TsdbConstant | TsdbVariable )
   3 Set          := 'set' TsdbVariable ( Integer | String | ':on' | ':off' )
   4 Retrieve     := ( 'retrieve' | 'select' ) SelectBody
   5 SelectBody   := ( Attribute+ | '*' )
   6                 [ 'from' Relation+ ]
   7                 [ 'where' Disjunction ]
   8                 [ 'report' FormatString ]
   9 Insert       := 'insert' 'into' Relation [ Attribute+ ]
  10                          'values' ( Integer | String | DateTime )+
  11 
  12 TsdbConstant := 'home'
  13               | 'tsdb_home'
  14               | 'relations-file'
  15               | 'tsdb_relations_file'
  16               | 'data-path'
  17               | 'tsdb_data_path'
  18 TsdbVariable := 'result-path'
  19               | 'tsdb_result_path'
  20               | 'result-prefix'
  21               | 'tsdb_result_prefix'
  22               | 'max-results'
  23               | 'tsdb_max_results'
  24               | 'uniquely-project'
  25               | 'tsdb_uniquely_project'
  26 
  27 Relation     := Identifier
  28 Attribute    := Identifier
  29 
  30 Disjunction  := Conjunction ( '|' | '||' | 'or'  Conjunction )*
  31 Conjunction  := Condition ( '&' | '&&' | 'and' Condition)*
  32 Condition    := Attribute ( '=' | '==' | '!=' | '~' | '!~' ) String
  33               | Attribute ( '=' | '==' | '!=' | '<' | '>' | '<=' | '>=' ) ( Integer | DateTime )
  34               | ( '!' | 'not' ) Condition
  35               | '(' Disjunction ')'
  36 
  37 FormatString := String
  38 
  39 Integer      := /[+-]?[0-9]+/
  40 Digit        := /[0-9]+]
  41 
  42 String       := /"([^"\\]|\\.)*"/"
  43               | /'([^'\\]|\\.)*'/
  44 
  45 DateTime     := Date [ ( Time | '(' Time ')' ) ]
  46               | [ ':' ] 'today'
  47               | [ ':' ] 'now'
  48 Date         := FullYear Month [ '-' Day ]
  49               | [ Day '-' ] Month '-' Year
  50 FullYear     := Digit Digit Digit Digit
  51 Year         := [ Digit Digit ] Digit Digit
  52 Month        := [ Digit ] Digit
  53               | MonthName
  54 MonthName    := 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun'
  55               | 'jul' | 'aug' | 'sep' | 'oct' | 'nov' | 'dec'
  56 Day          := [ Digit ] Digit
  57 Time         := Digit Digit ':' Digit Digit [ ':' Digit Digit ]
  58 
  59 Identifier   := Character ( Character | Digit | '-' | '_' )+
  60 Character    := /[a-zA-Z]+/

Notes on the syntax

Different publications and implementations have some differences in the syntax. I (MichaelGoodman) attempt to catalogue some of those differences here, excepting obvious bugs in the BNFs, as well as general

  • Some literals in the syntax (e.g., select, info, or from) are case-insensitive, but relation (table) names, attributes (column names), and some other literals (e.g., all, relations, tsdb_home, etc.) are case-sensitive

  • The TSNLP version of TSQL does not describe YYYY-MM-DD dates

  • The TSNLP version does not describe MonthName forms (although it appears to accept them); note that MonthName may be locale-dependent

  • FormatString does not appear to be defined or even described anywhere. From my experiments, it seems to be a printf string with format specifiers (%s, %d, or %i) used to insert column values (though it does not appear to matter which is used; e.g., %d could be used for a :string value, etc.). For instance, a query like select i-id i-input i-date could use up to three format specifiers (any more may trigger an error), such as ID=%s,Input=%s,Date=%s. If fewer than three format specifiers are used, the remaining data is output in [incr tsdb()] table format.

Clone this wiki locally