diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b9c647a7..15eebae3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -21,6 +21,7 @@ chrono = { version = "0.4.35", default-features = false, features = ["clock"] } clap = { version = "4.4", features = ["derive", "env"] } comfy-table = "7.1" csv = "1.3" +databend-common-ast = "0.0.1" fern = { version = "0.6", features = ["colored"] } indicatif = "0.17" log = "0.4" @@ -28,7 +29,6 @@ logos = "0.13" once_cell = "1.18" rustyline = "12.0" serde = { version = "1.0", features = ["derive"] } -sqlformat = "0.2" strum = "0.25" strum_macros = "0.25" terminal_size = "0.3" diff --git a/cli/src/ast/mod.rs b/cli/src/ast/mod.rs index 74962837..c2a2f3d2 100644 --- a/cli/src/ast/mod.rs +++ b/cli/src/ast/mod.rs @@ -14,7 +14,10 @@ mod tokenizer; -use sqlformat::{Indent, QueryParams}; +use databend_common_ast::{ + ast::pretty_statement, + parser::{parse_sql, Dialect}, +}; pub use tokenizer::*; use crate::session::QueryKind; @@ -24,10 +27,7 @@ pub fn format_query(query: &str) -> String { if kind == QueryKind::Put || kind == QueryKind::Get { return query.to_owned(); } - let options = sqlformat::FormatOptions { - indent: Indent::Spaces(2), - uppercase: true, - lines_between_queries: 1, - }; - sqlformat::format(query, &QueryParams::None, options) + let tokens = databend_common_ast::parser::tokenize_sql(query).unwrap(); + let (stmt, _) = parse_sql(&tokens, Dialect::Experimental).unwrap(); + pretty_statement(stmt, 80).unwrap() }