@@ -1749,6 +1749,62 @@ public void testDropWildcardFields_WithLookupJoin() {
17491749 );
17501750 }
17511751
1752+ public void testForkFieldsWithKeep () {
1753+ assumeTrue ("FORK available as snapshot only" , EsqlCapabilities .Cap .FORK .isEnabled ());
1754+
1755+ assertFieldNames ("""
1756+ FROM test
1757+ | WHERE a > 2000
1758+ | EVAL b = a + 100
1759+ | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500)
1760+ (WHERE d > 1000 AND e == "aaa" | EVAL c = a + 200)
1761+ | WHERE x > y
1762+ | KEEP a, b, c, d, x
1763+ """ , Set .of ("a" , "a.*" , "c" , "c.*" , "d" , "d.*" , "e" , "e.*" , "x" , "x.*" , "y" , "y.*" ));
1764+ }
1765+
1766+ public void testForkFieldsWithNoProjection () {
1767+ assumeTrue ("FORK available as snapshot only" , EsqlCapabilities .Cap .FORK .isEnabled ());
1768+
1769+ assertFieldNames ("""
1770+ FROM test
1771+ | WHERE a > 2000
1772+ | EVAL b = a + 100
1773+ | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500)
1774+ (WHERE d > 1000 AND e == "aaa" | EVAL c = a + 200)
1775+ | WHERE x > y
1776+ """ , ALL_FIELDS );
1777+ }
1778+
1779+ public void testForkFieldsWithStatsInOneBranch () {
1780+ assumeTrue ("FORK available as snapshot only" , EsqlCapabilities .Cap .FORK .isEnabled ());
1781+
1782+ assertFieldNames ("""
1783+ FROM test
1784+ | WHERE a > 2000
1785+ | EVAL b = a + 100
1786+ | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500)
1787+ (STATS x = count(*), y=min(z))
1788+ | WHERE x > y
1789+ """ , Set .of ("a" , "a.*" , "c" , "c.*" , "z" , "z.*" ));
1790+ }
1791+
1792+ public void testForkFieldsWithEnrichAndLookupJoins () {
1793+ assumeTrue ("FORK available as snapshot only" , EsqlCapabilities .Cap .FORK .isEnabled ());
1794+ assumeTrue ("LOOKUP JOIN available as snapshot only" , EsqlCapabilities .Cap .JOIN_LOOKUP_V12 .isEnabled ());
1795+
1796+ assertFieldNames ("""
1797+ FROM test
1798+ | ENRICH enrich_policy ON abc
1799+ | EVAL b = a + 100
1800+ | LOOKUP JOIN my_lookup_index ON def
1801+ | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500)
1802+ (STATS x = count(*), y=min(z))
1803+ | LOOKUP JOIN my_lookup_index ON xyz
1804+ | WHERE x > y
1805+ """ , Set .of ("a" , "a.*" , "abc" , "abc.*" , "c" , "c.*" , "def" , "def.*" , "x" , "x.*" , "xyz" , "xyz.*" , "y" , "y.*" , "z" , "z.*" ));
1806+ }
1807+
17521808 private Set <String > fieldNames (String query , Set <String > enrichPolicyMatchFields ) {
17531809 var preAnalysisResult = new EsqlSession .PreAnalysisResult (null );
17541810 return EsqlSession .fieldNames (parser .createStatement (query ), enrichPolicyMatchFields , preAnalysisResult ).fieldNames ();
0 commit comments