Skip to content

Commit

Permalink
fix: Adding datetime and timestamp format logic (#840)
Browse files Browse the repository at this point in the history
Co-authored-by: Piyush Sarraf <[email protected]>
  • Loading branch information
piyushsarraf and Piyush Sarraf committed May 11, 2023
1 parent 1dd5fea commit eb095c9
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit eb095c9

Please sign in to comment.