Skip to content

Commit

Permalink
Merge pull request #6135 from sundy-li/short-sql2
Browse files Browse the repository at this point in the history
chore(sql): fix short sql
  • Loading branch information
mergify[bot] authored Jun 22, 2022
2 parents 28eb03f + 997c185 commit 94c26c3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
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);
}
}

0 comments on commit 94c26c3

Please sign in to comment.