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

Implement comprehensive query wildcard re-write #1632

Merged
merged 8 commits into from
Feb 24, 2015
Merged

Conversation

otoolep
Copy link
Contributor

@otoolep otoolep commented Feb 18, 2015

This patch implements comprehensive rewrite of wildcards, for both the "source" of the SELECT statement, and the GROUP BY. The parser prevents statements such as SELECT *,value, so those unit tests are commented out. However, the query parser should be fixed up eventually to allow this, as other SQL-based query engines support this.

@otoolep otoolep force-pushed the wildcard_group_by branch 2 times, most recently from 0a7a151 to 28f0f5a Compare February 18, 2015 07:37
@otoolep
Copy link
Contributor Author

otoolep commented Feb 18, 2015

This changes uses dedicated code for SELECT query rewrite, and is very close in form to what existed already for SELECT *. It's not clear to me if we should be using some node-walking re-write code.

@pauldix @benbjohnson @corylanou

@otoolep
Copy link
Contributor Author

otoolep commented Feb 18, 2015

Addresses issue #1624.

@otoolep
Copy link
Contributor Author

otoolep commented Feb 18, 2015

@dgnorton -- could do with your review too.

@@ -1977,6 +1977,12 @@ func (s *Server) ExecuteQuery(q *influxql.Query, database string, user *User) Re

// executeSelectStatement plans and executes a select statement against a database.
func (s *Server) executeSelectStatement(stmt *influxql.SelectStatement, database string, user *User) *Result {
// Perform any necessary query re-writing.
stmt, err := s.rewriteSelectStatement(stmt)
Copy link
Member

Choose a reason for hiding this comment

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

We should only rewrite if the statement actually has a wildcard. The statement struct should have a method that indicates if it has a wildcard.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@corylanou
Copy link
Contributor

+1

@benbjohnson
Copy link
Contributor

Are we going to handle wildcard expansion for multiple source measurements? e.g.

@otoolep
Copy link
Contributor Author

otoolep commented Feb 18, 2015

Wildcard method added @pauldix @benbjohnson -- there are a couple of different places the check could be placed, of course.

@@ -1508,6 +1508,8 @@ func (p *Parser) parseUnaryExpr() (Expr, error) {
case DURATION_VAL:
v, _ := ParseDuration(lit)
return &DurationLiteral{Val: v}, nil
case MUL:
return &Wildcard{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if wildcard expressions should be parsed separately so we don't allow weird stuff like SELECT value + *,* FROM cpu, which will get expanded to look something like SELECT value + *, value1, value2 FROM cpu. /cc @benbjohnson

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a reasonable suggestion, but outside the scope of this change I'd say. Happy to open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that we should do a lookahead for wildcards before parsing expressions but we can push that to a separate PR.

@otoolep
Copy link
Contributor Author

otoolep commented Feb 19, 2015

@pauldix is refactoring a chunk of the query engine, so this PR is on hold. He and @benbjohnson have promised to merge (or possibly rework) this when ready.

This code, when given a SELECT statement, returns another SELECT
statement such that all "query" and GROUP BY wildcards have been
replaced with all Measurement fields and tag keys respectively.
GROUP BY * functionality is now in place.
@otoolep
Copy link
Contributor Author

otoolep commented Feb 24, 2015

Rebased on master, and green build now.

pauldix added a commit that referenced this pull request Feb 24, 2015
Implement comprehensive query wildcard re-write
@pauldix pauldix merged commit 8697278 into master Feb 24, 2015
@pauldix pauldix removed the review label Feb 24, 2015
@pauldix pauldix deleted the wildcard_group_by branch February 24, 2015 05:13
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.

None yet

5 participants