@@ -849,6 +849,7 @@ impl CubeScanWrapperNode {
849849 expr,
850850 None ,
851851 Arc :: new ( HashMap :: new ( ) ) ,
852+ None ,
852853 )
853854 . await ?;
854855 columns. push ( AliasedColumn { expr, alias } ) ;
@@ -1563,13 +1564,15 @@ impl CubeScanWrapperNode {
15631564 } else {
15641565 original_expr. clone ( )
15651566 } ;
1567+
15661568 let ( expr_sql, new_sql_query) = Self :: generate_sql_for_expr (
15671569 plan. clone ( ) ,
15681570 sql,
15691571 generator. clone ( ) ,
15701572 expr. clone ( ) ,
15711573 push_to_cube_context,
15721574 subqueries. clone ( ) ,
1575+ None ,
15731576 )
15741577 . await ?;
15751578 let expr_sql =
@@ -1674,6 +1677,7 @@ impl CubeScanWrapperNode {
16741677 expr : Expr ,
16751678 push_to_cube_context : Option < & ' ctx PushToCubeContext > ,
16761679 subqueries : Arc < HashMap < String , String > > ,
1680+ mut used_members : Option < & ' ctx mut HashSet < String > > ,
16771681 ) -> Pin < Box < dyn Future < Output = Result < ( String , SqlQuery ) > > + Send + ' ctx > > {
16781682 Box :: pin ( async move {
16791683 match expr {
@@ -1685,6 +1689,7 @@ impl CubeScanWrapperNode {
16851689 * expr,
16861690 push_to_cube_context,
16871691 subqueries. clone ( ) ,
1692+ used_members,
16881693 )
16891694 . await ?;
16901695 Ok ( ( expr, sql_query) )
@@ -1723,6 +1728,7 @@ impl CubeScanWrapperNode {
17231728 expr,
17241729 None ,
17251730 subqueries. clone ( ) ,
1731+ used_members,
17261732 )
17271733 . await ;
17281734 }
@@ -1757,6 +1763,9 @@ impl CubeScanWrapperNode {
17571763 } ) ?;
17581764 match member {
17591765 MemberField :: Member ( member) => {
1766+ if let Some ( used_members) = used_members {
1767+ used_members. insert ( member. clone ( ) ) ;
1768+ }
17601769 Ok ( ( format ! ( "${{{}}}" , member) , sql_query) )
17611770 }
17621771 MemberField :: Literal ( value) => {
@@ -1767,6 +1776,7 @@ impl CubeScanWrapperNode {
17671776 Expr :: Literal ( value. clone ( ) ) ,
17681777 push_to_cube_context,
17691778 subqueries. clone ( ) ,
1779+ used_members,
17701780 )
17711781 . await
17721782 }
@@ -1818,6 +1828,7 @@ impl CubeScanWrapperNode {
18181828 * left,
18191829 push_to_cube_context,
18201830 subqueries. clone ( ) ,
1831+ used_members. as_deref_mut ( ) ,
18211832 )
18221833 . await ?;
18231834 let ( right, sql_query) = Self :: generate_sql_for_expr (
@@ -1827,6 +1838,7 @@ impl CubeScanWrapperNode {
18271838 * right,
18281839 push_to_cube_context,
18291840 subqueries. clone ( ) ,
1841+ used_members,
18301842 )
18311843 . await ?;
18321844 let resulting_sql = sql_generator
@@ -1849,6 +1861,7 @@ impl CubeScanWrapperNode {
18491861 * like. expr ,
18501862 push_to_cube_context,
18511863 subqueries. clone ( ) ,
1864+ used_members. as_deref_mut ( ) ,
18521865 )
18531866 . await ?;
18541867 let ( pattern, sql_query) = Self :: generate_sql_for_expr (
@@ -1858,6 +1871,7 @@ impl CubeScanWrapperNode {
18581871 * like. pattern ,
18591872 push_to_cube_context,
18601873 subqueries. clone ( ) ,
1874+ used_members. as_deref_mut ( ) ,
18611875 )
18621876 . await ?;
18631877 let ( escape_char, sql_query) = match like. escape_char {
@@ -1869,6 +1883,7 @@ impl CubeScanWrapperNode {
18691883 Expr :: Literal ( ScalarValue :: Utf8 ( Some ( escape_char. to_string ( ) ) ) ) ,
18701884 push_to_cube_context,
18711885 subqueries. clone ( ) ,
1886+ used_members,
18721887 )
18731888 . await ?;
18741889 ( Some ( escape_char) , sql_query)
@@ -1894,6 +1909,7 @@ impl CubeScanWrapperNode {
18941909 * ilike. expr ,
18951910 push_to_cube_context,
18961911 subqueries. clone ( ) ,
1912+ used_members. as_deref_mut ( ) ,
18971913 )
18981914 . await ?;
18991915 let ( pattern, sql_query) = Self :: generate_sql_for_expr (
@@ -1903,6 +1919,7 @@ impl CubeScanWrapperNode {
19031919 * ilike. pattern ,
19041920 push_to_cube_context,
19051921 subqueries. clone ( ) ,
1922+ used_members. as_deref_mut ( ) ,
19061923 )
19071924 . await ?;
19081925 let ( escape_char, sql_query) = match ilike. escape_char {
@@ -1914,6 +1931,7 @@ impl CubeScanWrapperNode {
19141931 Expr :: Literal ( ScalarValue :: Utf8 ( Some ( escape_char. to_string ( ) ) ) ) ,
19151932 push_to_cube_context,
19161933 subqueries. clone ( ) ,
1934+ used_members,
19171935 )
19181936 . await ?;
19191937 ( Some ( escape_char) , sql_query)
@@ -1940,6 +1958,7 @@ impl CubeScanWrapperNode {
19401958 * expr,
19411959 push_to_cube_context,
19421960 subqueries. clone ( ) ,
1961+ used_members,
19431962 )
19441963 . await ?;
19451964 let resulting_sql =
@@ -1962,6 +1981,7 @@ impl CubeScanWrapperNode {
19621981 * expr,
19631982 push_to_cube_context,
19641983 subqueries. clone ( ) ,
1984+ used_members,
19651985 )
19661986 . await ?;
19671987 let resulting_sql = sql_generator
@@ -1983,6 +2003,7 @@ impl CubeScanWrapperNode {
19832003 * expr,
19842004 push_to_cube_context,
19852005 subqueries. clone ( ) ,
2006+ used_members,
19862007 )
19872008 . await ?;
19882009 let resulting_sql = sql_generator
@@ -2004,6 +2025,7 @@ impl CubeScanWrapperNode {
20042025 * expr,
20052026 push_to_cube_context,
20062027 subqueries. clone ( ) ,
2028+ used_members,
20072029 )
20082030 . await ?;
20092031 let resulting_sql = sql_generator
@@ -2032,6 +2054,7 @@ impl CubeScanWrapperNode {
20322054 * expr,
20332055 push_to_cube_context,
20342056 subqueries. clone ( ) ,
2057+ used_members. as_deref_mut ( ) ,
20352058 )
20362059 . await ?;
20372060 sql_query = sql_query_next;
@@ -2048,6 +2071,7 @@ impl CubeScanWrapperNode {
20482071 * when,
20492072 push_to_cube_context,
20502073 subqueries. clone ( ) ,
2074+ used_members. as_deref_mut ( ) ,
20512075 )
20522076 . await ?;
20532077 let ( then, sql_query_next) = Self :: generate_sql_for_expr (
@@ -2057,6 +2081,7 @@ impl CubeScanWrapperNode {
20572081 * then,
20582082 push_to_cube_context,
20592083 subqueries. clone ( ) ,
2084+ used_members. as_deref_mut ( ) ,
20602085 )
20612086 . await ?;
20622087 sql_query = sql_query_next;
@@ -2070,6 +2095,7 @@ impl CubeScanWrapperNode {
20702095 * else_expr,
20712096 push_to_cube_context,
20722097 subqueries. clone ( ) ,
2098+ used_members,
20732099 )
20742100 . await ?;
20752101 sql_query = sql_query_next;
@@ -2093,6 +2119,7 @@ impl CubeScanWrapperNode {
20932119 * expr,
20942120 push_to_cube_context,
20952121 subqueries. clone ( ) ,
2122+ used_members,
20962123 )
20972124 . await ?;
20982125 let data_type = Self :: generate_sql_type ( sql_generator. clone ( ) , data_type) ?;
@@ -2113,6 +2140,7 @@ impl CubeScanWrapperNode {
21132140 * expr,
21142141 push_to_cube_context,
21152142 subqueries. clone ( ) ,
2143+ used_members,
21162144 )
21172145 . await ?;
21182146 let resulting_sql = sql_generator
@@ -2446,6 +2474,7 @@ impl CubeScanWrapperNode {
24462474 arg,
24472475 push_to_cube_context,
24482476 subqueries. clone ( ) ,
2477+ used_members. as_deref_mut ( ) ,
24492478 )
24502479 . await ?;
24512480 sql_query = query;
@@ -2483,6 +2512,7 @@ impl CubeScanWrapperNode {
24832512 args[ 1 ] . clone ( ) ,
24842513 push_to_cube_context,
24852514 subqueries. clone ( ) ,
2515+ used_members,
24862516 )
24872517 . await ?;
24882518 return Ok ( (
@@ -2526,6 +2556,7 @@ impl CubeScanWrapperNode {
25262556 arg,
25272557 push_to_cube_context,
25282558 subqueries. clone ( ) ,
2559+ used_members. as_deref_mut ( ) ,
25292560 )
25302561 . await ?;
25312562 sql_query = query;
@@ -2566,6 +2597,7 @@ impl CubeScanWrapperNode {
25662597 arg,
25672598 push_to_cube_context,
25682599 subqueries. clone ( ) ,
2600+ used_members. as_deref_mut ( ) ,
25692601 )
25702602 . await ?;
25712603 sql_query = query;
@@ -2595,6 +2627,7 @@ impl CubeScanWrapperNode {
25952627 expr,
25962628 push_to_cube_context,
25972629 subqueries. clone ( ) ,
2630+ used_members. as_deref_mut ( ) ,
25982631 )
25992632 . await ?;
26002633 sql_query = query;
@@ -2623,6 +2656,7 @@ impl CubeScanWrapperNode {
26232656 expr,
26242657 push_to_cube_context,
26252658 subqueries. clone ( ) ,
2659+ used_members. as_deref_mut ( ) ,
26262660 )
26272661 . await ?;
26282662 sql_query = query;
@@ -2664,6 +2698,7 @@ impl CubeScanWrapperNode {
26642698 arg,
26652699 push_to_cube_context,
26662700 subqueries. clone ( ) ,
2701+ used_members. as_deref_mut ( ) ,
26672702 )
26682703 . await ?;
26692704 sql_query = query;
@@ -2678,6 +2713,7 @@ impl CubeScanWrapperNode {
26782713 arg,
26792714 push_to_cube_context,
26802715 subqueries. clone ( ) ,
2716+ used_members. as_deref_mut ( ) ,
26812717 )
26822718 . await ?;
26832719 sql_query = query;
@@ -2692,6 +2728,7 @@ impl CubeScanWrapperNode {
26922728 arg,
26932729 push_to_cube_context,
26942730 subqueries. clone ( ) ,
2731+ used_members. as_deref_mut ( ) ,
26952732 )
26962733 . await ?;
26972734 sql_query = query;
@@ -2728,6 +2765,7 @@ impl CubeScanWrapperNode {
27282765 * expr,
27292766 push_to_cube_context,
27302767 subqueries. clone ( ) ,
2768+ used_members. as_deref_mut ( ) ,
27312769 )
27322770 . await ?;
27332771 sql_query = query;
@@ -2740,6 +2778,7 @@ impl CubeScanWrapperNode {
27402778 expr,
27412779 push_to_cube_context,
27422780 subqueries. clone ( ) ,
2781+ used_members. as_deref_mut ( ) ,
27432782 )
27442783 . await ?;
27452784 sql_query = query;
@@ -2771,6 +2810,7 @@ impl CubeScanWrapperNode {
27712810 * expr,
27722811 push_to_cube_context,
27732812 subqueries. clone ( ) ,
2813+ used_members. as_deref_mut ( ) ,
27742814 )
27752815 . await ?;
27762816 sql_query = query;
@@ -2781,6 +2821,7 @@ impl CubeScanWrapperNode {
27812821 * subquery,
27822822 push_to_cube_context,
27832823 subqueries. clone ( ) ,
2824+ used_members,
27842825 )
27852826 . await ?;
27862827 sql_query = query;
0 commit comments