diff options
Diffstat (limited to 'tests/test_expressions.py')
-rw-r--r-- | tests/test_expressions.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/test_expressions.py b/tests/test_expressions.py index 69e1d14..c22f13e 100644 --- a/tests/test_expressions.py +++ b/tests/test_expressions.py @@ -15,6 +15,20 @@ class TestExpressions(unittest.TestCase): self.assertEqual(parse_one("x(1)").find(exp.Literal).depth, 1) def test_eq(self): + self.assertEqual(exp.to_identifier("a"), exp.to_identifier("A")) + + self.assertEqual( + exp.Column(table=exp.to_identifier("b"), this=exp.to_identifier("b")), + exp.Column(this=exp.to_identifier("b"), table=exp.to_identifier("b")), + ) + + self.assertEqual(exp.to_identifier("a", quoted=True), exp.to_identifier("A")) + self.assertNotEqual(exp.to_identifier("A", quoted=True), exp.to_identifier("A")) + self.assertNotEqual( + exp.to_identifier("A", quoted=True), exp.to_identifier("a", quoted=True) + ) + self.assertNotEqual(parse_one("'x'"), parse_one("'X'")) + self.assertNotEqual(parse_one("'1'"), parse_one("1")) self.assertEqual(parse_one("`a`", read="hive"), parse_one('"a"')) self.assertEqual(parse_one("`a`", read="hive"), parse_one('"a" ')) self.assertEqual(parse_one("`a`.b", read="hive"), parse_one('"a"."b"')) @@ -330,6 +344,7 @@ class TestExpressions(unittest.TestCase): self.assertEqual(parse_one("x + y * 2").sql(), "x + y * 2") self.assertEqual(parse_one('select "x"').sql(dialect="hive", pretty=True), "SELECT\n `x`") self.assertEqual(parse_one("X + y").sql(identify=True, normalize=True), '"x" + "y"') + self.assertEqual(parse_one('"X" + Y').sql(identify=True, normalize=True), '"X" + "y"') self.assertEqual(parse_one("SUM(X)").sql(identify=True, normalize=True), 'SUM("x")') def test_transform_with_arguments(self): @@ -450,22 +465,28 @@ class TestExpressions(unittest.TestCase): self.assertIsInstance(parse_one("ARRAY_CONTAINS(a, 'a')"), exp.ArrayContains) self.assertIsInstance(parse_one("ARRAY_SIZE(a)"), exp.ArraySize) self.assertIsInstance(parse_one("AVG(a)"), exp.Avg) + self.assertIsInstance(parse_one("BEGIN DEFERRED TRANSACTION"), exp.Transaction) self.assertIsInstance(parse_one("CEIL(a)"), exp.Ceil) self.assertIsInstance(parse_one("CEILING(a)"), exp.Ceil) self.assertIsInstance(parse_one("COALESCE(a, b)"), exp.Coalesce) + self.assertIsInstance(parse_one("COMMIT"), exp.Commit) self.assertIsInstance(parse_one("COUNT(a)"), exp.Count) + self.assertIsInstance(parse_one("COUNT_IF(a > 0)"), exp.CountIf) self.assertIsInstance(parse_one("DATE_ADD(a, 1)"), exp.DateAdd) self.assertIsInstance(parse_one("DATE_DIFF(a, 2)"), exp.DateDiff) self.assertIsInstance(parse_one("DATE_STR_TO_DATE(a)"), exp.DateStrToDate) self.assertIsInstance(parse_one("DAY(a)"), exp.Day) self.assertIsInstance(parse_one("EXP(a)"), exp.Exp) self.assertIsInstance(parse_one("FLOOR(a)"), exp.Floor) + self.assertIsInstance(parse_one("GENERATE_SERIES(a, b, c)"), exp.GenerateSeries) + self.assertIsInstance(parse_one("GLOB(x, y)"), exp.Glob) self.assertIsInstance(parse_one("GREATEST(a, b)"), exp.Greatest) self.assertIsInstance(parse_one("IF(a, b, c)"), exp.If) self.assertIsInstance(parse_one("INITCAP(a)"), exp.Initcap) self.assertIsInstance(parse_one("JSON_EXTRACT(a, '$.name')"), exp.JSONExtract) self.assertIsInstance(parse_one("JSON_EXTRACT_SCALAR(a, '$.name')"), exp.JSONExtractScalar) self.assertIsInstance(parse_one("LEAST(a, b)"), exp.Least) + self.assertIsInstance(parse_one("LIKE(x, y)"), exp.Like) self.assertIsInstance(parse_one("LN(a)"), exp.Ln) self.assertIsInstance(parse_one("LOG10(a)"), exp.Log10) self.assertIsInstance(parse_one("MAX(a)"), exp.Max) @@ -477,6 +498,7 @@ class TestExpressions(unittest.TestCase): self.assertIsInstance(parse_one("QUANTILE(a, 0.90)"), exp.Quantile) self.assertIsInstance(parse_one("REGEXP_LIKE(a, 'test')"), exp.RegexpLike) self.assertIsInstance(parse_one("REGEXP_SPLIT(a, 'test')"), exp.RegexpSplit) + self.assertIsInstance(parse_one("ROLLBACK"), exp.Rollback) self.assertIsInstance(parse_one("ROUND(a)"), exp.Round) self.assertIsInstance(parse_one("ROUND(a, 2)"), exp.Round) self.assertIsInstance(parse_one("SPLIT(a, 'test')"), exp.Split) @@ -504,11 +526,6 @@ class TestExpressions(unittest.TestCase): self.assertIsInstance(parse_one("VARIANCE(a)"), exp.Variance) self.assertIsInstance(parse_one("VARIANCE_POP(a)"), exp.VariancePop) self.assertIsInstance(parse_one("YEAR(a)"), exp.Year) - self.assertIsInstance(parse_one("BEGIN DEFERRED TRANSACTION"), exp.Transaction) - self.assertIsInstance(parse_one("COMMIT"), exp.Commit) - self.assertIsInstance(parse_one("ROLLBACK"), exp.Rollback) - self.assertIsInstance(parse_one("GENERATE_SERIES(a, b, c)"), exp.GenerateSeries) - self.assertIsInstance(parse_one("COUNT_IF(a > 0)"), exp.CountIf) def test_column(self): column = parse_one("a.b.c.d") @@ -542,6 +559,7 @@ class TestExpressions(unittest.TestCase): self.assertEqual(column.table, "a") self.assertIsInstance(parse_one("*"), exp.Star) + self.assertEqual(exp.column("a", table="b", db="c", catalog="d"), exp.to_column("d.c.b.a")) def test_text(self): column = parse_one("a.b.c.d.e") |