-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathLambdaExpressionTest.java
More file actions
54 lines (45 loc) · 1.99 KB
/
Copy pathLambdaExpressionTest.java
File metadata and controls
54 lines (45 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2024 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class LambdaExpressionTest {
@Test
void testLambdaFunctionSingleParameter() throws JSQLParserException {
String sqlStr = "select list_transform( split('test', ''), x -> unicode(x) )";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testNestedLambdaFunctionMultipleParameter() throws JSQLParserException {
String sqlStr = "SELECT list_transform(\n" +
" [1, 2, 3],\n" +
" x -> list_reduce([4, 5, 6], (a, b) -> a + b) + x\n" +
" )";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testLambdaMultiParameterIssue2030() throws JSQLParserException {
String sqlStr = "SELECT map_filter(my_column, v -> v.my_inner_column = 'some_value')\n" +
"FROM my_table";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testLambdaMultiParameterIssue2032() throws JSQLParserException {
String sqlStr = "SELECT array_sort(array_agg(named_struct('depth', events_union.depth, 'eventtime',events_union.eventtime)), (left, right) -> case when(left.eventtime, left.depth) <(right.eventtime, right.depth) then -1 when(left.eventtime, left.depth) >(right.eventtime, right.depth) then 1 else 0 end) as col1 FROM your_table;";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
@Test
void testLambdaFirstArgumentIssue2195() throws JSQLParserException {
String sqlStr = "select array_map((x,y,z) -> x + y, [1], [2], [4]) FROM table_name";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}