diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-30 17:08:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-30 17:08:37 +0000 |
commit | be1cb18ea28222fca384a5459a024b7e9af5cadb (patch) | |
tree | 4698c9069380a7c30ceb51129f93f6c8662315e4 /tests/test_expressions.py | |
parent | Releasing debian version 10.5.6-1. (diff) | |
download | sqlglot-be1cb18ea28222fca384a5459a024b7e9af5cadb.tar.xz sqlglot-be1cb18ea28222fca384a5459a024b7e9af5cadb.zip |
Merging upstream version 10.5.10.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_expressions.py')
-rw-r--r-- | tests/test_expressions.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_expressions.py b/tests/test_expressions.py index 9e5f988..2d5407e 100644 --- a/tests/test_expressions.py +++ b/tests/test_expressions.py @@ -189,6 +189,27 @@ class TestExpressions(unittest.TestCase): "SELECT * FROM (SELECT a FROM tbl1) WHERE b > 100", ) + def test_function_building(self): + self.assertEqual(exp.func("bla", 1, "foo").sql(), "BLA(1, 'foo')") + self.assertEqual(exp.func("COUNT", exp.Star()).sql(), "COUNT(*)") + self.assertEqual(exp.func("bloo").sql(), "BLOO()") + self.assertEqual( + exp.func("locate", "x", "xo", dialect="hive").sql("hive"), "LOCATE('x', 'xo')" + ) + + self.assertIsInstance(exp.func("instr", "x", "b", dialect="mysql"), exp.StrPosition) + self.assertIsInstance(exp.func("bla", 1, "foo"), exp.Anonymous) + self.assertIsInstance( + exp.func("cast", this=exp.Literal.number(5), to=exp.DataType.build("DOUBLE")), + exp.Cast, + ) + + with self.assertRaises(ValueError): + exp.func("some_func", 1, arg2="foo") + + with self.assertRaises(ValueError): + exp.func("abs") + def test_named_selects(self): expression = parse_one( "SELECT a, b AS B, c + d AS e, *, 'zz', 'zz' AS z FROM foo as bar, baz" |