Skip to content

Commit 14b42b0

Browse files
committed
fix todatetimeop compiler
1 parent 81e9222 commit 14b42b0

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • packages/bigframes/bigframes/core/compile/sqlglot/expressions

packages/bigframes/bigframes/core/compile/sqlglot/expressions/datetime_ops.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,14 @@ def _(expr: TypedExpr) -> sge.Expression:
364364
def _(expr: TypedExpr, op: ops.ToDatetimeOp) -> sge.Expression:
365365
if op.format:
366366
result = expr.expr
367-
if expr.dtype != dtypes.STRING_DTYPE:
367+
if expr.dtype == dtypes.STRING_DTYPE:
368+
return sge.TryCast(this=result, to="DATETIME")
369+
else:
368370
result = sge.Cast(this=result, to="STRING")
369-
return sge.TryCast(this=result, to="DATETIME")
371+
result = sge.func(
372+
"PARSE_TIMESTAMP", sge.convert(op.format), result, sge.convert("UTC")
373+
)
374+
return sge.Cast(this=result, to="DATETIME")
370375

371376
if expr.dtype in (
372377
dtypes.STRING_DTYPE,

0 commit comments

Comments
 (0)