@@ -5,62 +5,6 @@ use crate::sql_lint::tests::helpers::{fixture_harness, format_batch_json};
55use crate :: sql_lint:: tests:: { helpers, test_types} ;
66use crate :: sql_tokens:: main:: query_fingerprint:: query_fingerprint;
77
8- #[ test]
9- fn given_nested_function_calls_when_linting_then_the_requested_or_default_depth_bounds_them ( ) {
10- let test_cases = [
11- test_types:: FunctionDepthTestCase {
12- description : "the default depth of 256 parses" ,
13- depth : 256 ,
14- max_function_call_depth : None ,
15- expected_error : None ,
16- } ,
17- test_types:: FunctionDepthTestCase {
18- description : "one call past the default fails and names the setting" ,
19- depth : 257 ,
20- max_function_call_depth : None ,
21- expected_error : Some ( "configured limit 256" ) ,
22- } ,
23- test_types:: FunctionDepthTestCase {
24- description : "a requested depth bounds the parse" ,
25- depth : 65 ,
26- max_function_call_depth : Some ( 64 ) ,
27- expected_error : Some ( "configured limit 64" ) ,
28- } ,
29- test_types:: FunctionDepthTestCase {
30- description : "a requested depth above the default lets deeper calls parse" ,
31- depth : 300 ,
32- max_function_call_depth : Some ( 300 ) ,
33- expected_error : None ,
34- } ,
35- ] ;
36- for test_case in test_cases {
37- let request = json ! ( {
38- "version" : 1 ,
39- "sql" : helpers:: nested_function_sql( test_case. depth) ,
40- "dialect" : "snowflake" ,
41- "max_function_call_depth" : test_case. max_function_call_depth,
42- } ) ;
43- let outcome: Result < Value , String > = lint_json ( & request. to_string ( ) )
44- . and_then ( |response| serde_json:: from_str ( & response) . map_err ( |e| e. to_string ( ) ) ) ;
45- match ( outcome, test_case. expected_error ) {
46- ( Ok ( response) , None ) => assert_eq ! (
47- response[ "diagnostics" ] ,
48- json!( [ ] ) ,
49- "{}" ,
50- test_case. description
51- ) ,
52- ( Err ( error) , Some ( limit) ) => assert ! (
53- error. contains( "E_GUARD_FUNCTION_NESTING_DEPTH_EXCEEDED" )
54- && error. contains( limit)
55- && error. contains( "max_function_call_depth" ) ,
56- "{}: {error}" ,
57- test_case. description
58- ) ,
59- ( outcome, _) => panic ! ( "{}: {outcome:?}" , test_case. description) ,
60- }
61- }
62- }
63-
648#[ test]
659fn given_sql_cases_when_linting_then_diagnostics_match ( ) -> Result < ( ) , String > {
6610 let test_cases = [
@@ -1826,62 +1770,6 @@ fn given_tsql_bare_union_when_linting_then_diagnostic_has_no_invalid_fix() -> Re
18261770 Ok ( ( ) )
18271771}
18281772
1829- /// Databricks keeps a WINDOW clause written after a parenthesized query on the subquery, so a ranking call naming that window is still checked.
1830- #[ test]
1831- fn given_databricks_window_after_parentheses_when_linting_then_ranking_rules_read_it ( )
1832- -> Result < ( ) , String > {
1833- let test_cases = [
1834- test_types:: NamedWindowRankingTestCase {
1835- description : "a ranking sort above the cap in a WINDOW after the parentheses" ,
1836- sql : "(SELECT o.order_id, ROW_NUMBER() OVER w AS rn FROM orders AS o) WINDOW w AS (ORDER BY o.a, o.b, o.c, o.d, o.e, o.f)" ,
1837- rule : "SQLCLEAN043" ,
1838- expected_anchors : & [ "ROW_NUMBER" ] ,
1839- } ,
1840- test_types:: NamedWindowRankingTestCase {
1841- description : "the same with a WITH before the parentheses" ,
1842- sql : "WITH c AS (SELECT 1 AS x) (SELECT o.order_id, ROW_NUMBER() OVER w AS rn FROM orders AS o) WINDOW w AS (ORDER BY o.a, o.b, o.c, o.d, o.e, o.f)" ,
1843- rule : "SQLCLEAN043" ,
1844- expected_anchors : & [ "ROW_NUMBER" ] ,
1845- } ,
1846- test_types:: NamedWindowRankingTestCase {
1847- description : "an ordering without a declared key in a WINDOW after the parentheses is unproven" ,
1848- sql : "(SELECT o.order_id, ROW_NUMBER() OVER w AS rn FROM orders AS o) WINDOW w AS (ORDER BY o.ordered_at)" ,
1849- rule : "SQLCLEAN018" ,
1850- expected_anchors : & [ "ROW_NUMBER" ] ,
1851- } ,
1852- test_types:: NamedWindowRankingTestCase {
1853- description : "a ranking sort within the cap in a WINDOW after the parentheses is clean" ,
1854- sql : "(SELECT o.order_id, ROW_NUMBER() OVER w AS rn FROM orders AS o) WINDOW w AS (ORDER BY o.a)" ,
1855- rule : "SQLCLEAN043" ,
1856- expected_anchors : & [ ] ,
1857- } ,
1858- ] ;
1859-
1860- for test_case in & test_cases {
1861- let diagnostics =
1862- helpers:: diagnostics_for_dialect ( test_case. sql , "databricks" , & [ test_case. rule ] ) ?;
1863- let anchors: Vec < String > = diagnostics
1864- . iter ( )
1865- . map ( |diagnostic| {
1866- let start = diagnostic[ "start" ] . as_u64 ( ) . unwrap_or_default ( ) as usize ;
1867- let end = diagnostic[ "end" ] . as_u64 ( ) . unwrap_or_default ( ) as usize ;
1868- test_case
1869- . sql
1870- . chars ( )
1871- . skip ( start)
1872- . take ( end - start)
1873- . collect ( )
1874- } )
1875- . collect ( ) ;
1876- assert_eq ! (
1877- anchors, test_case. expected_anchors,
1878- "{}" ,
1879- test_case. description
1880- ) ;
1881- }
1882- Ok ( ( ) )
1883- }
1884-
18851773#[ test]
18861774fn given_ordered_sql_batch_when_formatting_then_outputs_are_parallel_and_ordered ( )
18871775-> Result < ( ) , String > {
@@ -2050,57 +1938,3 @@ fn given_each_documented_dialect_when_reading_sql_then_sqlquack_was_built_for_it
20501938 }
20511939 Ok ( ( ) )
20521940}
2053-
2054- #[ test]
2055- fn given_nested_function_calls_when_formatting_then_the_requested_or_default_depth_bounds_them ( ) {
2056- let test_cases = [
2057- test_types:: FunctionDepthTestCase {
2058- description : "the default depth of 256 formats" ,
2059- depth : 256 ,
2060- max_function_call_depth : None ,
2061- expected_error : None ,
2062- } ,
2063- test_types:: FunctionDepthTestCase {
2064- description : "one call past the default is declined, naming the setting that raises it" ,
2065- depth : 257 ,
2066- max_function_call_depth : None ,
2067- expected_error : Some ( "configured limit 256; raise max_function_call_depth, up to 512" ) ,
2068- } ,
2069- test_types:: FunctionDepthTestCase {
2070- description : "a requested depth bounds the formatter" ,
2071- depth : 65 ,
2072- max_function_call_depth : Some ( 64 ) ,
2073- expected_error : Some ( "configured limit 64" ) ,
2074- } ,
2075- test_types:: FunctionDepthTestCase {
2076- description : "a requested depth above the most allowed is declined" ,
2077- depth : 2 ,
2078- max_function_call_depth : Some ( 513 ) ,
2079- expected_error : Some ( "max_function_call_depth" ) ,
2080- } ,
2081- ] ;
2082- for test_case in test_cases {
2083- let request = json ! ( {
2084- "version" : 1 ,
2085- "sql" : helpers:: nested_function_sql( test_case. depth) ,
2086- "dialect" : "snowflake" ,
2087- "max_function_call_depth" : test_case. max_function_call_depth,
2088- } ) ;
2089- let response: Value = serde_json:: from_str (
2090- & crate :: sql_lint:: main:: formatter:: format_json ( & request. to_string ( ) )
2091- . expect ( "a format response" ) ,
2092- )
2093- . expect ( "JSON" ) ;
2094- let declined: Option < & str > = ( response[ "formatted" ] == json ! ( false ) )
2095- . then ( || response[ "reason" ] . as_str ( ) . unwrap_or_default ( ) ) ;
2096- match ( declined, test_case. expected_error ) {
2097- ( None , None ) => { }
2098- ( Some ( reason) , Some ( limit) ) => assert ! (
2099- reason. contains( limit) ,
2100- "{}: {reason}" ,
2101- test_case. description
2102- ) ,
2103- ( declined, _) => panic ! ( "{}: {declined:?}" , test_case. description) ,
2104- }
2105- }
2106- }
0 commit comments