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(clickhouse): Remove CURRENT_TIMESTAMP from NO_PAREN_FUNCTIONS #4079

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

VaggelisD
Copy link
Collaborator

Fixes #4076

@georgesittas georgesittas merged commit 4eb384a into main Sep 6, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/ch_curr_ts branch September 6, 2024 12:48
@hellozepp
Copy link
Contributor

@VaggelisD Can we add quoted arg to CURRENT_TIMESTAMP in ClickHouse?

e.g: this=Identifier(this=current_timestamp, quoted=True))

This will ensure that the target dialect will not have ambiguity when transpiling whether it is a field or a sql expression?

I encountered this problem when transpiling to spark, which supports this sql expression. Although it is not easy to handle, I did it like this:

def _escape_current_timestamp(expression: exp.Select):
    for column in expression.find_all(exp.Column):
        if column.this.name.upper() == 'CURRENT_TIMESTAMP':
            column.this.set("quoted", True)

Is this right?

@georgesittas
Copy link
Collaborator

This isn't the correct way to do it, you need to add RESERVED_KEYWORDS for spark or whatever you want to transpile towards.

@hellozepp
Copy link
Contributor

@georgesittas Tks, this works for me.

My understanding is that when current_timestamp is used as a sql expression in the source dialect, it will be parsed as expressions=[CurrentTimestamp()], so it does not affect our RESERVED of current_timestamp. Right?

@georgesittas
Copy link
Collaborator

If you're parsing using clickhouse that's not right, for example:

>>> import sqlglot
>>> sqlglot.parse_one("current_timestamp", "clickhouse")
Column(
  this=Identifier(this=current_timestamp, quoted=False))

This would be quoted if current_timestamp is among the reserved expressions.

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.

Clickhouse current_timestamp table field is not support
3 participants