Skip to content

Commit 00210aa

Browse files
committed
feat: actually compile dtype arg from TimestampFromYMDHMS
1 parent f88521e commit 00210aa

File tree

10 files changed

+53
-39
lines changed

10 files changed

+53
-39
lines changed

ibis/backends/sql/compilers/bigquery/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,13 @@ def visit_StringContains(self, op, *, haystack, needle):
527527
return self.f.strpos(haystack, needle) > 0
528528

529529
def visit_TimestampFromYMDHMS(
530-
self, op, *, year, month, day, hours, minutes, seconds
530+
self, op, *, year, month, day, hours, minutes, seconds, dtype
531531
):
532-
return self.f.anon.DATETIME(year, month, day, hours, minutes, seconds)
532+
if dtype.timezone is not None:
533+
raise NotImplementedError(
534+
"ibis hasn't implemented timezone-aware timestamp literals yet"
535+
)
536+
return self.f.datetime_from_parts(year, month, day, hours, minutes, seconds)
533537

534538
def visit_NonNullLiteral(self, op, *, value, dtype):
535539
if dtype.is_inet() or dtype.is_macaddr():

ibis/backends/sql/compilers/clickhouse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def visit_DateFromYMD(self, op, *, year, month, day):
424424
)
425425

426426
def visit_TimestampFromYMDHMS(
427-
self, op, *, year, month, day, hours, minutes, seconds, **_
427+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp, **_
428428
):
429429
to_datetime = self.f.toDateTime(
430430
self.f.concat(
@@ -441,7 +441,7 @@ def visit_TimestampFromYMDHMS(
441441
self.f.leftPad(self.f.toString(seconds), 2, "0"),
442442
)
443443
)
444-
if timezone := op.dtype.timezone:
444+
if timezone := dtype.timezone:
445445
return self.f.toTimeZone(to_datetime, timezone)
446446
return to_datetime
447447

ibis/backends/sql/compilers/datafusion.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -413,24 +413,25 @@ def visit_DateFromYMD(self, op, *, year, month, day):
413413
)
414414

415415
def visit_TimestampFromYMDHMS(
416-
self, op, *, year, month, day, hours, minutes, seconds, **_
416+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp, **_
417417
):
418-
return self.f.to_timestamp_micros(
419-
self.f.concat(
420-
self.f.lpad(self.cast(self.cast(year, dt.int64), dt.string), 4, "0"),
421-
"-",
422-
self.f.lpad(self.cast(self.cast(month, dt.int64), dt.string), 2, "0"),
423-
"-",
424-
self.f.lpad(self.cast(self.cast(day, dt.int64), dt.string), 2, "0"),
425-
"T",
426-
self.f.lpad(self.cast(self.cast(hours, dt.int64), dt.string), 2, "0"),
427-
":",
428-
self.f.lpad(self.cast(self.cast(minutes, dt.int64), dt.string), 2, "0"),
429-
":",
430-
self.f.lpad(self.cast(self.cast(seconds, dt.int64), dt.string), 2, "0"),
431-
".000000Z",
432-
)
433-
)
418+
args = [
419+
self.f.lpad(self.cast(self.cast(year, dt.int64), dt.string), 4, "0"),
420+
"-",
421+
self.f.lpad(self.cast(self.cast(month, dt.int64), dt.string), 2, "0"),
422+
"-",
423+
self.f.lpad(self.cast(self.cast(day, dt.int64), dt.string), 2, "0"),
424+
"T",
425+
self.f.lpad(self.cast(self.cast(hours, dt.int64), dt.string), 2, "0"),
426+
":",
427+
self.f.lpad(self.cast(self.cast(minutes, dt.int64), dt.string), 2, "0"),
428+
":",
429+
self.f.lpad(self.cast(self.cast(seconds, dt.int64), dt.string), 2, "0"),
430+
"Z",
431+
]
432+
if dtype.timezone is not None:
433+
args.append(dtype.timezone)
434+
return self.f.to_timestamp_seconds(self.f.concat(*args))
434435

435436
def visit_IsInf(self, op, *, arg):
436437
return sg.and_(sg.not_(self.f.isnan(arg)), self.f.abs(arg).eq(self.POS_INF))

ibis/backends/sql/compilers/druid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ def visit_TimestampFromUNIX(self, op, *, arg, unit):
179179
raise exc.UnsupportedArgumentError(f"Druid doesn't support {unit} units")
180180

