Lexical Elements
rekuiper SQL queries consist of comments, tokens, operators, and literals.
Comments
Comments document query statements. Block comments start with /* and end with */.
Tokens
rekuiper SQL decomposes input text into four token categories:
- Identifiers
- Keywords
- Operators
- Literals
Whitespace characters (spaces, horizontal tabs, carriage returns, and newlines) separate adjacent tokens and are ignored during parsing. The lexical analyzer selects the longest matching sequence of characters to construct each token.
Identifiers
Identifiers name database entities such as streams, tables, and columns. A standard identifier begins with a letter followed by letters or digits.
Enclose reserved keywords, special characters (such as hyphens and spaces), or multilingual Unicode strings in backticks (`):
SELECT `select`, `and` FROM demo;
SELECT `a-b`, `hello world`, `中文Chinese` FROM demo;Keywords
The following reserved keywords require backticks when used as entity names in SQL statements:
SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR, CASE, WHEN, UNTIL, THEN, ELSE, END, IN, NOT, BETWEEN, LIKE, OVER, PARTITIONExample querying a field named from:
SELECT * FROM demo1 WHERE `from` = "device1"Example defining a stream named stream with Unicode columns:
CREATE STREAM `stream` (
USERID BIGINT,
FIRST_NAME STRING,
LAST_NAME STRING,
NICKNAMES ARRAY(STRING),
Gender BOOLEAN,
`地址` STRUCT(STREET_NAME STRING, NUMBER BIGINT)
) WITH (DATASOURCE = "users", FORMAT = "JSON");Operators
rekuiper supports the following arithmetic, logical, comparison, and access operators:
+, -, *, /, %, &, |, ^, =, !=, <, <=, >, >=, [], ->, (), IN, NOT IN, BETWEEN, NOT BETWEENLiterals
Boolean Literals
TRUE, FALSEExample query:
SELECT TRUE AS field1 FROM demoThe output field field1 always returns true.
Time Unit Literals
The following literals specify time durations in window specifications:
DD: DaysHH: HoursMI: MinutesSS: SecondsMS: Milliseconds
String Literals
Enclose string literals in single quotes or double quotes:
"user", 'user'When passing rules through shell command lines, nested single quotes can cause premature argument termination:
bin/kuiper create rule myrule '{"sql": "SELECT lower('abc') FROM demo"}'In this command, the shell evaluates 'abc' as a variable reference. Use escaped double quotes within single-quoted command payloads to preserve string literals:
bin/kuiper create rule myrule '{"sql": "SELECT lower(\"abc\") FROM demo"}'