@@ -8,7 +8,7 @@ mod sqllogictest_tests {
88 use timefusion:: utils:: value_to_string;
99 use std:: error:: Error as StdError ;
1010 use datafusion:: error:: DataFusionError ;
11- use log :: debug ; // Add logging for debugging
11+ use uuid :: Uuid ;
1212
1313 // Custom error type to wrap anyhow::Error
1414 #[ derive( Debug ) ]
@@ -41,6 +41,8 @@ mod sqllogictest_tests {
4141 // Define a custom database wrapper for sqllogictest
4242 struct TimeFusionDB {
4343 db : Arc < Database > ,
44+ project_id : String , // Store the generated projectId
45+ id : String , // Store the generated id
4446 }
4547
4648 #[ async_trait:: async_trait]
@@ -49,15 +51,25 @@ mod sqllogictest_tests {
4951 type ColumnType = DefaultColumnType ;
5052
5153 async fn run ( & mut self , sql : & str ) -> Result < DBOutput < Self :: ColumnType > , Self :: Error > {
52- debug ! ( "Executing SQL: {}" , sql) ;
53-
54- let df = self . db . query ( sql) . await . map_err ( TestError :: from) ?;
55- debug ! ( "Query executed successfully, collecting batches..." ) ;
56- let batches = df. collect ( ) . await . map_err ( TestError :: from) ?;
57- debug ! ( "Collected {} batches" , batches. len( ) ) ;
54+ // Replace placeholders with generated UUIDs
55+ let sql = sql
56+ . replace ( "PROJECT_ID_PLACEHOLDER" , & self . project_id )
57+ . replace ( "ID_PLACEHOLDER" , & self . id ) ;
58+ println ! ( "Executing SQL: {}" , sql) ;
59+
60+ let df = self . db . query ( & sql) . await . map_err ( |e| {
61+ println ! ( "Query error: {:?}" , e) ;
62+ TestError :: from ( e)
63+ } ) ?;
64+ println ! ( "Query executed successfully, collecting batches..." ) ;
65+ let batches = df. collect ( ) . await . map_err ( |e| {
66+ println ! ( "Collect error: {:?}" , e) ;
67+ TestError :: from ( e)
68+ } ) ?;
69+ println ! ( "Collected {} batches" , batches. len( ) ) ;
5870
5971 if batches. is_empty ( ) {
60- debug ! ( "No batches returned, assuming statement complete" ) ;
72+ println ! ( "No batches returned, assuming statement complete" ) ;
6173 return Ok ( DBOutput :: StatementComplete ( 0 ) ) ;
6274 }
6375
@@ -78,10 +90,10 @@ mod sqllogictest_tests {
7890 if sql. trim ( ) . to_lowercase ( ) . starts_with ( "insert" ) ||
7991 sql. trim ( ) . to_lowercase ( ) . starts_with ( "update" ) ||
8092 sql. trim ( ) . to_lowercase ( ) . starts_with ( "delete" ) {
81- debug ! ( "Returning StatementComplete with row count: {}" , row_count) ;
93+ println ! ( "Returning StatementComplete with row count: {}" , row_count) ;
8294 Ok ( DBOutput :: StatementComplete ( row_count as u64 ) )
8395 } else {
84- debug ! ( "Returning Rows with {} rows and {} columns" , rows. len( ) , batches[ 0 ] . num_columns( ) ) ;
96+ println ! ( "Returning Rows with {} rows and {} columns" , rows. len( ) , batches[ 0 ] . num_columns( ) ) ;
8597 Ok ( DBOutput :: Rows {
8698 types : vec ! [ DefaultColumnType :: Text ; batches[ 0 ] . num_columns( ) ] ,
8799 rows
@@ -100,28 +112,37 @@ mod sqllogictest_tests {
100112
101113 #[ tokio:: test]
102114 async fn run_sqllogictest ( ) -> anyhow:: Result < ( ) > {
103- // Initialize logging
104- env_logger:: init ( ) ;
115+ // Initialize logging with a default level
116+ env_logger:: Builder :: from_env ( env_logger :: Env :: default ( ) . default_filter_or ( "debug" ) ) . init ( ) ;
105117
106118 // Initialize the database
107119 let db: Arc < Database > = Arc :: new ( Database :: new ( ) . await ?) ;
108120
109121 // Use an in-memory table for testing
110122 let storage_uri = "memory://test_table" ;
111- debug ! ( "Creating events table: telemetry_events at {}" , storage_uri) ;
123+ println ! ( "Creating events table: telemetry_events at {}" , storage_uri) ;
112124 db. create_events_table ( "telemetry_events" , storage_uri) . await ?;
113125
126+ // Generate random UUIDs
127+ let project_id = Uuid :: new_v4 ( ) . to_string ( ) ;
128+ let id = Uuid :: new_v4 ( ) . to_string ( ) ;
129+ println ! ( "Generated projectId: {}, id: {}" , project_id, id) ;
130+
114131 // Create a closure that implements MakeConnection
115132 let make_db = || async {
116- Ok ( TimeFusionDB { db : db. clone ( ) } ) as Result < TimeFusionDB , TestError >
133+ Ok ( TimeFusionDB {
134+ db : db. clone ( ) ,
135+ project_id : project_id. clone ( ) ,
136+ id : id. clone ( ) ,
137+ } ) as Result < TimeFusionDB , TestError >
117138 } ;
118139
119140 // Create a runner with the connection factory
120141 let mut runner = Runner :: new ( make_db) ;
121142
122143 // Specify the path to your .slt files
123144 let test_file = "tests/example.slt" ;
124- debug ! ( "Running SQL logic test from file: {}" , test_file) ;
145+ println ! ( "Running SQL logic test from file: {}" , test_file) ;
125146
126147 // Run the tests
127148 runner. run_file_async ( test_file) . await ?;
0 commit comments