summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_databricks.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:24:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-04 07:24:05 +0000
commit621555af37594a213d91ea113d5fc7739af84d40 (patch)
tree5aaa3b586692062accffc21cfaaa5a3917ee77b3 /tests/dialects/test_databricks.py
parentAdding upstream version 10.2.9. (diff)
downloadsqlglot-621555af37594a213d91ea113d5fc7739af84d40.tar.xz
sqlglot-621555af37594a213d91ea113d5fc7739af84d40.zip
Adding upstream version 10.4.2.upstream/10.4.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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(