summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_databricks.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dialects/test_databricks.py')
-rw-r--r--tests/dialects/test_databricks.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/dialects/test_databricks.py b/tests/dialects/test_databricks.py
index 2168f55..7560d61 100644
--- a/tests/dialects/test_databricks.py
+++ b/tests/dialects/test_databricks.py
@@ -12,6 +12,76 @@ class TestDatabricks(Validator):
"databricks": "SELECT DATEDIFF(year, 'start', 'end')",
},
)
+ self.validate_all(
+ "SELECT DATEDIFF(microsecond, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(microsecond, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) * 1000000 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(millisecond, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(millisecond, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) * 1000 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(second, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(second, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(minute, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(minute, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) / 60 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(hour, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(hour, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) / 3600 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(day, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(day, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(epoch FROM CAST('end' AS TIMESTAMP) - CAST('start' AS TIMESTAMP)) / 86400 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(week, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(week, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(year FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) * 48 + EXTRACT(month FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) * 4 + EXTRACT(day FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) / 7 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(month, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(month, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(year FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) * 12 + EXTRACT(month FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(quarter, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(quarter, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(year FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) * 4 + EXTRACT(month FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) / 3 AS BIGINT)",
+ },
+ )
+ self.validate_all(
+ "SELECT DATEDIFF(year, 'start', 'end')",
+ write={
+ "databricks": "SELECT DATEDIFF(year, 'start', 'end')",
+ "postgres": "SELECT CAST(EXTRACT(year FROM AGE(CAST('end' AS TIMESTAMP), CAST('start' AS TIMESTAMP))) AS BIGINT)",
+ },
+ )
def test_add_date(self):
self.validate_all(