Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sql): fix short sql #6135

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion query/src/sql/sql_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl SQLCommon {
}

pub fn short_sql(query: &str) -> String {
if query.len() >= 64 && query[..=6].eq_ignore_ascii_case("INSERT") {
let query = query.trim_start();
if query.len() >= 64 && query[..6].eq_ignore_ascii_case("INSERT") {
format!("{}...", &query[..64])
} else {
query.to_string()
Expand Down
1 change: 1 addition & 0 deletions query/tests/it/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ mod optimizer;
mod parsers;
mod plan_parser;
mod planner;
mod sql_common;
mod sql_parser;
mod statements;
42 changes: 42 additions & 0 deletions query/tests/it/sql/sql_common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2021 Datafuse Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_query::sql::SQLCommon;

#[test]
fn short_sql_test() {
{
let sql = "select 1";
assert_eq!(SQLCommon::short_sql(sql), sql);
}

{
let sql = "insert into a select xxxxxx1";
assert_eq!(SQLCommon::short_sql(sql), sql);
}

let size = "INSERT INTO ".len();

{
let sql = format!("INSERT INTO {}", "x".repeat(100));
let expect = format!("INSERT INTO {}...", "x".repeat(64 - size));
assert_eq!(SQLCommon::short_sql(&sql), expect);
}

{
let sql = format!("inSerT INTO {}", "x".repeat(100));
let expect = format!("inSerT INTO {}...", "x".repeat(64 - size));
assert_eq!(SQLCommon::short_sql(&sql), expect);
}
}