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

transpile doesn't work for date_trunc from duckdb to spark/databricks #1875

Closed
xinglin-zhao opened this issue Jul 1, 2023 · 0 comments
Closed

Comments

@xinglin-zhao
Copy link

xinglin-zhao commented Jul 1, 2023

Hi there, i have an issue with transpile. It cannot work for date_trunc from duckdb to spark/databricks, see below:

from pypika import CustomFunction
from pypika.functions import Timestamp
from sqlglot import transpile
from datetime import datetime


DateTrunc = CustomFunction("date_trunc", ["part", "timestamp"])
# duckdb format https://duckdb.org/docs/archive/0.2.8/sql/functions/timestamp
query = DateTrunc("hour", Timestamp(datetime.now())).get_sql(dialect="duckdb")
print(query)

spark_sql = transpile(query, read="duckdb", write="databricks", pretty=True)

print(spark_sql)

The output is

date_trunc('hour',TIMESTAMP('2023-07-01T00:29:36.860678'))
["TRUNC(TIMESTAMP('2023-07-01T00:29:36.860678'), 'hour')"]

expecting the databricks sql output be something like this date_trunc('hour',TIMESTAMP('2023-07-01T00:29:36.860678')), see doc https://docs.databricks.com/sql/language-manual/functions/date_trunc.html

@tobymao tobymao closed this as completed in fe69102 Jul 1, 2023
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

No branches or pull requests

1 participant