181181
def visit_TimestampFromYMDHMS(
182-
self, op, *, year, month, day, hours, minutes, seconds
182+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp
183183
):
184+
if dtype.timezone is not None:
185+
raise NotImplementedError()
184186
return self.f.time_parse(
185187
self.f.concat(
186188
self.f.lpad(self.cast(year, dt.string), 4, "0"),

ibis/backends/sql/compilers/duckdb.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,13 @@ def visit_TimestampFromUNIX(self, op, *, arg, unit):
403403
raise com.UnsupportedOperationError(f"{unit!r} unit is not supported!")
404404

405405
def visit_TimestampFromYMDHMS(
406-
self, op, *, year, month, day, hours, minutes, seconds, **_
406+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp, **_
407407
):
408408
args = [year, month, day, hours, minutes, seconds]
409-
410-
func = "make_timestamp"
411-
if (timezone := op.dtype.timezone) is not None:
412-
func += "tz"
413-
args.append(timezone)
414-
415-
return self.f[func](*args)
409+
if (timezone := dtype.timezone) is not None:
410+
return self.f.make_timestamptz(*args, timezone)
411+
else:
412+
return self.f.make_timestamp(*args)
416413

417414
def visit_Cast(self, op, *, arg, to):
418415
dtype = op.arg.dtype

ibis/backends/sql/compilers/flink.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def visit_DateFromYMD(self, op, *, year, month, day):
381381
)
382382

383383
def visit_TimestampFromYMDHMS(
384-
self, op, *, year, month, day, hours, minutes, seconds
384+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp
385385
):
386386
padded_year = self.f.lpad(self.cast(year, dt.string), 4, "0")
387387
padded_month = self.f.lpad(self.cast(month, dt.string), 2, "0")
@@ -403,7 +403,7 @@ def visit_TimestampFromYMDHMS(
403403
":",
404404
padded_second,
405405
),
406-
op.dtype,
406+
dtype,
407407
)
408408

409409
def visit_ExtractEpochSeconds(self, op, *, arg):

ibis/backends/sql/compilers/mssql.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,13 @@ def visit_TimeFromHMS(self, op, *, hours, minutes, seconds):
334334
return self.f.timefromparts(hours, minutes, seconds, 0, 0)
335335

336336
def visit_TimestampFromYMDHMS(
337-
self, op, *, year, month, day, hours, minutes, seconds
337+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp
338338
):
339-
return self.f.datetimefromparts(year, month, day, hours, minutes, seconds, 0)
339+
if dtype.timezone is not None:
340+
raise NotImplementedError()
341+
return self.f.datetime2fromparts(
342+
year, month, day, hours, minutes, seconds, 0, dtype.scale
343+
)
340344

341345
def visit_StringFind(self, op, *, arg, substr, start, end):
342346
if start is not None:

ibis/backends/sql/compilers/postgres.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,21 @@ def visit_NonNullLiteral(self, op, *, value, dtype):
594594
return None
595595

596596
def visit_TimestampFromYMDHMS(
597-
self, op, *, year, month, day, hours, minutes, seconds
597+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp
598598
):
599599
to_int32 = partial(self.cast, to=dt.int32)
600-
return self.f.make_timestamp(
600+
args = (
601601
to_int32(year),
602602
to_int32(month),
603603
to_int32(day),
604604
to_int32(hours),
605605
to_int32(minutes),
606606
self.cast(seconds, dt.float64),
607607
)
608+
if dtype.timezone:
609+
return self.f.make_timestamptz(*args, dtype.timezone)
610+
else:
611+
return self.f.make_timestamp(*args)
608612

609613
def visit_DateFromYMD(self, op, *, year, month, day):
610614
to_int32 = partial(self.cast, to=dt.int32)

ibis/backends/sql/compilers/sqlite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,10 @@ def visit_TimeFromHMS(self, op, *, hours, minutes, seconds):
271271
return self.f.time(self.f.printf("%02d:%02d:%02d", hours, minutes, seconds))
272272

273273
def visit_TimestampFromYMDHMS(
274-
self, op, *, year, month, day, hours, minutes, seconds
274+
self, op, *, year, month, day, hours, minutes, seconds, dtype: dt.Timestamp
275275
):
276+
if dtype.timezone not in (None, "UTC"):
277+
raise NotImplementedError
276278
return self.f.datetime(
277279
self.f.printf(
278280
"%04d-%02d-%02d %02d:%02d:%02d%s",

ibis/backends/sql/compilers/trino.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def visit_TimeFromHMS(self, op, *, hours, minutes, seconds):
323323
)
324324

325325
def visit_TimestampFromYMDHMS(
326-
self, op, *, year, month, day, hours, minutes, seconds
326+
self, op, *, year, month, day, hours, minutes, seconds, dtype
327327
):
328328
return self.cast(
329329
self.f.from_iso8601_timestamp(
@@ -337,7 +337,7 @@ def visit_TimestampFromYMDHMS(
337337
seconds,
338338
)
339339
),
340-
dt.timestamp,
340+
dtype,
341341
)
342342

343343
def visit_TimestampFromUNIX(self, op, *, arg, unit):

0 commit comments

Comments
 (0)