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

Move statement re-write logic into engine #3400

Merged

Conversation

big-andy-coates
Copy link
Contributor

@big-andy-coates big-andy-coates commented Sep 23, 2019

Description

We have to statement re-writers. These currently reside in the parser, but more correctly belong in the engine.

First, we have StatementRewriteForStruct, which searches out and replaces any DereferencedExpression with a special UDF for accessing fields in structs.
Previously, this re-write happened in the parser. This PR sees this logic move into the engine. After all, it's an implementation of the engine that we handle struct field access via a UDF.

Second, we have StatementRewriteForRowtime which looks to allow comparisons between rowtime and strings, given we don't have a datatime type yet.
This is already only used in the engine. So moving the type itself to the engine seems sensible.

While moving, the API to these types was cleaned up. The if(statement needs rewrite) check has been moved inside the re-write class and the class has been refactored to make it more suitable for dependency injection.

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 #")

KSQL uses a statement rewritter to convert STRUCT field dereferences into `FETCH_FIELD_FROM_STRUCT` function calls.  The rewrite is done for `Query`, `C*AS` and `INSERT INTO` statements, but was missing `EXPLAIN`.

It is valid to execute `EXPLAIN` on a query string, e.g.  `EXPLAIN SELECT address->street FROM Y;`.  It is therefore important that the query within the `EXPLAIN` statement has the same rewrites applied to it as would be applied should the statement be executed directly.
We have to statement re-writers. These currently reside in the parser, but more correctly belong in the engine.

First, we have `StatementRewriteForStruct`, which searches out and replaces any `DereferencedExpression` with a special UDF for accessing fields in structs.
Previously, this re-write happened in the parser. This PR sees this logic move into the engine. After all, it's an implementation of the engine that we handle struct field access via a UDF.

Second, we have `StatementRewriteForRowtime` which looks to allow comparisons between rowtime and strings, given we don't have a datatime type yet.
This is already only used in the engine. So moving the type itself to the engine seems sensible.

While moving, the API to these types was cleaned up. The `if(statement needs rewrite)` check has been moved inside the re-write class and the class has been refactored to make it more suitable for dependency injection.
@big-andy-coates big-andy-coates requested a review from a team as a code owner September 23, 2019 14:35
# Conflicts:
#	ksql-engine/src/main/java/io/confluent/ksql/engine/rewrite/StatementRewriteForStruct.java
#	ksql-engine/src/main/java/io/confluent/ksql/engine/rewrite/StatementRewriter.java
#	ksql-parser/src/test/java/io/confluent/ksql/parser/rewrite/StatementRewriteForStructTest.java
Copy link
Contributor

@rodesai rodesai left a comment

Choose a reason for hiding this comment

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

Code LGTM. One suggestion inline.

@big-andy-coates big-andy-coates merged commit 078e114 into confluentinc:master Sep 24, 2019
@big-andy-coates big-andy-coates deleted the rewrites_to_engine branch September 24, 2019 07:42
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.

2 participants