Kuiper lexical elements

Comments

Comment serve as documentation. Comments begin with the character sequence /* and stop at the pair */.

Tokens

Kuiper SQL is built up from tokens. There are four classes of tokens:

  • identifiers
  • keywords
  • operators
  • literals

White space formed from spaces, horizontal tabs, carriage returns, and newlines is ignored except as it separates tokens that would otherwise combine into a single token. While breaking the input into tokens, the next token is the longest sequence of characters that form a valid token.

Identifiers

Identifiers name entities within a program. An identifier is a sequence of one or more letters and digits. An identifier must start with a letter.

To use the reserved words as the column name and the stream name etc, they need to be quoted by backtick. You can also use all kinds of unicode string in the backtick as an SQL element. For example, operator -, spaces, and various language characters such as Chinese.

  1. SELECT `select`, `and` from demo
  2. SELECT `a-b`, `hello world`, `中文Chinese` from demo

Keywords

Reserved keywords for rule SQL: If you’d like to use the following keyword in rule SQL, you will have to use backtick to enclose them.

  1. SELECT, FROM, JOIN, LEFT, INNER, ON, WHERE, GROUP, ORDER, HAVING, BY, ASC, DESC, AND, OR, CASE, WHEN, THEN, ELSE, END

The following is an example for using a stream named from, which is a reserved keyword in Kuiper.

  1. SELECT * FROM demo1 where `from`="device1"

Reserved keywords for streams management: If you’d like to use the following keywords in stream management command, you will have to use backtick to enclose them.

  1. CREATE, RROP, EXPLAIN, DESCRIBE, SHOW, STREAM, STREAMS, WITH, BIGINT, FLOAT, STRING, DATETIME, BOOLEAN, ARRAY, STRUCT, DATASOURCE, KEY, FORMAT,CONF_KEY, TYPE, STRICT_VALIDATION, TIMESTAMP, TIMESTAMP_FORMAT

The following is an example for how to use reserved keywords in stream creation statement.

  1. CREATE STREAM `stream` (
  2. USERID BIGINT,
  3. FIRST_NAME STRING,
  4. LAST_NAME STRING,
  5. NICKNAMES ARRAY(STRING),
  6. Gender BOOLEAN,
  7. `地址` STRUCT(STREET_NAME STRING, NUMBER BIGINT),
  8. ) WITH (DATASOURCE="users", FORMAT="JSON");

Operators

Following operators are provided.

  1. +, -, *, /, %, &, |, ^, =, !=, <, <=, >, >=, [], ->, ()

Literals

Boolean literals

  1. TRUE, FALSE

Example, SELECT TRUE AS field1 FROM demo , the field field1 always returns true.

Time literals: Below literals are used in time window, which identify the time unit for windows.

  1. DD, HH, MI, SS, MS