summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_tsql.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-17 10:32:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-17 10:32:12 +0000
commit244a05de60c9417daab9528b51788c3d2a00dc5f (patch)
tree89a9c82aa41d397e1b81c320ad7a287b6c80f313 /tests/dialects/test_tsql.py
parentAdding upstream version 10.4.2. (diff)
downloadsqlglot-244a05de60c9417daab9528b51788c3d2a00dc5f.tar.xz
sqlglot-244a05de60c9417daab9528b51788c3d2a00dc5f.zip
Adding upstream version 10.5.2.upstream/10.5.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_tsql.py')
-rw-r--r--tests/dialects/test_tsql.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index b4ac094..b74c05f 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -6,6 +6,8 @@ class TestTSQL(Validator):
def test_tsql(self):
self.validate_identity('SELECT "x"."y" FROM foo')
+ self.validate_identity("SELECT * FROM #foo")
+ self.validate_identity("SELECT * FROM ##foo")
self.validate_identity(
"SELECT DISTINCT DepartmentName, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY BaseRate) OVER (PARTITION BY DepartmentName) AS MedianCont FROM dbo.DimEmployee"
)
@@ -71,6 +73,12 @@ class TestTSQL(Validator):
"tsql": "CAST(x AS DATETIME2)",
},
)
+ self.validate_all(
+ "CAST(x AS DATETIME2(6))",
+ write={
+ "hive": "CAST(x AS TIMESTAMP)",
+ },
+ )
def test_charindex(self):
self.validate_all(
@@ -300,6 +308,12 @@ class TestTSQL(Validator):
"spark": "SELECT CAST(y.x AS VARCHAR(10)) AS z FROM testdb.dbo.test AS y",
},
)
+ self.validate_all(
+ "SELECT CAST((SELECT x FROM y) AS VARCHAR) AS test",
+ write={
+ "spark": "SELECT CAST((SELECT x FROM y) AS STRING) AS test",
+ },
+ )
def test_add_date(self):
self.validate_identity("SELECT DATEADD(year, 1, '2017/08/25')")
@@ -441,3 +455,13 @@ class TestTSQL(Validator):
"SELECT '''test'''",
write={"spark": r"SELECT '\'test\''"},
)
+
+ def test_eomonth(self):
+ self.validate_all(
+ "EOMONTH(GETDATE())",
+ write={"spark": "LAST_DAY(CURRENT_TIMESTAMP())"},
+ )
+ self.validate_all(
+ "EOMONTH(GETDATE(), -1)",
+ write={"spark": "LAST_DAY(ADD_MONTHS(CURRENT_TIMESTAMP(), -1))"},
+ )