summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_tsql.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-10 05:36:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-10 05:36:25 +0000
commit3517257d82008871c863f71a402742556dacc5cf (patch)
tree65704dee85c7aa830d01426c9bc3080a80c4e863 /tests/dialects/test_tsql.py
parentAdding upstream version 17.2.0. (diff)
downloadsqlglot-3517257d82008871c863f71a402742556dacc5cf.tar.xz
sqlglot-3517257d82008871c863f71a402742556dacc5cf.zip
Adding upstream version 17.3.0.upstream/17.3.0
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.py209
1 files changed, 207 insertions, 2 deletions
diff --git a/tests/dialects/test_tsql.py b/tests/dialects/test_tsql.py
index ca6d70c..5426859 100644
--- a/tests/dialects/test_tsql.py
+++ b/tests/dialects/test_tsql.py
@@ -43,7 +43,7 @@ class TestTSQL(Validator):
"SELECT CAST([a].[b] AS SMALLINT) FROM foo",
write={
"tsql": 'SELECT CAST("a"."b" AS SMALLINT) FROM foo',
- "spark": "SELECT CAST(`a`.`b` AS SHORT) FROM foo",
+ "spark": "SELECT CAST(`a`.`b` AS SMALLINT) FROM foo",
},
)
self.validate_all(
@@ -84,7 +84,7 @@ class TestTSQL(Validator):
"SELECT CAST([a].[b] AS SMALLINT) FROM foo",
write={
"tsql": 'SELECT CAST("a"."b" AS SMALLINT) FROM foo',
- "spark": "SELECT CAST(`a`.`b` AS SHORT) FROM foo",
+ "spark": "SELECT CAST(`a`.`b` AS SMALLINT) FROM foo",
},
)
self.validate_all(
@@ -155,6 +155,211 @@ class TestTSQL(Validator):
},
)
+ def test__types_ints(self):
+ self.validate_all(
+ "CAST(X AS INT)",
+ write={
+ "hive": "CAST(X AS INT)",
+ "spark2": "CAST(X AS INT)",
+ "spark": "CAST(X AS INT)",
+ "tsql": "CAST(X AS INTEGER)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(X AS BIGINT)",
+ write={
+ "hive": "CAST(X AS BIGINT)",
+ "spark2": "CAST(X AS BIGINT)",
+ "spark": "CAST(X AS BIGINT)",
+ "tsql": "CAST(X AS BIGINT)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(X AS SMALLINT)",
+ write={
+ "hive": "CAST(X AS SMALLINT)",
+ "spark2": "CAST(X AS SMALLINT)",
+ "spark": "CAST(X AS SMALLINT)",
+ "tsql": "CAST(X AS SMALLINT)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(X AS TINYINT)",
+ write={
+ "hive": "CAST(X AS TINYINT)",
+ "spark2": "CAST(X AS TINYINT)",
+ "spark": "CAST(X AS TINYINT)",
+ "tsql": "CAST(X AS TINYINT)",
+ },
+ )
+
+ def test_types_decimals(self):
+ self.validate_all(
+ "CAST(x as FLOAT)",
+ write={
+ "spark": "CAST(x AS FLOAT)",
+ "tsql": "CAST(x AS FLOAT)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as DOUBLE)",
+ write={
+ "spark": "CAST(x AS DOUBLE)",
+ "tsql": "CAST(x AS DOUBLE)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as DECIMAL(15, 4))",
+ write={
+ "spark": "CAST(x AS DECIMAL(15, 4))",
+ "tsql": "CAST(x AS NUMERIC(15, 4))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as NUMERIC(13,3))",
+ write={
+ "spark": "CAST(x AS DECIMAL(13, 3))",
+ "tsql": "CAST(x AS NUMERIC(13, 3))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as MONEY)",
+ write={
+ "spark": "CAST(x AS DECIMAL(15, 4))",
+ "tsql": "CAST(x AS MONEY)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as SMALLMONEY)",
+ write={
+ "spark": "CAST(x AS DECIMAL(6, 4))",
+ "tsql": "CAST(x AS SMALLMONEY)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as REAL)",
+ write={
+ "spark": "CAST(x AS FLOAT)",
+ "tsql": "CAST(x AS FLOAT)",
+ },
+ )
+
+ def test_types_string(self):
+ self.validate_all(
+ "CAST(x as CHAR(1))",
+ write={
+ "spark": "CAST(x AS CHAR(1))",
+ "tsql": "CAST(x AS CHAR(1))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as VARCHAR(2))",
+ write={
+ "spark": "CAST(x AS VARCHAR(2))",
+ "tsql": "CAST(x AS VARCHAR(2))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as NCHAR(1))",
+ write={
+ "spark": "CAST(x AS CHAR(1))",
+ "tsql": "CAST(x AS CHAR(1))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as NVARCHAR(2))",
+ write={
+ "spark": "CAST(x AS VARCHAR(2))",
+ "tsql": "CAST(x AS VARCHAR(2))",
+ },
+ )
+
+ def test_types_date(self):
+ self.validate_all(
+ "CAST(x as DATE)",
+ write={
+ "spark": "CAST(x AS DATE)",
+ "tsql": "CAST(x AS DATE)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as DATE)",
+ write={
+ "spark": "CAST(x AS DATE)",
+ "tsql": "CAST(x AS DATE)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as TIME(4))",
+ write={
+ "spark": "CAST(x AS TIMESTAMP)",
+ "tsql": "CAST(x AS TIMESTAMP(4))",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as DATETIME2)",
+ write={
+ "spark": "CAST(x AS TIMESTAMP)",
+ "tsql": "CAST(x AS DATETIME2)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as DATETIMEOFFSET)",
+ write={
+ "spark": "CAST(x AS TIMESTAMP)",
+ "tsql": "CAST(x AS TIMESTAMPTZ)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as SMALLDATETIME)",
+ write={
+ "spark": "CAST(x AS TIMESTAMP)",
+ "tsql": "CAST(x AS DATETIME2)",
+ },
+ )
+
+ def test_types_bin(self):
+ self.validate_all(
+ "CAST(x as BIT)",
+ write={
+ "spark": "CAST(x AS BOOLEAN)",
+ "tsql": "CAST(x AS BIT)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as UNIQUEIDENTIFIER)",
+ write={
+ "spark": "CAST(x AS STRING)",
+ "tsql": "CAST(x AS UNIQUEIDENTIFIER)",
+ },
+ )
+
+ self.validate_all(
+ "CAST(x as VARBINARY)",
+ write={
+ "spark": "CAST(x AS BINARY)",
+ "tsql": "CAST(x AS VARBINARY)",
+ },
+ )
+
def test_udf(self):
self.validate_identity(
"CREATE PROCEDURE foo @a INTEGER, @b INTEGER AS SELECT @a = SUM(bla) FROM baz AS bar"