@@ -53,12 +53,47 @@ public void testViewDepthExceeded() throws Exception {
5353 addView ("view9" , "from view8" );
5454 addView ("view10" , "from view9" );
5555 addView ("view11" , "from view10" );
56- LogicalPlan plan = statement ("from view11" );
57- Exception e = expectThrows (VerificationException .class , () -> viewService .replaceViews (plan , telemetry , EsqlTestUtils .TEST_CFG ));
56+
57+ // FROM view11 should fail
58+ Exception e = expectThrows (
59+ VerificationException .class ,
60+ () -> viewService .replaceViews (statement ("from view11" ), telemetry , EsqlTestUtils .TEST_CFG )
61+ );
5862 assertThat (e .getMessage (), startsWith ("The maximum allowed view depth of 10 has been exceeded" ));
63+
64+ // But FROM view10 should work
65+ LogicalPlan rewritten = viewService .replaceViews (statement ("from view10" ), telemetry , EsqlTestUtils .TEST_CFG );
66+ assertThat (rewritten , equalTo (statement ("from emp" )));
67+ }
68+
69+ public void testModifiedViewDepth () {
70+ var config = new ViewService .ViewServiceConfig (100 , 10_000 , 1 );
71+ InMemoryViewService customViewService = new InMemoryViewService (functionRegistry , config );
72+ try {
73+ addView ("view1" , "from emp" , customViewService );
74+ addView ("view2" , "from view1" , customViewService );
75+ addView ("view3" , "from view2" , customViewService );
76+
77+ // FROM view2 should fail
78+ Exception e = expectThrows (
79+ VerificationException .class ,
80+ () -> customViewService .replaceViews (statement ("from view2" ), telemetry , EsqlTestUtils .TEST_CFG )
81+ );
82+ assertThat (e .getMessage (), startsWith ("The maximum allowed view depth of 1 has been exceeded" ));
83+
84+ // But FROM view1 should work
85+ LogicalPlan rewritten = customViewService .replaceViews (statement ("from view1" ), telemetry , EsqlTestUtils .TEST_CFG );
86+ assertThat (rewritten , equalTo (statement ("from emp" )));
87+ } catch (Exception e ) {
88+ throw new AssertionError ("unexpected exception" , e );
89+ }
5990 }
6091
6192 private void addView (String name , String query ) throws Exception {
93+ addView (name , query , viewService );
94+ }
95+
96+ private void addView (String name , String query , ViewService viewService ) throws Exception {
6297 viewService .put (name , new View (query ), ActionListener .noop (), EsqlTestUtils .TEST_CFG );
6398 }
6499
0 commit comments