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: Adding datetime and timestamp format logic #840

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions third_party/ibis/ibis_addon/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def strftime_bigquery(translator, expr):
strftime_format_func_name, fmt_string, arg_formatted
)

def strftime_mysql(translator, expr):
arg, format_string = expr.op().args
arg_formatted = translator.translate(arg)
arg_type = arg.type()
fmt_string = translator.translate(format_string)
if isinstance(arg_type, dt.Timestamp):
fmt_string = "%Y-%m-%d %H:%i:%S"
return sa.func.date_format(arg_formatted, fmt_string)


def format_hashbytes_teradata(translator, expr):
arg, how = expr.op().args
Expand Down Expand Up @@ -308,6 +317,7 @@ def sa_cast_postgres(t, expr):
BigQueryExprTranslator._registry[HashBytes] = format_hashbytes_bigquery
BigQueryExprTranslator._registry[RawSQL] = format_raw_sql
BigQueryExprTranslator._registry[Strftime] = strftime_bigquery
MySQLExprTranslator._registry[Strftime] = strftime_mysql
AlchemyExprTranslator._registry[RawSQL] = format_raw_sql
AlchemyExprTranslator._registry[HashBytes] = format_hashbytes_alchemy
MSSQLExprTranslator._registry[HashBytes] = sa_format_hashbytes_mssql
Expand Down