CQL Query Syntax and Semantics Checks ------------------------------------ The CQL syntax is given first. The semantic checks done by the plan generator are given after the syntax specification. ::= 'SELECT' 'FROM' | '(' ')' ::= | '*' ::= ',' | ::= '.' | ::= ',' | ::= 'AS' | | ::= '(' '.' ')' | '(' ')' ::= ',' | | ::= | | | ::= 'BY' '[' ']' | '[' ']' ::= 'RANGE' | 'ROWS' | 'NOW' ::= | | | ::= 'WHERE' | ::= 'GROUP' 'BY' | ::= 'DISTINCT' | ::= 'ISTREAM' | 'DSTREAM' | 'RSTREAM' ::= 'AND' | ::= ::= | ::= ',' | ::= | | ::= | ::= '<' | '<=' | '>' | '>=' | '=' | '<>' ::= 'AVG' | 'MIN' | 'MAX' | 'COUNT' | 'SUM' ::= 'UNION' | 'ANTISEMIJOIN' ::= '+' | '-' | '*' | '/' ::= 'AND' | ::= | '(' ')' ::= '+' | '-' | '*' | '/' | '(' ')' | | ::= '"' '"' ::= { | | | } ::= 'SECOND' | 'SECONDS' ::= 'MINUTE' | 'MINUTES' ::= 'HOUR' | 'HOURS' ::= 'DAY' | 'DAYS' ::= { } ::= { } {'.'} { } ::= CQL Semantics Checks -------------------- (1) CQL reserved words (e.g., select, where) are case insensitive. (2) All identifiers including attribute and stream names must start with a letter and can be followed by any letter, digit, or "_" (the underscore character). (3) Predicates in the "WHERE" clause of a CQL query must have one the following forms: (a) Attribute operator Attribute. E.g., A > B, R.A = B, R.A <> S.B (<> is "not equal to"). The attributes must be of the same type. (b) Attribute operator ConstantValue. E.g., A = 10, R.A = "stanford". Constant values can appear only in the RHS of the predicate. The constant value must be of the same type as the attribute. (4) String constants used in "WHERE" clause predicates must be surrounded by double quotes ("). E.g., R.name = "stanford". Single quotes are incorrect here. E.g., R.name = 'stanford' will throw a parse error because the string constant is surrounded by single quotes (') and not double quotes ("). (5) COUNT(*) is not supported. You have to specify COUNT(AttributeName). (6) Windows are allowed over streams only. (7) We currently do not allow streams to be joined unless they each have an explicit window specified over them. This rule also applies to streams that are CQL Views. (8) Terms in the "SELECT" clause must have one of following forms: (a) An attribute. E.g., A, or * as in "SELECT *". (b) An aggregated attribute. E.g., AVG(R.A), COUNT(B). (c) An arithmetic expression of the form: (1) Attribute ArithOp Attribute AS ProjectedTermName. E.g., R.A + S.B AS foo, A / S.B AS bar. The attributes must be of the same type and the same as the output type in case the output is fed into a CQL View. (2) Attribute ArithOp ConstValue AS ProjectedTermName. E.g., A + 10 AS B. The constant value must be of the same type as the attribute and the same as the output type in case the output is fed into a CQL View. (9) User-defined functions are not supported. (10) Subqueries are not supported. CQL queries which need subqueries should be written using CQL Views. (11) Group By and Aggregation queries: (a) Queries having a a Group By list G, must have a select clause of the form: select G, followed by attributes with aggregation. (b) We require that there be at least one attribute that is aggregated in a Group By query. The DISTINCT clause can be used for duplicate elimination. (c) We do not support project expressions (e.g., R.A * 10) alongside aggregation in Group By and Aggregation queries. (d) Aggregation is not allowed on string attributes. (12) CQL Views: (a) Note that registering a CQL view is a two-step process. The view must be registered first as a stream or a relation as the case may be. If the view is a derived stream, then use the same steps as in the case of registering an input stream. Similarly, if the view is a derived relation, then use the same steps as in the case of registering a relation. The second step consists of registering the CQL query which generates the view. The semantic checks applied to this step are given next. (b) If the query is a CQL View then its return type and schema must match the type and schema of the registered CQL View. This also includes length checks on string attributes since we support fixed length strings only. (c) It is a semantic error if no relation-to-stream converter is specified for a stream CQL View. Similarly, it is a semantic error if a relation-to-stream converter is specified for a relation CQL View. (13) CQL Queries with Bag Operations (e.g., UNION, ANTISEMIJOIN): (a) The FROM clause must be , where must be UNION or ANTISEMIJOIN. (d) Both operands have to be declared relations or CQL Views that are relations. E.g., they cannot be windowed streams. (e) Both operands must have the same schema in terms of attribute types and lengths. Attribute names can differ. (f) The projected attributes in the SELECT clause must all belong to the first relation specified in the FROM clause. (g) Aggregation or complex projection is not allowed in the SELECT clause.