llkv_sql/tpch.rs
1use regex::Regex;
2use std::sync::OnceLock;
3
4/// Strip TPC-H `CONNECT TO database;` statements from the input SQL script.
5///
6/// The upstream TPC-H referential integrity scripts use a multi-database syntax
7/// that LLKV does not implement. Treat these directives as no-ops so the
8/// remainder of the script can be parsed and executed without modification.
9pub fn strip_tpch_connect_statements(sql: &str) -> String {
10 static CONNECT_REGEX: OnceLock<Regex> = OnceLock::new();
11 let re = CONNECT_REGEX.get_or_init(|| {
12 Regex::new(r#"(?im)^\s*CONNECT\s+TO\s+(?:[A-Za-z0-9_]+|'[^']+'|"[^"]+")\s*;\s*"#)
13 .expect("valid CONNECT TO regex")
14 });
15 re.replace_all(sql, "").to_string()
16}