Skip to content

Commit 8df2e0d

Browse files
Shefeek JinnahShefeek Jinnah
authored andcommitted
Clean up sqllogic test runner
1 parent b1a9da1 commit 8df2e0d

1 file changed

Lines changed: 49 additions & 38 deletions

File tree

tests/sqllogictest_runner.rs

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ fn extract_rows(
7979
}
8080

8181
/// DuckLake database adapter for sqllogictest
82-
///
83-
/// This adapter maintains both:
84-
/// - DuckDB connection for write operations (CREATE, INSERT, etc.)
85-
/// - DataFusion context for read operations via datafusion-ducklake
8682
struct DuckLakeDB {
8783
ctx: SessionContext,
8884
duckdb_conn: Connection,
@@ -113,10 +109,8 @@ impl DuckLakeDB {
113109
})
114110
}
115111

116-
/// Process ATTACH statement and store catalog info (defer registration)
112+
/// Process ATTACH statement and store catalog info
117113
fn handle_attach(&mut self, sql: &str) -> Result<(), TestError> {
118-
// Note: __TEST_DIR__ and env vars are already replaced in preprocessor
119-
120114
// Create data directory (either explicit or default)
121115
if let Some(data_path) = extract_quoted_value(sql, "DATA_PATH '") {
122116
std::fs::create_dir_all(data_path).map_err(|e| TestError(e.to_string()))?;
@@ -188,12 +182,7 @@ impl DuckLakeDB {
188182
/// Rewrite table references to add 'main' schema when missing
189183
/// E.g., "catalog.table" -> "catalog.main.table"
190184
fn rewrite_table_references(&self, sql: &str, catalog_name: &str) -> String {
191-
// Simple regex-based rewriting: look for catalog.table_name patterns
192-
// and replace with catalog.main.table_name
193-
// This is a simple heuristic - for production use a proper SQL parser
194-
195-
// Find all occurrences of "catalog.table"
196-
// Replace with "catalog.main.table" if not already "catalog.something.table"
185+
// Simple heuristic - for production use a proper SQL parser
197186
let parts: Vec<&str> = sql.split_whitespace().collect();
198187
let mut new_parts = Vec::new();
199188

@@ -249,7 +238,6 @@ impl AsyncDB for DuckLakeDB {
249238

250239
// Handle USE
251240
if sql_lower.starts_with("use ") {
252-
// Just track the current catalog, don't execute in DuckDB
253241
if let Some(catalog_name) = sql.split_whitespace().nth(1) {
254242
self.current_catalog = Some(catalog_name.to_string());
255243
}
@@ -259,9 +247,7 @@ impl AsyncDB for DuckLakeDB {
259247
// Handle SHOW TABLES
260248
if sql_lower == "show tables" {
261249
if let Some(catalog_name) = &self.current_catalog {
262-
// Use DataFusion's catalog API directly
263250
if let Some(catalog) = self.ctx.catalog(catalog_name) {
264-
// Get the 'main' schema (default schema for DuckLake)
265251
if let Some(schema) = catalog.schema("main") {
266252
let table_names = schema.table_names();
267253
let rows: Vec<Vec<String>> =
@@ -288,17 +274,13 @@ impl AsyncDB for DuckLakeDB {
288274
// Handle write operations via DuckDB
289275
if self.is_write_operation(sql) {
290276
self.duckdb_conn.execute(sql, [])?;
291-
// Sync catalog after writes to pick up new tables
292277
self.sync_catalog()?;
293278
return Ok(sqllogictest::DBOutput::StatementComplete(0));
294279
}
295280

296-
// Handle query operations via DataFusion + datafusion-ducklake
281+
// Handle query operations via DataFusion
297282
if self.is_query_operation(sql) {
298-
// Ensure catalog is synced before queries
299283
self.sync_catalog()?;
300-
// Rewrite queries to add 'main' schema if missing
301-
// E.g., "SELECT * FROM ducklake.test" -> "SELECT * FROM ducklake.main.test"
302284
let rewritten_sql = if let Some(catalog_name) = &self.current_catalog {
303285
self.rewrite_table_references(sql, catalog_name)
304286
} else {
@@ -434,7 +416,6 @@ async fn run_test_file(test_name: &str) -> Result<(), Box<dyn std::error::Error>
434416
// Test Cases
435417
// ============================================================================
436418

437-
/// Helper to run tests from subdirectories
438419
async fn run_test_from_folder(
439420
folder: &str,
440421
test_name: &str,
@@ -443,32 +424,62 @@ async fn run_test_from_folder(
443424
run_test_file(&test_path).await
444425
}
445426

446-
// ----------------------------------------------------------------------------
447427
// Top-level tests
448-
// ----------------------------------------------------------------------------
449428

450429
#[tokio::test]
451430
async fn test_ducklake_basic() -> Result<(), Box<dyn std::error::Error>> {
452431
run_test_file("ducklake_basic.test").await
453432
}
454433

455-
// ----------------------------------------------------------------------------
456-
// Insert folder tests - Testing SELECT queries after INSERT
457-
// ----------------------------------------------------------------------------
434+
// Insert tests
458435

459436
#[tokio::test]
460437
async fn test_insert_column_list() -> Result<(), Box<dyn std::error::Error>> {
461438
run_test_from_folder("insert", "insert_column_list.test").await
462439
}
463440

464-
// Skipped: Tests DuckDB INSERT row counts, not datafusion-ducklake reads
465-
// #[tokio::test]
466-
// async fn test_insert_into_self() -> Result<(), Box<dyn std::error::Error>> {
467-
// run_test_from_folder("insert", "insert_into_self.test").await
468-
// }
469-
470-
// Skipped: Uses DuckDB glob() function and tests INSERT row counts
471-
// #[tokio::test]
472-
// async fn test_insert_file_size() -> Result<(), Box<dyn std::error::Error>> {
473-
// run_test_from_folder("insert", "insert_file_size.test").await
474-
// }
441+
#[tokio::test]
442+
async fn test_insert_into_self() -> Result<(), Box<dyn std::error::Error>> {
443+
run_test_from_folder("insert", "insert_into_self.test").await
444+
}
445+
446+
#[tokio::test]
447+
async fn test_insert_file_size() -> Result<(), Box<dyn std::error::Error>> {
448+
run_test_from_folder("insert", "insert_file_size.test").await
449+
}
450+
451+
// Delete tests
452+
453+
#[tokio::test]
454+
async fn test_empty_delete() -> Result<(), Box<dyn std::error::Error>> {
455+
run_test_from_folder("delete", "empty_delete.test").await
456+
}
457+
458+
#[tokio::test]
459+
async fn test_basic_delete() -> Result<(), Box<dyn std::error::Error>> {
460+
run_test_from_folder("delete", "basic_delete.test").await
461+
}
462+
463+
#[tokio::test]
464+
async fn test_multi_deletes() -> Result<(), Box<dyn std::error::Error>> {
465+
run_test_from_folder("delete", "multi_deletes.test").await
466+
}
467+
468+
// General tests
469+
470+
#[tokio::test]
471+
async fn test_ducklake_read_only() -> Result<(), Box<dyn std::error::Error>> {
472+
run_test_from_folder("general", "ducklake_read_only.test").await
473+
}
474+
475+
// Type tests
476+
477+
#[tokio::test]
478+
async fn test_floats() -> Result<(), Box<dyn std::error::Error>> {
479+
run_test_from_folder("types", "floats.test").await
480+
}
481+
482+
#[tokio::test]
483+
async fn test_timestamp() -> Result<(), Box<dyn std::error::Error>> {
484+
run_test_from_folder("types", "timestamp.test").await
485+
}

0 commit comments

Comments
 (0)