Skip to content

Commit

Permalink
chore(mysqldump): support mysqldump dump schema with:mysqldump --set-…
Browse files Browse the repository at this point in the history
…gtid-purged=OFF --no-tablespaces --no-data --triggers=0 --column-statistics=0 -uroot -h127.0.0.1 -P3307 dd1
  • Loading branch information
BohuTANG committed Apr 20, 2022
1 parent 0f576a7 commit f6bdec8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions query/src/interpreters/interpreter_table_describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Interpreter for DescribeTableInterpreter {
let mut types: Vec<String> = vec![];
let mut nulls: Vec<String> = vec![];
let mut default_exprs: Vec<String> = vec![];
let mut extras: Vec<String> = vec![];

for field in schema.fields().iter() {
names.push(field.name().to_string());
Expand All @@ -78,6 +79,7 @@ impl Interpreter for DescribeTableInterpreter {
default_exprs.push(format!("{}", value));
}
}
extras.push("".to_string());
}

let desc_schema = self.plan.schema();
Expand All @@ -87,6 +89,7 @@ impl Interpreter for DescribeTableInterpreter {
Series::from_data(types),
Series::from_data(nulls),
Series::from_data(default_exprs),
Series::from_data(extras),
]);

Ok(Box::pin(DataBlockStream::create(desc_schema, None, vec![
Expand Down
7 changes: 6 additions & 1 deletion query/src/servers/mysql/mysql_federated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ impl MySQLFederated {
("(?i)^(SET AUTOCOMMIT(.*))", None),
("(?i)^(SET sql_mode(.*))", None),
("(?i)^(SET @@(.*))", None),
("(?i)^(SET SESSION TRANSACTION ISOLATION LEVEL(.*))", None),
// mysqldump.
("(?i)^(SET SESSION(.*))", None),
("(?i)^(SET SQL_QUOTE_SHOW_CREATE(.*))", None),
("(?i)^(LOCK TABLES(.*))", None),
("(?i)^(UNLOCK TABLES(.*))", None),
("(?i)^(SELECT LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA FROM INFORMATION_SCHEMA.FILES(.*))", None),
// DBeaver.
("(?i)^(SHOW WARNINGS)", None),
("(?i)^(/\\* ApplicationName=(.*)SHOW WARNINGS)", None),
Expand Down
13 changes: 13 additions & 0 deletions query/src/sql/parsers/parser_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use sqlparser::keywords::Keyword;
use sqlparser::parser::ParserError;
use sqlparser::tokenizer::Token;

use crate::sql::statements::DfDescribeTable;
use crate::sql::statements::DfShowDatabases;
use crate::sql::statements::DfShowFunctions;
use crate::sql::statements::DfShowKind;
Expand Down Expand Up @@ -124,4 +125,16 @@ impl<'a> DfParser<'a> {
_ => self.expected("like or where", tok),
}
}

// parse `show fields from` statement
// Convert it to the `desc <table>`
pub(crate) fn parse_show_fields(&mut self) -> Result<DfStatement<'a>, ParserError> {
if !self.consume_token("FROM") {
self.expect_token("from")?;
}

let table_name = self.parser.parse_object_name()?;
let desc = DfDescribeTable { name: table_name };
Ok(DfStatement::DescribeTable(desc))
}
}
2 changes: 2 additions & 0 deletions query/src/sql/sql_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ impl<'a> DfParser<'a> {
Ok(DfStatement::ShowSettings(DfShowSettings))
} else if self.consume_token("CREATE") {
self.parse_show_create()
} else if self.consume_token("FIELDS") {
self.parse_show_fields()
} else if self.consume_token("PROCESSLIST") {
Ok(DfStatement::ShowProcessList(DfShowProcessList))
} else if self.consume_token("METRICS") {
Expand Down
1 change: 1 addition & 0 deletions query/src/sql/statements/statement_describe_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl DfDescribeTable {
DataField::new("Type", Vu8::to_data_type()),
DataField::new("Null", Vu8::to_data_type()),
DataField::new("Default", Vu8::to_data_type()),
DataField::new("Extra", Vu8::to_data_type()),
])
}
}
12 changes: 12 additions & 0 deletions query/tests/it/sql/parsers/parser_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use common_exception::Result;
use databend_query::sql::statements::DfDescribeTable;
use databend_query::sql::statements::DfShowDatabases;
use databend_query::sql::statements::DfShowEngines;
use databend_query::sql::statements::DfShowFunctions;
Expand Down Expand Up @@ -337,3 +338,14 @@ fn show_tab_stat_test() -> Result<()> {

Ok(())
}

#[test]
fn show_fields_from() -> Result<()> {
expect_parse_ok(
"show fields from t2",
DfStatement::DescribeTable(DfDescribeTable {
name: name: ObjectName(vec![Ident::new("t2")]),
}),
)?;
Ok(())
}

0 comments on commit f6bdec8

Please sign in to comment.