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

In LogAggregator, allow the use of a complex dimension w/ an already defined select as. #13729

Merged
merged 2 commits into from Nov 24, 2018

Conversation

diosmosis
Copy link
Member

This change allows the use of complex expressions as dimensions. Currently if someone uses, eg, a complex CASE WHEN ... END statement as a dimension, it will be duplicated in the select and in the group by of the query. This will allow users to add their own alias like CASE WHEN ... END AS blahblah, which will appear in the select as the entire CASE WHEN ... but as blahblah in the group by.

Also includes a hasTable($table) method addition to DataTable\Map so we can check if a table exists w/o triggering an error w/ getTable.

@diosmosis diosmosis added the Needs Review PRs that need a code review label Nov 19, 2018
@diosmosis diosmosis added this to the 3.8.0 milestone Nov 19, 2018
// if function, do not alias or prefix
if ($this->isFieldFunctionOrComplexExpression($field)) {
$selectAsString = $appendSelectAs = false;
} else if ($this->isFieldFunctionOrComplexExpression($field)) {
Copy link
Member

Choose a reason for hiding this comment

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

can you add a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a unit/integration test. the system tests should show a difference (I haven't copied the files over)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a test

Copy link
Member

Choose a reason for hiding this comment

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

just reading https://dev.mysql.com/doc/refman/8.0/en/select.html ... the AS is optional. I suppose we don't bother about this for now until this is a use case? Be best I think...

does the regex need to check it case insensitive?

also just double checked there cannot be two AS statements in there cause we have an entry for each dimension... just fyi ... was wondering about that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR isn't about requiring the AS, it's about detecting when it's there and just using it instead of assigning a new one. It's a workaround for when a complex sql expression is used as a dimension, which currently doesn't work since it just gets duplicated in both the select & group by parts.

Since it has to be used explicitly by a plugin developer, I think we don't have to check for uniqueness of the AS, since there will be an error and it will be programmer error.

Should be a case insensitive check, will look into that.

Copy link
Member

Choose a reason for hiding this comment

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

This PR isn't about requiring the AS,

I meant if someone used foo bar we wouldn't detect the bar alias. All good though and not needed to be detected right now.

@diosmosis
Copy link
Member Author

FYI @tsteur assuming this is ok to merge, let me know if it needs another change, will make it in another PR

@diosmosis diosmosis merged commit bd0de0c into 3.x-dev Nov 24, 2018
@diosmosis diosmosis deleted the log-aggregator-dim-select-as branch November 24, 2018 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants