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

Preserve '*' when formatting a 'SELECT *' statement #2473

Merged
merged 2 commits into from
Feb 22, 2019

Conversation

agavra
Copy link
Contributor

@agavra agavra commented Feb 21, 2019

Description

Consider stream X with fields A and B. Previously, the following semantics would hold:

// Statement statement = resolve("SELECT * FROM X");
print(SqlFormatter.formatSql(statement));
> SELECT X.ROWTIME "ROWTIME", X.ROWKEY "ROWKEY", X.A "A", X.B "B" FROM X X;

The new behavior replaces all of the select items that came from a * with *, for example:

// Statement statement = resolve("SELECT *, A AS ONE FROM X");
print(SqlFormatter.formatSql(statement));
> SELECT *, X.A "ONE" FROM X X;

Motivation

In order to support #2436, we need to make sure that SELECT * statements do not expand to include ROWKEY/ROWTIME. Fixing the root cause of this behavior is tricky and perhaps backwards incompatible (see discussion #2436 (comment)), so in the meantime I propose the behavior in this PR, which I think is good independent of that PR.

Testing done

New unit tests.

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

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.

LGTM. One semi-nit inline. To clarify, this doesn't actually fix the semantics of '*' - its just deferring the final evaluation to the executor.

@@ -78,6 +96,10 @@ public Expression getExpression() {
return expression;
}

public Optional<AllColumns> getSource() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this from getSource to something else (maybe getAllColumns) ? It's confusing because source generally refers to a data source (stream/table) in the parser/engine. Same for other usage of the word source.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @rodesai. source refers to the '*' column only, so it makes more sense to rename this method (perhaps the variable name as well) to one that relates to it, like starColumn, allColumns, whatever.

Copy link
Member

@spena spena left a comment

Choose a reason for hiding this comment

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

The code looks good. Just the minor feedback about the StatementRewriter.getSource() method name.

@@ -78,6 +96,10 @@ public Expression getExpression() {
return expression;
}

public Optional<AllColumns> getSource() {
Copy link
Member

Choose a reason for hiding this comment

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

Agree with @rodesai. source refers to the '*' column only, so it makes more sense to rename this method (perhaps the variable name as well) to one that relates to it, like starColumn, allColumns, whatever.

@agavra
Copy link
Contributor Author

agavra commented Feb 22, 2019

Thanks for reviews @rodesai @spena. About your clarification - you are correct, this does not fix the semantics (that's a much more involved change).

@agavra agavra merged commit 41c401d into confluentinc:master Feb 22, 2019
@agavra agavra deleted the select_star branch February 22, 2019 18:34
@agavra agavra mentioned this pull request Feb 22, 2019
2 tasks
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