11use crate :: {
2- catalog:: iceberg:: memory_catalog,
2+ catalog:: { Catalog , iceberg:: memory_catalog} ,
33 dsl:: {
4- analyzer:: hir:: Value ,
4+ analyzer:: hir:: { CoreData , LogicalOp , Materializable , Udf , Value } ,
55 compile:: { Config , compile_hir} ,
66 engine:: { Continuation , Engine , EngineResponse } ,
7- utils:: retriever:: MockRetriever ,
7+ utils:: retriever:: { MockRetriever , Retriever } ,
88 } ,
99 memo:: MemoryMemo ,
10- optimizer:: { OptimizeRequest , Optimizer , hir_cir:: into_cir:: value_to_logical} ,
10+ optimizer:: { ClientRequest , OptimizeRequest , Optimizer , hir_cir:: into_cir:: value_to_logical} ,
1111} ;
1212use std:: { collections:: HashMap , sync:: Arc , time:: Duration } ;
13- use tokio:: { sync:: mpsc, time:: timeout} ;
13+ use tokio:: {
14+ sync:: mpsc,
15+ time:: { sleep, timeout} ,
16+ } ;
17+
18+ pub async fn properties (
19+ args : Vec < Value > ,
20+ _catalog : Arc < dyn Catalog > ,
21+ retriever : Arc < dyn Retriever > ,
22+ ) -> Value {
23+ let arg = args[ 0 ] . clone ( ) ;
24+ let group_id = match & arg. data {
25+ CoreData :: Logical ( Materializable :: Materialized ( LogicalOp { group_id, .. } ) ) => {
26+ group_id. unwrap ( )
27+ }
28+ CoreData :: Logical ( Materializable :: UnMaterialized ( group_id) ) => * group_id,
29+ _ => panic ! ( "Expected a logical plan" ) ,
30+ } ;
31+
32+ retriever. get_properties ( group_id) . await
33+ }
1434
1535async fn run_demo ( ) {
1636 // Compile the HIR.
1737 let config = Config :: new ( "src/demo/demo.opt" . into ( ) ) ;
18- let udfs = HashMap :: new ( ) ;
38+
39+ // Create a properties UDF.
40+ let properties_udf = Udf {
41+ func : Arc :: new ( |args, catalog, retriever| {
42+ Box :: pin ( async move { properties ( args, catalog, retriever) . await } )
43+ } ) ,
44+ } ;
45+
46+ // Create the UDFs HashMap.
47+ let mut udfs = HashMap :: new ( ) ;
48+ udfs. insert ( "properties" . to_string ( ) , properties_udf) ;
49+
50+ // Compile with the config and UDFs.
1951 let hir = compile_hir ( config, udfs) . unwrap ( ) ;
2052
2153 // Create necessary components.
@@ -35,15 +67,15 @@ async fn run_demo() {
3567 let optimize_channel = Optimizer :: launch ( memo, catalog, hir) ;
3668 let ( tx, mut rx) = mpsc:: channel ( 1 ) ;
3769 optimize_channel
38- . send ( OptimizeRequest {
39- plan : logical_plan,
40- physical_tx : tx,
41- } )
70+ . send ( ClientRequest :: Optimize ( OptimizeRequest {
71+ plan : logical_plan. clone ( ) ,
72+ physical_tx : tx. clone ( ) ,
73+ } ) )
4274 . await
4375 . unwrap ( ) ;
4476
45- // Timeout after 2 seconds.
46- let timeout_duration = Duration :: from_secs ( 2 ) ;
77+ // Timeout after 5 seconds.
78+ let timeout_duration = Duration :: from_secs ( 5 ) ;
4779 let result = timeout ( timeout_duration, async {
4880 while let Some ( response) = rx. recv ( ) . await {
4981 println ! ( "Received response: {:?}" , response) ;
@@ -55,6 +87,13 @@ async fn run_demo() {
5587 Ok ( _) => println ! ( "Finished receiving responses." ) ,
5688 Err ( _) => println ! ( "Timed out after 5 seconds." ) ,
5789 }
90+
91+ // Dump the memo (debug utility).
92+ optimize_channel
93+ . send ( ClientRequest :: DumpMemo )
94+ . await
95+ . unwrap ( ) ;
96+ sleep ( Duration :: from_secs ( 10 ) ) . await ;
5897}
5998
6099#[ cfg( test) ]
0 commit comments