Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error message when users enter old style syntax for query #3397

Merged
merged 16 commits into from
Sep 24, 2019

Conversation

big-andy-coates
Copy link
Contributor

Description

Say a user executes SELECT * FROM X JOIN Y ON X.ID = Y.ID; or similar. In older versions of KSQL this would be a streaming join and would work. With the introduction of static queries this example is now a static query, which don't support joins. Hence the user will get the error: Static queries do not support joins... which isn't very helpful if you don't know the query syntax has changed. With this PR the output is now:

Static queries do not support joins. Did you mean to execute a continuous query? Add an 'EMIT CHANGES' clause to do so.

Query syntax in KSQL has changed. There are now two broad categories of queries:
- Static queries: query the current state of the system, return a result and terminate.
- Streaming queries: query the state of the system in motion and will continue to output results until they meet any LIMIT clause criteria or are terminated by the user.

'EMIT CHANGES' is used to indicate a query is continuous and outputs all changes. To turn a static query into a streaming query, as was the default in older versions of KSQL, add `EMIT CHANGES` to the end of the statement before any limit clause.

For example, the following are static queries:
	'SELECT * FROM X WHERE ROWKEY=Y;' (non-windowed table)
	'SELECT * FROM X WHERE ROWKEY=Y AND WINDOWSTART>=Z;' (windowed table)

and, the following is a streaming query:
	'SELECT * FROM X EMIT CHANGES;'

Note: Persistent queries, e.g. `CREATE TABLE AS ...`, currently have an implicit `EMIT CHANGES`. However, it is recommended to add `EMIT CHANGES` to such statements going forward, as a this will be required in a future release.

Testing done

usual

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

Say a user executes `SELECT * FROM X JOIN Y ON X.ID = Y.ID;` or similar. In older versions of KSQL this would be a streaming join and would work. With the introduction of static queries this example is now a static query, which don't support joins. Hence the user will get the error: `Static queries do not support joins`... which isn't very helpful if you don't know the query syntax has changed. With this PR the output is now:

```
Static queries do not support joins.
Did you mean to execute a continuous query? If so, add an 'EMIT CHANGES' clause.
Query syntax in KSQL has changed. There are now two broad categories of queries:
- Static queries: query the current state of the system, return a result and terminate.
- Streaming queries: query the state of the system in motion and will continue to
output results until they meet any LIMIT clause criteria or are terminated by the user.

'EMIT CHANGES' is used to indicate a query is continuous and outputs all changes.
To turn a static query into a streaming query, as was the default in older versions
of KSQL, add `EMIT CHANGES` to the end of the statement before any limit clause.

For example, the following are static queries:
    'SELECT * FROM X WHERE ROWKEY=Y;' (non-windowed table)
    'SELECT * FROM X WHERE ROWKEY=Y AND WINDOWSTART>=Z;' (windowed table)
and, the following is a streaming query:
    'SELECT * FROM X EMIT CHANGES;'

Note: Persistent queries, e.g. `CREATE TABLE AS ...`, currently have an implicit
`EMIT CHANGES`. However, it is recommended to add `EMIT CHANGES` to such statements
going forward, as a this will be required in a future release.
```
@big-andy-coates big-andy-coates requested a review from a team as a code owner September 23, 2019 11:39
@big-andy-coates
Copy link
Contributor Author

@JimGalasyn, fancy correctly my terrible english in the above message? :D

Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @big-andy-coates -- this is great!

@vcrfxia vcrfxia requested a review from a team September 23, 2019 14:17
Copy link
Member

@JimGalasyn JimGalasyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a few suggestions.

big-andy-coates and others added 11 commits September 23, 2019 18:35
# Conflicts:
#	ksql-engine/src/main/java/io/confluent/ksql/analyzer/StaticQueryValidator.java
@big-andy-coates big-andy-coates merged commit f948ec0 into confluentinc:master Sep 24, 2019
@big-andy-coates big-andy-coates deleted the static_help branch September 24, 2019 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants