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(hogql): proper datetime aliases for select columns #15970

Closed
wants to merge 6 commits into from

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Jun 9, 2023

Problem

Grouping by timestamp selected from events in a subquery doesn't work. That's because we replace timestamps with toTimeZone(events.timestamp, 'Your/Timezone'), but without an as timestamp in the end, we can't reference this field from within a subquery.

Changes

  • Adds as timestamp to the end of selected timestamps.
  • Moved the stack into the Visitor so it doesn't need to be reimplemented all the time
  • Keeps track which part of a select query is now evaluated with a separate tag stack

Feedback on this approach is very welcome.

How did you test this code?

Wrote tests

@mariusandra mariusandra marked this pull request as ready for review June 9, 2023 08:39
@mariusandra mariusandra requested a review from a team June 9, 2023 08:42
@mariusandra mariusandra requested a review from Twixes June 9, 2023 14:38
Comment on lines 30 to +31

def visit(self, node):
def visit(self, node: ast.AST, tag: Optional[str] = None):
Copy link
Member

@Twixes Twixes Jun 9, 2023

Choose a reason for hiding this comment

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

So tag is clunky and ambiguous. I think the real issue here is that the AST has no concept of a column , which is key, as a column is a very special case of an expression (columnExpr in the syntax). The rule is basically: ast.Alias is allowed as an ast.Column expr, and nowhere else. So if we have ast.Column, we'll be able to check whether the parent allows ast.Alias simply using stack.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@thmsobrmlr thmsobrmlr reopened this Jul 31, 2023
@thmsobrmlr thmsobrmlr removed the stale label Jul 31, 2023
@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@mariusandra mariusandra deleted the datetime-aliases branch August 23, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants