From eb84d185ce5f43a8c4bf52b8c3d7b20bcdd2922b Mon Sep 17 00:00:00 2001 From: Guy Cohen Date: Wed, 6 Dec 2023 16:12:39 +0200 Subject: [PATCH] Add tests for inline functions --- .../tests/TestInlineFunctionQueries.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testing/trino-tests/src/test/java/io/trino/tests/TestInlineFunctionQueries.java b/testing/trino-tests/src/test/java/io/trino/tests/TestInlineFunctionQueries.java index ec16db4f49b8..9010a0701569 100644 --- a/testing/trino-tests/src/test/java/io/trino/tests/TestInlineFunctionQueries.java +++ b/testing/trino-tests/src/test/java/io/trino/tests/TestInlineFunctionQueries.java @@ -63,4 +63,34 @@ SELECT my_func(nationkey) """, "SELECT nationkey * 2 FROM nation"); } + + @Test + public void testInlineFunctionWithIf() + { + assertQuery( + """ + WITH FUNCTION my_func(x bigint) + RETURNS bigint + RETURN if(x=1, NULL, x) + SELECT my_func(nationkey) + FROM nation + WHERE nationkey = 1 + """, + "VALUES(cast(NULL as bigint))"); + } + + @Test + public void testInlineFunctionWithNullIf() + { + assertQuery( + """ + WITH FUNCTION my_func(x bigint) + RETURNS bigint + RETURN nullif(x, 1) + SELECT my_func(nationkey) + FROM nation + WHERE nationkey = 1 + """, + "VALUES(cast(NULL as bigint))"); + } }