Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

add TIMESTAMP_NTZ for databricks #780

Merged
merged 1 commit into from
Nov 21, 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
4 changes: 3 additions & 1 deletion data_diff/databases/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Dialect(BaseDialect):
"DECIMAL": Decimal,
# Timestamps
"TIMESTAMP": Timestamp,
"TIMESTAMP_NTZ": Timestamp,
# Text
"STRING": Text,
# Boolean
Expand Down Expand Up @@ -89,7 +90,8 @@ def normalize_timestamp(self, value: str, coltype: TemporalType) -> str:
"""Databricks timestamp contains no more than 6 digits in precision"""

if coltype.rounds:
timestamp = f"cast(round(unix_micros({value}) / 1000000, {coltype.precision}) * 1000000 as bigint)"
# cast to timestamp due to unix_micros() requiring timestamp
timestamp = f"cast(round(unix_micros(cast({value} as timestamp)) / 1000000, {coltype.precision}) * 1000000 as bigint)"
return f"date_format(timestamp_micros({timestamp}), 'yyyy-MM-dd HH:mm:ss.SSSSSS')"

precision_format = "S" * coltype.precision + "0" * (6 - coltype.precision)
Expand Down