Skip to content

Commit e2eaf0c

Browse files
committed
Fix:Just Test
1 parent 86ad9db commit e2eaf0c

File tree

2 files changed

+94
-19
lines changed

2 files changed

+94
-19
lines changed

tests/example.slt

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,62 @@
11
statement ok
2-
INSERT INTO telemetry_events (projectId, id, timestamp, traceId, spanId, eventType, durationNs, spanName, endpointHash, shapeHash, sdkType)
3-
VALUES ('proj1', 'rec1', '2025-03-19T12:00:00Z', 'trace1', 'span1', 'span', 1000, 'test_span', 'hash1', 'hash2', 'rust')
2+
INSERT INTO telemetry_events (
3+
projectid, id, timestamp, traceid, spanid, eventtype, status, endtime, durationns, spanname,
4+
spankind, parentspanid, tracestate, haserror, severitytext, severitynumber, body, httpmethod,
5+
httpurl, httproute, httphost, httpstatuscode, pathparams, queryparams, requestbody, responsebody,
6+
sdktype, serviceversion, errors, tags, parentid, dbsystem, dbname, dbstatement, dboperation,
7+
rpcsystem, rpcservice, rpcmethod, endpointhash, shapehash, formathashes, fieldhashes, attributes,
8+
events, links, resource, instrumentationscope
9+
) VALUES (
10+
'PROJECT_ID_PLACEHOLDER',
11+
'ID_PLACEHOLDER',
12+
'2023-11-25T12:34:56.789Z',
13+
'trace123',
14+
'span123',
15+
'ERROR',
16+
'ok',
17+
'2023-11-25T12:35:56.000Z',
18+
60000000000,
19+
'sample_span',
20+
'server',
21+
'parent123',
22+
'state123',
23+
FALSE,
24+
'INFO',
25+
1,
26+
'{"message": "Sample event body"}',
27+
'GET',
28+
'http://localhost/api/test',
29+
'/api/test',
30+
'localhost',
31+
200,
32+
'{"id": "1"}',
33+
'{"q": "test"}',
34+
'{"key": "value"}',
35+
'{"result": "ok"}',
36+
'rust',
37+
'v1.0',
38+
'{}',
39+
'["tag1", "tag2"]',
40+
'parent0',
41+
'postgres',
42+
'sample_db',
43+
'SELECT * FROM table',
44+
'read',
45+
'grpc',
46+
'sample_service',
47+
'GetSample',
48+
'endpointhash123',
49+
'shapehash123',
50+
'["format1", "format2"]',
51+
'["field1", "field2"]',
52+
'{"attr": "value"}',
53+
'{"event": "value"}',
54+
'{"link": "value"}',
55+
'{"resource": "value"}',
56+
'{"scope": "value"}'
57+
)
458

559
query T
6-
SELECT projectId, id, timestamp FROM telemetry_events WHERE projectId = 'proj1'
60+
SELECT projectid, id, timestamp FROM telemetry_events WHERE projectid = 'PROJECT_ID_PLACEHOLDER'
761
----
8-
proj1 rec1 2025-03-19T12:00:00Z
62+
PROJECT_ID_PLACEHOLDER ID_PLACEHOLDER 2023-11-25T12:34:56.789Z

tests/sqllogictest.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)