diff options
Diffstat (limited to '')
-rw-r--r-- | tests/test_expressions.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_expressions.py b/tests/test_expressions.py index abc95cb..9ad2bf5 100644 --- a/tests/test_expressions.py +++ b/tests/test_expressions.py @@ -1,3 +1,4 @@ +import datetime import unittest from sqlglot import alias, exp, parse_one @@ -29,6 +30,7 @@ class TestExpressions(unittest.TestCase): self.assertEqual(parse_one("TO_DATE(x)", read="hive"), parse_one("ts_or_ds_to_date(x)")) self.assertEqual(exp.Table(pivots=[]), exp.Table()) self.assertNotEqual(exp.Table(pivots=[None]), exp.Table()) + self.assertEqual(exp.DataType.build("int"), exp.DataType(this=exp.DataType.Type.INT, nested=False)) def test_find(self): expression = parse_one("CREATE TABLE x STORED AS PARQUET AS SELECT * FROM y") @@ -486,6 +488,8 @@ class TestExpressions(unittest.TestCase): ((1, "2", None), "(1, '2', NULL)"), ([1, "2", None], "ARRAY(1, '2', NULL)"), ({"x": None}, "MAP('x', NULL)"), + (datetime.datetime(2022, 10, 1, 1, 1, 1), "TIME_STR_TO_TIME('2022-10-01 01:01:01')"), + (datetime.date(2022, 10, 1), "DATE_STR_TO_DATE('2022-10-01')"), ]: with self.subTest(value): self.assertEqual(exp.convert(value).sql(), expected) @@ -496,3 +500,25 @@ class TestExpressions(unittest.TestCase): [e.alias_or_name for e in expression.expressions], ["a", "B", "c", "D"], ) + + def test_to_table(self): + table_only = exp.to_table("table_name") + self.assertEqual(table_only.name, "table_name") + self.assertIsNone(table_only.args.get("db")) + self.assertIsNone(table_only.args.get("catalog")) + db_and_table = exp.to_table("db.table_name") + self.assertEqual(db_and_table.name, "table_name") + self.assertEqual(db_and_table.args.get("db"), exp.to_identifier("db")) + self.assertIsNone(db_and_table.args.get("catalog")) + catalog_db_and_table = exp.to_table("catalog.db.table_name") + self.assertEqual(catalog_db_and_table.name, "table_name") + self.assertEqual(catalog_db_and_table.args.get("db"), exp.to_identifier("db")) + self.assertEqual(catalog_db_and_table.args.get("catalog"), exp.to_identifier("catalog")) + + def test_union(self): + expression = parse_one("SELECT cola, colb UNION SELECT colx, coly") + self.assertIsInstance(expression, exp.Union) + self.assertEqual(expression.named_selects, ["cola", "colb"]) + self.assertEqual( + expression.selects, [exp.Column(this=exp.to_identifier("cola")), exp.Column(this=exp.to_identifier("colb"))] + ) |