@@ -4,8 +4,8 @@ use super::{
44 security_context:: { NativeSecurityContext , SecurityContext } ,
55 sql_utils:: { NativeSqlUtils , SqlUtils } ,
66} ;
7- use crate :: planner:: sql_evaluator:: SqlCallArg ;
87use crate :: utils:: UniqueVector ;
8+ use crate :: { cube_bridge:: base_tools:: BaseTools , planner:: sql_evaluator:: SqlCallArg } ;
99use cubenativeutils:: wrappers:: make_proxy;
1010use cubenativeutils:: wrappers:: object:: { NativeFunction , NativeStruct , NativeType } ;
1111use cubenativeutils:: wrappers:: serializer:: {
@@ -127,33 +127,12 @@ impl ProxyStateWeak {
127127 }
128128}
129129
130- #[ derive( Default ) ]
131- pub struct MemberSqlStruct {
132- pub sql_fn : Option < String > ,
133- pub to_string_fn : Option < String > ,
134- pub properties : HashMap < String , MemberSqlArg > ,
135- }
136-
137- pub enum ContextSymbolArg {
138- SecurityContext ( Rc < dyn SecurityContext > ) ,
139- SqlUtils ( Rc < dyn SqlUtils > ) ,
140- FilterParams ( Rc < dyn FilterParams > ) ,
141- FilterGroup ( Rc < dyn FilterGroup > ) ,
142- }
143-
144- pub enum MemberSqlArg {
145- String ( String ) ,
146- Struct ( MemberSqlStruct ) ,
147- ContextSymbol ( ContextSymbolArg ) ,
148- }
149-
150130pub trait MemberSql {
151- fn call ( & self , args : Vec < MemberSqlArg > ) -> Result < String , CubeError > ;
152131 fn args_names ( & self ) -> & Vec < String > ;
153- fn need_deps_resolve ( & self ) -> bool ;
154132 fn as_any ( self : Rc < Self > ) -> Rc < dyn Any > ;
155133 fn compile_template_sql (
156134 & self ,
135+ base_tools : Rc < dyn BaseTools > ,
157136 security_context : Rc < dyn SecurityContext > ,
158137 ) -> Result < ( String , SqlTemplateArgs ) , CubeError > ;
159138}
@@ -163,70 +142,6 @@ pub struct NativeMemberSql<IT: InnerTypes> {
163142 args_names : Vec < String > ,
164143}
165144
166- impl < IT : InnerTypes > NativeSerialize < IT > for MemberSqlStruct {
167- fn to_native (
168- & self ,
169- context : NativeContextHolder < IT > ,
170- ) -> Result < NativeObjectHandle < IT > , CubeError > {
171- let res = context. empty_struct ( ) ?;
172- for ( k, v) in self . properties . iter ( ) {
173- res. set_field ( k, v. to_native ( context. clone ( ) ) ?) ?;
174- }
175- if let Some ( to_string_fn) = & self . to_string_fn {
176- res. set_field (
177- "toString" ,
178- NativeObjectHandle :: new ( context. to_string_fn ( to_string_fn. clone ( ) ) ?. into_object ( ) ) ,
179- ) ?;
180- }
181- if let Some ( sql_fn) = & self . sql_fn {
182- res. set_field (
183- "__sql_fn" ,
184- NativeObjectHandle :: new ( context. to_string_fn ( sql_fn. clone ( ) ) ?. into_object ( ) ) ,
185- ) ?;
186- }
187- Ok ( NativeObjectHandle :: new ( res. into_object ( ) ) )
188- }
189- }
190-
191- impl < IT : InnerTypes > NativeSerialize < IT > for MemberSqlArg {
192- fn to_native (
193- & self ,
194- context_holder : NativeContextHolder < IT > ,
195- ) -> Result < NativeObjectHandle < IT > , CubeError > {
196- let res = match self {
197- MemberSqlArg :: String ( s) => s. to_native ( context_holder. clone ( ) ) ,
198- MemberSqlArg :: Struct ( s) => s. to_native ( context_holder. clone ( ) ) ,
199- MemberSqlArg :: ContextSymbol ( symbol) => match symbol {
200- ContextSymbolArg :: SecurityContext ( context) => context
201- . clone ( )
202- . as_any ( )
203- . downcast :: < NativeSecurityContext < IT > > ( )
204- . unwrap ( )
205- . to_native ( context_holder. clone ( ) ) ,
206- ContextSymbolArg :: SqlUtils ( context) => context
207- . clone ( )
208- . as_any ( )
209- . downcast :: < NativeSqlUtils < IT > > ( )
210- . unwrap ( )
211- . to_native ( context_holder. clone ( ) ) ,
212- ContextSymbolArg :: FilterParams ( params) => params
213- . clone ( )
214- . as_any ( )
215- . downcast :: < NativeFilterParams < IT > > ( )
216- . unwrap ( )
217- . to_native ( context_holder. clone ( ) ) ,
218- ContextSymbolArg :: FilterGroup ( group) => group
219- . clone ( )
220- . as_any ( )
221- . downcast :: < NativeFilterGroup < IT > > ( )
222- . unwrap ( )
223- . to_native ( context_holder. clone ( ) ) ,
224- } ,
225- } ?;
226- Ok ( NativeObjectHandle :: new ( res. into_object ( ) ) )
227- }
228- }
229-
230145impl < IT : InnerTypes > NativeMemberSql < IT > {
231146 pub fn try_new ( native_object : NativeObjectHandle < IT > ) -> Result < Self , CubeError > {
232147 let args_names = native_object. to_function ( ) ?. args_names ( ) ?;
@@ -242,13 +157,16 @@ impl<IT: InnerTypes> NativeMemberSql<IT> {
242157 path : Vec < String > ,
243158 ) -> Result < NativeObjectHandle < CIT > , CubeError > {
244159 context_holder. make_proxy ( None , move |inner_context, _, prop| {
160+ println ! ( "!!!! into {}" , prop) ;
245161 if prop == "sql" {
162+ println ! ( "!!!! JJJJJJ" ) ;
246163 let mut path_with_sql = path. clone ( ) ;
247164 path_with_sql. push ( "sql" . to_string ( ) ) ;
248165 let index = proxy_state. insert_symbol_path ( & path_with_sql) ?;
249166 let str = SqlCallArg :: dependency ( index) ;
250167 let result = inner_context. to_string_fn ( str) ?;
251168 let result = NativeObjectHandle :: new ( result. into_object ( ) ) ;
169+ println ! ( "!!!! LLLLLL" ) ;
252170 return Ok ( Some ( result) ) ;
253171 }
254172 if prop == "toString" || prop == "valueOf" {
@@ -544,38 +462,20 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
544462 fn as_any ( self : Rc < Self > ) -> Rc < dyn Any > {
545463 self . clone ( )
546464 }
547- fn call ( & self , args : Vec < MemberSqlArg > ) -> Result < String , CubeError > {
548- if args. len ( ) != self . args_names . len ( ) {
549- return Err ( CubeError :: internal ( format ! (
550- "Invalid arguments count for MemberSql call: expected {}, got {}" ,
551- self . args_names. len( ) ,
552- args. len( )
553- ) ) ) ;
554- }
555- let context_holder = NativeContextHolder :: < IT > :: new ( self . native_object . get_context ( ) ) ;
556- let native_args = args
557- . into_iter ( )
558- . map ( |a| a. to_native ( context_holder. clone ( ) ) )
559- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
560-
561- let res = self . native_object . to_function ( ) ?. call ( native_args) ?;
562- NativeDeserializer :: deserialize :: < IT , String > ( res)
563- }
564465 fn args_names ( & self ) -> & Vec < String > {
565466 & self . args_names
566467 }
567- fn need_deps_resolve ( & self ) -> bool {
568- !self . args_names . is_empty ( )
569- }
570468
571469 fn compile_template_sql (
572470 & self ,
471+ base_tools : Rc < dyn BaseTools > ,
573472 security_context : Rc < dyn SecurityContext > ,
574473 ) -> Result < ( String , SqlTemplateArgs ) , CubeError > {
575474 let state = ProxyState :: new ( ) ;
576475 let weak_state = state. weak ( ) ;
577476 let context_holder = NativeContextHolder :: < IT > :: new ( self . native_object . get_context ( ) ) ;
578477 let mut proxy_args = vec ! [ ] ;
478+ println ! ( "!!! RRRR" ) ;
579479 for arg in self . args_names . iter ( ) . cloned ( ) {
580480 let proxy_arg = if arg == "FILTER_PARAMS" {
581481 Self :: filter_params_proxy ( context_holder. clone ( ) , weak_state. clone ( ) ) ?
@@ -601,16 +501,28 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
601501 weak_state. clone ( ) ,
602502 context_obj,
603503 ) ?
504+ } else if arg == "SQL_UTILS" {
505+ base_tools
506+ . sql_utils_for_rust ( ) ?
507+ . as_any ( )
508+ . downcast :: < NativeSqlUtils < IT > > ( )
509+ . unwrap ( )
510+ . to_native ( context_holder. clone ( ) ) ?
604511 } else {
605512 let path = vec ! [ arg] ;
606513 Self :: property_proxy ( context_holder. clone ( ) , weak_state. clone ( ) , path. clone ( ) ) ?
607514 } ;
608515 proxy_args. push ( proxy_arg) ;
609516 }
517+ println ! ( "!!! KKKKK" ) ;
610518 let native_func = self . native_object . to_function ( ) ?;
519+ println ! ( "!!! 1111 {}" , proxy_args. len( ) ) ;
611520 let evaluation_result = native_func. call ( proxy_args) ?;
521+ println ! ( "!!! 2222" ) ;
612522 let template = String :: from_native ( evaluation_result) ?;
523+ println ! ( "!!! 3333" ) ;
613524 let sql_args = state. get_args ( ) ?;
525+ println ! ( "!!! templ: {}" , template) ;
614526
615527 Ok ( ( template, sql_args) )
616528 }
0 commit comments