mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-18 05:50:41 +00:00
chore: update datafusion family (#6675)
* chore: update datafusion family Signed-off-by: luofucong <luofc@foxmail.com> * fix ci Signed-off-by: luofucong <luofc@foxmail.com> * use official otel-arrow-rust Signed-off-by: luofucong <luofc@foxmail.com> * rebase Signed-off-by: luofucong <luofc@foxmail.com> * use the official orc-rust Signed-off-by: luofucong <luofc@foxmail.com> * resolve PR comments Signed-off-by: luofucong <luofc@foxmail.com> * remove the empty lines Signed-off-by: luofucong <luofc@foxmail.com> * try following PR comments Signed-off-by: luofucong <luofc@foxmail.com> --------- Signed-off-by: luofucong <luofc@foxmail.com>
This commit is contained in:
@@ -15,6 +15,17 @@
|
||||
pub use sqlparser::ast::{
|
||||
visit_expressions_mut, visit_statements_mut, BinaryOperator, ColumnDef, ColumnOption,
|
||||
ColumnOptionDef, DataType, Expr, Function, FunctionArg, FunctionArgExpr, FunctionArguments,
|
||||
Ident, ObjectName, SqlOption, TableConstraint, TimezoneInfo, Value, Visit, VisitMut, Visitor,
|
||||
VisitorMut,
|
||||
Ident, ObjectName, ObjectNamePart, SqlOption, TableConstraint, TimezoneInfo, Value,
|
||||
ValueWithSpan, Visit, VisitMut, Visitor, VisitorMut,
|
||||
};
|
||||
|
||||
pub trait ObjectNamePartExt {
|
||||
fn to_string_unquoted(&self) -> String;
|
||||
}
|
||||
|
||||
impl ObjectNamePartExt for ObjectNamePart {
|
||||
fn to_string_unquoted(&self) -> String {
|
||||
let ObjectNamePart::Identifier(ident) = self;
|
||||
ident.value.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use snafu::ResultExt;
|
||||
use sqlparser::ast::{Ident, Query, Value};
|
||||
use sqlparser::ast::{Ident, ObjectNamePart, Query, Value};
|
||||
use sqlparser::dialect::Dialect;
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::parser::{Parser, ParserError, ParserOptions};
|
||||
@@ -117,7 +117,7 @@ impl ParserContext<'_> {
|
||||
|
||||
let function_name = parser.parse_identifier().context(SyntaxSnafu)?;
|
||||
parser
|
||||
.parse_function(ObjectName(vec![function_name]))
|
||||
.parse_function(vec![function_name].into())
|
||||
.context(SyntaxSnafu)
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ impl ParserContext<'_> {
|
||||
actual: self.peek_token_as_string(),
|
||||
}
|
||||
})?;
|
||||
let Value::Number(s, _) = connection_id_exp else {
|
||||
let Value::Number(s, _) = connection_id_exp.value else {
|
||||
return error::UnexpectedTokenSnafu {
|
||||
expected: "MySQL numeric connection id",
|
||||
actual: connection_id_exp.to_string(),
|
||||
@@ -304,13 +304,16 @@ impl ParserContext<'_> {
|
||||
|
||||
/// Like [canonicalize_identifier] but for [ObjectName].
|
||||
pub fn canonicalize_object_name(object_name: ObjectName) -> ObjectName {
|
||||
ObjectName(
|
||||
object_name
|
||||
.0
|
||||
.into_iter()
|
||||
.map(Self::canonicalize_identifier)
|
||||
.collect(),
|
||||
)
|
||||
object_name
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|x| {
|
||||
let ObjectNamePart::Identifier(ident) = x;
|
||||
ident
|
||||
})
|
||||
.map(Self::canonicalize_identifier)
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Simply a shortcut for sqlparser's same name method `parse_object_name`,
|
||||
|
||||
@@ -46,7 +46,7 @@ impl ParserContext<'_> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use sqlparser::ast::FunctionArguments;
|
||||
use sqlparser::ast::{FunctionArguments, ValueWithSpan};
|
||||
|
||||
use super::*;
|
||||
use crate::ast::{Expr, Function, FunctionArg, FunctionArgExpr, Value};
|
||||
@@ -71,7 +71,7 @@ mod tests {
|
||||
assert_eq!(arg_list.args.len(), 1);
|
||||
assert!(matches!(&arg_list.args[0],
|
||||
FunctionArg::Unnamed(FunctionArgExpr::Expr(
|
||||
Expr::Value(Value::SingleQuotedString(s))
|
||||
Expr::Value(ValueWithSpan { value: Value::SingleQuotedString(s), ..})
|
||||
)) if s == "test"));
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
||||
@@ -25,6 +25,7 @@ use sqlparser::keywords::Keyword;
|
||||
use sqlparser::parser::{Parser, ParserError};
|
||||
use sqlparser::tokenizer::{Token, TokenWithSpan};
|
||||
|
||||
use crate::ast::ObjectNamePartExt;
|
||||
use crate::error::{self, InvalidColumnOptionSnafu, Result, SetFulltextOptionSnafu};
|
||||
use crate::parser::ParserContext;
|
||||
use crate::parsers::create_parser::INVERTED;
|
||||
@@ -144,7 +145,7 @@ impl ParserContext<'_> {
|
||||
let new_table_name_obj =
|
||||
Self::canonicalize_object_name(new_table_name_obj_raw);
|
||||
let new_table_name = match &new_table_name_obj.0[..] {
|
||||
[table] => table.value.clone(),
|
||||
[table] => table.to_string_unquoted(),
|
||||
_ => {
|
||||
return Err(ParserError::ParserError(format!(
|
||||
"expect table name, actual: {new_table_name_obj}"
|
||||
@@ -555,6 +556,7 @@ mod tests {
|
||||
use sqlparser::ast::{ColumnDef, ColumnOption, ColumnOptionDef, DataType};
|
||||
|
||||
use super::*;
|
||||
use crate::ast::ObjectNamePartExt;
|
||||
use crate::dialect::GreptimeDbDialect;
|
||||
use crate::parser::ParseOptions;
|
||||
use crate::statements::alter::AlterDatabaseOperation;
|
||||
@@ -571,7 +573,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterDatabase { .. });
|
||||
match statement {
|
||||
Statement::AlterDatabase(alter_database) => {
|
||||
assert_eq!("test_db", alter_database.database_name().0[0].value);
|
||||
assert_eq!("test_db", alter_database.database_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_database.alter_operation();
|
||||
assert_matches!(
|
||||
@@ -600,7 +602,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterDatabase { .. });
|
||||
match statement {
|
||||
Statement::AlterDatabase(alter_database) => {
|
||||
assert_eq!("test_db", alter_database.database_name().0[0].value);
|
||||
assert_eq!("test_db", alter_database.database_name().0[0].to_string());
|
||||
let alter_operation = alter_database.alter_operation();
|
||||
assert_matches!(
|
||||
alter_operation,
|
||||
@@ -631,7 +633,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::AddColumns { .. });
|
||||
@@ -666,7 +668,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::AddColumns { .. });
|
||||
@@ -701,7 +703,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::AddColumns { .. });
|
||||
@@ -719,7 +721,6 @@ mod tests {
|
||||
name: None,
|
||||
option: ColumnOption::Null,
|
||||
}],
|
||||
collation: None,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -728,7 +729,6 @@ mod tests {
|
||||
name: Ident::new("tagl_i"),
|
||||
data_type: DataType::String(None),
|
||||
options: vec![],
|
||||
collation: None,
|
||||
},
|
||||
),
|
||||
];
|
||||
@@ -759,7 +759,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter) => {
|
||||
assert_eq!(alter.table_name.0[0].value, "test");
|
||||
assert_eq!(alter.table_name.0[0].to_string(), "test");
|
||||
assert_matches!(
|
||||
alter.alter_operation,
|
||||
AlterTableOperation::AddColumns { .. }
|
||||
@@ -771,7 +771,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: Ident::new("a"),
|
||||
data_type: DataType::Integer(None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
location: None,
|
||||
@@ -781,7 +780,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: Ident::new("b"),
|
||||
data_type: DataType::String(None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
location: None,
|
||||
@@ -791,7 +789,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: Ident::new("c"),
|
||||
data_type: DataType::Int(None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
location: None,
|
||||
@@ -831,7 +828,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::DropColumn { .. });
|
||||
@@ -870,7 +867,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(
|
||||
@@ -904,7 +901,7 @@ mod tests {
|
||||
|
||||
match result_1.remove(0) {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(
|
||||
@@ -935,7 +932,7 @@ mod tests {
|
||||
|
||||
match result_2.remove(0) {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].value);
|
||||
assert_eq!("my_metric_1", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(
|
||||
@@ -976,7 +973,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_matches!(alter_operation, AlterTableOperation::RenameTable { .. });
|
||||
@@ -999,7 +996,7 @@ mod tests {
|
||||
let Statement::AlterTable(alter) = &result[0] else {
|
||||
unreachable!()
|
||||
};
|
||||
assert_eq!("test_table", alter.table_name.0[0].value);
|
||||
assert_eq!("test_table", alter.table_name.0[0].to_string());
|
||||
let AlterTableOperation::SetTableOptions { options } = &alter.alter_operation else {
|
||||
unreachable!()
|
||||
};
|
||||
@@ -1020,7 +1017,7 @@ mod tests {
|
||||
let Statement::AlterTable(alter) = &result[0] else {
|
||||
unreachable!()
|
||||
};
|
||||
assert_eq!("test_table", alter.table_name.0[0].value);
|
||||
assert_eq!("test_table", alter.table_name.0[0].to_string());
|
||||
let AlterTableOperation::UnsetTableOptions { keys } = &alter.alter_operation else {
|
||||
unreachable!()
|
||||
};
|
||||
@@ -1075,7 +1072,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
match alter_operation {
|
||||
@@ -1114,7 +1111,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_eq!(
|
||||
@@ -1156,7 +1153,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
match alter_operation {
|
||||
@@ -1178,7 +1175,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].to_string());
|
||||
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
assert_eq!(
|
||||
@@ -1257,7 +1254,10 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!(
|
||||
"test_table",
|
||||
alter_table.table_name().0[0].to_string_unquoted()
|
||||
);
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
match alter_operation {
|
||||
AlterTableOperation::DropDefaults { columns } => {
|
||||
@@ -1295,7 +1295,7 @@ mod tests {
|
||||
assert_matches!(statement, Statement::AlterTable { .. });
|
||||
match statement {
|
||||
Statement::AlterTable(alter_table) => {
|
||||
assert_eq!("test_table", alter_table.table_name().0[0].value);
|
||||
assert_eq!("test_table", alter_table.table_name().to_string());
|
||||
let alter_operation = alter_table.alter_operation();
|
||||
match alter_operation {
|
||||
AlterTableOperation::SetDefaults { defaults } => {
|
||||
|
||||
@@ -598,8 +598,14 @@ mod tests {
|
||||
};
|
||||
let trigger_name = alter.trigger_name.0;
|
||||
assert_eq!(trigger_name.len(), 2);
|
||||
assert_eq!(trigger_name[0].value, "public");
|
||||
assert_eq!(trigger_name[1].value, "old_trigger");
|
||||
assert_eq!(
|
||||
trigger_name
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
"public old_trigger"
|
||||
);
|
||||
assert_eq!(alter.operation.rename, Some("newTrigger".to_string()));
|
||||
}
|
||||
|
||||
|
||||
@@ -254,20 +254,8 @@ mod tests {
|
||||
else {
|
||||
unreachable!()
|
||||
};
|
||||
let (catalog, schema, table) =
|
||||
if let [catalog, schema, table] = ©_table.table_name.0[..] {
|
||||
(
|
||||
catalog.value.clone(),
|
||||
schema.value.clone(),
|
||||
table.value.clone(),
|
||||
)
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
assert_eq!("catalog0", catalog);
|
||||
assert_eq!("schema0", schema);
|
||||
assert_eq!("tbl", table);
|
||||
let table = copy_table.table_name.to_string();
|
||||
assert_eq!("catalog0.schema0.tbl", table);
|
||||
|
||||
let file_name = ©_table.location;
|
||||
assert_eq!("tbl_file.parquet", file_name);
|
||||
@@ -302,20 +290,8 @@ mod tests {
|
||||
Statement::Copy(crate::statements::copy::Copy::CopyTable(CopyTable::From(
|
||||
copy_table,
|
||||
))) => {
|
||||
let (catalog, schema, table) =
|
||||
if let [catalog, schema, table] = ©_table.table_name.0[..] {
|
||||
(
|
||||
catalog.value.clone(),
|
||||
schema.value.clone(),
|
||||
table.value.clone(),
|
||||
)
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
assert_eq!("catalog0", catalog);
|
||||
assert_eq!("schema0", schema);
|
||||
assert_eq!("tbl", table);
|
||||
let table = copy_table.table_name.to_string();
|
||||
assert_eq!("catalog0.schema0.tbl", table);
|
||||
|
||||
let file_name = ©_table.location;
|
||||
assert_eq!("tbl_file.parquet", file_name);
|
||||
@@ -442,7 +418,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::new("catalog0"), Ident::new("schema0")]),
|
||||
ObjectName::from(vec![Ident::new("catalog0"), Ident::new("schema0")]),
|
||||
stmt.database_name
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -478,7 +454,7 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
ObjectName(vec![Ident::new("catalog0"), Ident::new("schema0")]),
|
||||
ObjectName::from(vec![Ident::new("catalog0"), Ident::new("schema0")]),
|
||||
stmt.database_name
|
||||
);
|
||||
assert_eq!(
|
||||
|
||||
@@ -31,7 +31,7 @@ use sqlparser::parser::{Parser, ParserError};
|
||||
use sqlparser::tokenizer::{Token, TokenWithSpan, Word};
|
||||
use table::requests::{validate_database_option, validate_table_option};
|
||||
|
||||
use crate::ast::{ColumnDef, Ident};
|
||||
use crate::ast::{ColumnDef, Ident, ObjectNamePartExt};
|
||||
use crate::error::{
|
||||
self, InvalidColumnOptionSnafu, InvalidDatabaseOptionSnafu, InvalidIntervalSnafu,
|
||||
InvalidSqlSnafu, InvalidTableOptionSnafu, InvalidTimeIndexSnafu, MissingTimeIndexSnafu, Result,
|
||||
@@ -612,11 +612,6 @@ impl<'a> ParserContext<'a> {
|
||||
);
|
||||
|
||||
let data_type = parser.parse_data_type().context(SyntaxSnafu)?;
|
||||
let collation = if parser.parse_keyword(Keyword::COLLATE) {
|
||||
Some(parser.parse_object_name(false).context(SyntaxSnafu)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut options = vec![];
|
||||
let mut extensions = ColumnExtensions::default();
|
||||
loop {
|
||||
@@ -643,7 +638,6 @@ impl<'a> ParserContext<'a> {
|
||||
column_def: ColumnDef {
|
||||
name: Self::canonicalize_identifier(name),
|
||||
data_type,
|
||||
collation,
|
||||
options,
|
||||
},
|
||||
extensions,
|
||||
@@ -713,7 +707,7 @@ impl<'a> ParserContext<'a> {
|
||||
) -> Result<bool> {
|
||||
if let DataType::Custom(name, tokens) = column_type
|
||||
&& name.0.len() == 1
|
||||
&& &name.0[0].value.to_uppercase() == "VECTOR"
|
||||
&& &name.0[0].to_string_unquoted().to_uppercase() == "VECTOR"
|
||||
{
|
||||
ensure!(
|
||||
tokens.len() == 1,
|
||||
@@ -1007,7 +1001,9 @@ fn validate_time_index(columns: &[Column], constraints: &[TableConstraint]) -> R
|
||||
fn get_unalias_type(data_type: &DataType) -> DataType {
|
||||
match data_type {
|
||||
DataType::Custom(name, tokens) if name.0.len() == 1 && tokens.is_empty() => {
|
||||
if let Some(real_type) = get_data_type_by_alias_name(name.0[0].value.as_str()) {
|
||||
if let Some(real_type) =
|
||||
get_data_type_by_alias_name(name.0[0].to_string_unquoted().as_str())
|
||||
{
|
||||
real_type
|
||||
} else {
|
||||
data_type.clone()
|
||||
@@ -1308,7 +1304,7 @@ mod tests {
|
||||
let stmts = result.unwrap();
|
||||
match &stmts.last().unwrap() {
|
||||
Statement::CreateDatabase(c) => {
|
||||
assert_eq!(c.name, ObjectName(vec![Ident::with_quote('`', "fOo")]));
|
||||
assert_eq!(c.name, vec![Ident::with_quote('`', "fOo")].into());
|
||||
assert!(!c.if_not_exists);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -1369,8 +1365,8 @@ COMMENT 'test comment'
|
||||
AS
|
||||
SELECT max(c1), min(c2) FROM schema_2.table_2;",
|
||||
CreateFlowWoutQuery {
|
||||
flow_name: ObjectName(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName(vec![
|
||||
flow_name: ObjectName::from(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName::from(vec![
|
||||
Ident::new("schema_1"),
|
||||
Ident::new("table_1"),
|
||||
]),
|
||||
@@ -1389,8 +1385,8 @@ COMMENT 'test comment'
|
||||
AS
|
||||
SELECT max(c1), min(c2) FROM schema_2.table_2;",
|
||||
CreateFlowWoutQuery {
|
||||
flow_name: ObjectName(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName(vec![
|
||||
flow_name: ObjectName::from(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName::from(vec![
|
||||
Ident::new("schema_1"),
|
||||
Ident::new("table_1"),
|
||||
]),
|
||||
@@ -1409,8 +1405,8 @@ COMMENT 'test comment'
|
||||
AS
|
||||
SELECT max(c1), min(c2) FROM schema_2.table_2;",
|
||||
CreateFlowWoutQuery {
|
||||
flow_name: ObjectName(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName(vec![
|
||||
flow_name: ObjectName::from(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName::from(vec![
|
||||
Ident::new("schema_1"),
|
||||
Ident::new("table_1"),
|
||||
]),
|
||||
@@ -1429,8 +1425,8 @@ COMMENT 'test comment'
|
||||
AS
|
||||
SELECT max(c1), min(c2) FROM schema_2.table_2;",
|
||||
CreateFlowWoutQuery {
|
||||
flow_name: ObjectName(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName(vec![
|
||||
flow_name: ObjectName::from(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName::from(vec![
|
||||
Ident::new("schema_1"),
|
||||
Ident::new("table_1"),
|
||||
]),
|
||||
@@ -1448,8 +1444,8 @@ EXPIRE AFTER '1 month 2 days 1h 2 min'
|
||||
AS
|
||||
SELECT max(c1), min(c2) FROM schema_2.table_2;",
|
||||
CreateFlowWoutQuery {
|
||||
flow_name: ObjectName(vec![Ident::with_quote('`', "task_2")]),
|
||||
sink_table_name: ObjectName(vec![
|
||||
flow_name: ObjectName::from(vec![Ident::with_quote('`', "task_2")]),
|
||||
sink_table_name: ObjectName::from(vec![
|
||||
Ident::new("schema_1"),
|
||||
Ident::new("table_1"),
|
||||
]),
|
||||
@@ -1501,8 +1497,8 @@ SELECT max(c1), min(c2) FROM schema_2.table_2;";
|
||||
};
|
||||
|
||||
let expected = CreateFlow {
|
||||
flow_name: ObjectName(vec![Ident::new("task_1")]),
|
||||
sink_table_name: ObjectName(vec![Ident::new("schema_1"), Ident::new("table_1")]),
|
||||
flow_name: vec![Ident::new("task_1")].into(),
|
||||
sink_table_name: vec![Ident::new("schema_1"), Ident::new("table_1")].into(),
|
||||
or_replace: true,
|
||||
if_not_exists: true,
|
||||
expire_after: Some(300),
|
||||
@@ -1607,15 +1603,17 @@ ENGINE=mito";
|
||||
left: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("idc".into())),
|
||||
op: BinaryOperator::LtEq,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"hz".to_string()
|
||||
)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("hz".to_string()).into()
|
||||
))
|
||||
}),
|
||||
op: BinaryOperator::And,
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("host_id".into())),
|
||||
op: BinaryOperator::Lt,
|
||||
right: Box::new(Expr::Value(Value::Number("1000".to_string(), false)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::Number("1000".to_string(), false).into()
|
||||
))
|
||||
})
|
||||
}
|
||||
);
|
||||
@@ -1626,24 +1624,26 @@ ENGINE=mito";
|
||||
left: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("idc".into())),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"hz".to_string()
|
||||
)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("hz".to_string()).into()
|
||||
))
|
||||
}),
|
||||
op: BinaryOperator::And,
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("idc".into())),
|
||||
op: BinaryOperator::LtEq,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"sh".to_string()
|
||||
)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("sh".to_string()).into()
|
||||
))
|
||||
})
|
||||
}),
|
||||
op: BinaryOperator::And,
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("host_id".into())),
|
||||
op: BinaryOperator::Lt,
|
||||
right: Box::new(Expr::Value(Value::Number("2000".to_string(), false)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::Number("2000".to_string(), false).into()
|
||||
))
|
||||
})
|
||||
}
|
||||
);
|
||||
@@ -1653,15 +1653,17 @@ ENGINE=mito";
|
||||
left: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("idc".into())),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"sh".to_string()
|
||||
)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("sh".to_string()).into()
|
||||
))
|
||||
}),
|
||||
op: BinaryOperator::And,
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("host_id".into())),
|
||||
op: BinaryOperator::Lt,
|
||||
right: Box::new(Expr::Value(Value::Number("3000".to_string(), false)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::Number("3000".to_string(), false).into()
|
||||
))
|
||||
})
|
||||
}
|
||||
);
|
||||
@@ -1671,15 +1673,17 @@ ENGINE=mito";
|
||||
left: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("idc".into())),
|
||||
op: BinaryOperator::Gt,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"sh".to_string()
|
||||
)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("sh".to_string()).into()
|
||||
))
|
||||
}),
|
||||
op: BinaryOperator::And,
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
left: Box::new(Expr::Identifier("host_id".into())),
|
||||
op: BinaryOperator::GtEq,
|
||||
right: Box::new(Expr::Value(Value::Number("3000".to_string(), false)))
|
||||
right: Box::new(Expr::Value(
|
||||
Value::Number("3000".to_string(), false).into()
|
||||
))
|
||||
})
|
||||
}
|
||||
);
|
||||
@@ -2467,10 +2471,8 @@ CREATE TABLE log (
|
||||
let tokens = tokenizer.tokenize().unwrap();
|
||||
let mut parser = Parser::new(&dialect).with_tokens(tokens);
|
||||
let name = Ident::new("vec_col");
|
||||
let data_type = DataType::Custom(
|
||||
ObjectName(vec![Ident::new("VECTOR")]),
|
||||
vec!["128".to_string()],
|
||||
);
|
||||
let data_type =
|
||||
DataType::Custom(vec![Ident::new("VECTOR")].into(), vec!["128".to_string()]);
|
||||
let mut extensions = ColumnExtensions::default();
|
||||
|
||||
let result =
|
||||
@@ -2489,7 +2491,7 @@ CREATE TABLE log (
|
||||
let tokens = tokenizer.tokenize().unwrap();
|
||||
let mut parser = Parser::new(&dialect).with_tokens(tokens);
|
||||
let name = Ident::new("vec_col");
|
||||
let data_type = DataType::Custom(ObjectName(vec![Ident::new("VECTOR")]), vec![]);
|
||||
let data_type = DataType::Custom(vec![Ident::new("VECTOR")].into(), vec![]);
|
||||
let mut extensions = ColumnExtensions::default();
|
||||
|
||||
let result =
|
||||
|
||||
@@ -181,7 +181,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropTable(DropTable::new(
|
||||
vec![ObjectName(vec![Ident::new("foo")])],
|
||||
vec![ObjectName::from(vec![Ident::new("foo")])],
|
||||
false
|
||||
))
|
||||
);
|
||||
@@ -193,7 +193,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropTable(DropTable::new(
|
||||
vec![ObjectName(vec![Ident::new("foo")])],
|
||||
vec![ObjectName::from(vec![Ident::new("foo")])],
|
||||
true
|
||||
))
|
||||
);
|
||||
@@ -205,7 +205,10 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropTable(DropTable::new(
|
||||
vec![ObjectName(vec![Ident::new("my_schema"), Ident::new("foo")])],
|
||||
vec![ObjectName::from(vec![
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
])],
|
||||
false
|
||||
))
|
||||
);
|
||||
@@ -217,7 +220,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropTable(DropTable::new(
|
||||
vec![ObjectName(vec![
|
||||
vec![ObjectName::from(vec![
|
||||
Ident::new("my_catalog"),
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
@@ -236,7 +239,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropDatabase(DropDatabase::new(
|
||||
ObjectName(vec![Ident::new("public")]),
|
||||
ObjectName::from(vec![Ident::new("public")]),
|
||||
false
|
||||
))
|
||||
);
|
||||
@@ -248,7 +251,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropDatabase(DropDatabase::new(
|
||||
ObjectName(vec![Ident::new("public")]),
|
||||
ObjectName::from(vec![Ident::new("public")]),
|
||||
true
|
||||
))
|
||||
);
|
||||
@@ -260,7 +263,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropDatabase(DropDatabase::new(
|
||||
ObjectName(vec![Ident::with_quote('`', "fOo"),]),
|
||||
ObjectName::from(vec![Ident::with_quote('`', "fOo"),]),
|
||||
false
|
||||
))
|
||||
);
|
||||
@@ -274,7 +277,10 @@ mod tests {
|
||||
let mut stmts: Vec<Statement> = result.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropFlow(DropFlow::new(ObjectName(vec![Ident::new("foo")]), false))
|
||||
Statement::DropFlow(DropFlow::new(
|
||||
ObjectName::from(vec![Ident::new("foo")]),
|
||||
false
|
||||
))
|
||||
);
|
||||
|
||||
let sql = "DROP FLOW IF EXISTS foo";
|
||||
@@ -283,7 +289,10 @@ mod tests {
|
||||
let mut stmts = result.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropFlow(DropFlow::new(ObjectName(vec![Ident::new("foo")]), true))
|
||||
Statement::DropFlow(DropFlow::new(
|
||||
ObjectName::from(vec![Ident::new("foo")]),
|
||||
true
|
||||
))
|
||||
);
|
||||
|
||||
let sql = "DROP FLOW my_schema.foo";
|
||||
@@ -293,7 +302,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropFlow(DropFlow::new(
|
||||
ObjectName(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
ObjectName::from(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
false
|
||||
))
|
||||
);
|
||||
@@ -305,7 +314,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::DropFlow(DropFlow::new(
|
||||
ObjectName(vec![
|
||||
ObjectName::from(vec![
|
||||
Ident::new("my_catalog"),
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
@@ -325,7 +334,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::DropView(DropView {
|
||||
view_name: ObjectName(vec![Ident::new("foo")]),
|
||||
view_name: ObjectName::from(vec![Ident::new("foo")]),
|
||||
drop_if_exists: false,
|
||||
})
|
||||
);
|
||||
@@ -339,7 +348,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::DropView(DropView {
|
||||
view_name: ObjectName(vec![
|
||||
view_name: ObjectName::from(vec![
|
||||
Ident::new("greptime"),
|
||||
Ident::new("public"),
|
||||
Ident::new("foo")
|
||||
@@ -357,7 +366,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::DropView(DropView {
|
||||
view_name: ObjectName(vec![Ident::new("foo")]),
|
||||
view_name: ObjectName::from(vec![Ident::new("foo")]),
|
||||
drop_if_exists: true,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -41,7 +41,8 @@ impl ParserContext<'_> {
|
||||
mod tests {
|
||||
use sqlparser::ast::helpers::attached_token::AttachedToken;
|
||||
use sqlparser::ast::{
|
||||
GroupByExpr, Query as SpQuery, Statement as SpStatement, WildcardAdditionalOptions,
|
||||
GroupByExpr, Query as SpQuery, SelectFlavor, Statement as SpStatement,
|
||||
WildcardAdditionalOptions,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
@@ -65,7 +66,7 @@ mod tests {
|
||||
into: None,
|
||||
from: vec![sqlparser::ast::TableWithJoins {
|
||||
relation: sqlparser::ast::TableFactor::Table {
|
||||
name: sqlparser::ast::ObjectName(vec![sqlparser::ast::Ident::new("foo")]),
|
||||
name: sqlparser::ast::ObjectName::from(vec![sqlparser::ast::Ident::new("foo")]),
|
||||
alias: None,
|
||||
args: None,
|
||||
with_hints: vec![],
|
||||
@@ -74,6 +75,7 @@ mod tests {
|
||||
with_ordinality: false,
|
||||
json_path: None,
|
||||
sample: None,
|
||||
index_hints: vec![],
|
||||
},
|
||||
joins: vec![],
|
||||
}],
|
||||
@@ -92,6 +94,7 @@ mod tests {
|
||||
window_before_qualify: false,
|
||||
connect_by: None,
|
||||
select_token: AttachedToken::empty(),
|
||||
flavor: SelectFlavor::Standard,
|
||||
};
|
||||
|
||||
let sp_statement = SpStatement::Query(Box::new(SpQuery {
|
||||
|
||||
@@ -38,7 +38,7 @@ impl ParserContext<'_> {
|
||||
})),
|
||||
|
||||
SpStatement::SetTimeZone { value, .. } => Ok(Statement::SetVariables(SetVariables {
|
||||
variable: ObjectName(vec![Ident::new("TIMEZONE")]),
|
||||
variable: ObjectName::from(vec![Ident::new("TIMEZONE")]),
|
||||
value: vec![value],
|
||||
})),
|
||||
|
||||
@@ -65,7 +65,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::SetVariables(SetVariables {
|
||||
variable: ObjectName(vec![Ident::new(indent_str)]),
|
||||
variable: ObjectName::from(vec![Ident::new(indent_str)]),
|
||||
value: vec![expr]
|
||||
})
|
||||
);
|
||||
@@ -78,7 +78,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::SetVariables(SetVariables {
|
||||
variable: ObjectName(vec![Ident::new(indent)]),
|
||||
variable: ObjectName::from(vec![Ident::new(indent)]),
|
||||
value: vec![expr],
|
||||
})
|
||||
);
|
||||
@@ -86,7 +86,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn test_set_timezone() {
|
||||
let expected_utc_expr = Expr::Value(Value::SingleQuotedString("UTC".to_string()));
|
||||
let expected_utc_expr = Expr::Value(Value::SingleQuotedString("UTC".to_string()).into());
|
||||
// mysql style
|
||||
let sql = "SET time_zone = 'UTC'";
|
||||
assert_mysql_parse_result(sql, "time_zone", expected_utc_expr.clone());
|
||||
@@ -105,7 +105,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
pub fn test_set_query_timeout() {
|
||||
let expected_query_timeout_expr = Expr::Value(Value::Number("5000".to_string(), false));
|
||||
let expected_query_timeout_expr =
|
||||
Expr::Value(Value::Number("5000".to_string(), false).into());
|
||||
// mysql style
|
||||
let sql = "SET MAX_EXECUTION_TIME = 5000";
|
||||
assert_mysql_parse_result(
|
||||
|
||||
@@ -19,6 +19,7 @@ use snafu::{ensure, ResultExt};
|
||||
use sqlparser::keywords::Keyword;
|
||||
use sqlparser::tokenizer::Token;
|
||||
|
||||
use crate::ast::ObjectNamePartExt;
|
||||
use crate::error::{
|
||||
self, InvalidDatabaseNameSnafu, InvalidFlowNameSnafu, InvalidTableNameSnafu, Result,
|
||||
};
|
||||
@@ -228,9 +229,7 @@ impl ParserContext<'_> {
|
||||
);
|
||||
|
||||
// Safety: already checked above
|
||||
Ok(Self::canonicalize_object_name(table_name).0[0]
|
||||
.value
|
||||
.clone())
|
||||
Ok(Self::canonicalize_object_name(table_name).0[0].to_string_unquoted())
|
||||
}
|
||||
|
||||
fn parse_db_name(&mut self) -> Result<Option<String>> {
|
||||
@@ -251,7 +250,7 @@ impl ParserContext<'_> {
|
||||
|
||||
// Safety: already checked above
|
||||
Ok(Some(
|
||||
Self::canonicalize_object_name(db_name).0[0].value.clone(),
|
||||
Self::canonicalize_object_name(db_name).0[0].to_string_unquoted(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -866,7 +865,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts[0],
|
||||
Statement::ShowVariables(ShowVariables {
|
||||
variable: ObjectName(vec![Ident::new("system_time_zone")]),
|
||||
variable: ObjectName::from(vec![Ident::new("system_time_zone")]),
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -1152,7 +1151,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts[0],
|
||||
Statement::ShowCreateView(ShowCreateView {
|
||||
view_name: ObjectName(vec![Ident::new("test")]),
|
||||
view_name: ObjectName::from(vec![Ident::new("test")]),
|
||||
})
|
||||
);
|
||||
assert_eq!(sql, stmts[0].to_string());
|
||||
|
||||
@@ -64,6 +64,7 @@ impl ParserContext<'_> {
|
||||
let start = self
|
||||
.parser
|
||||
.parse_value()
|
||||
.map(|x| x.value)
|
||||
.with_context(|e| error::UnexpectedSnafu {
|
||||
expected: "a timestamp value",
|
||||
actual: e.to_string(),
|
||||
@@ -80,6 +81,7 @@ impl ParserContext<'_> {
|
||||
let end = self
|
||||
.parser
|
||||
.parse_value()
|
||||
.map(|x| x.value)
|
||||
.with_context(|_| error::UnexpectedSnafu {
|
||||
expected: "a timestamp",
|
||||
actual: self.peek_token_as_string(),
|
||||
@@ -148,7 +150,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::new("foo")]),
|
||||
ObjectName::from(vec![Ident::new("foo")]),
|
||||
vec![(
|
||||
sqlparser::ast::Value::Number("0".to_string(), false),
|
||||
sqlparser::ast::Value::Number("20".to_string(), false)
|
||||
@@ -163,7 +165,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::new("foo")]),
|
||||
ObjectName::from(vec![Ident::new("foo")]),
|
||||
vec![
|
||||
(
|
||||
sqlparser::ast::Value::DoubleQuotedString(
|
||||
@@ -188,7 +190,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
ObjectName::from(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
vec![
|
||||
(
|
||||
sqlparser::ast::Value::Number("1".to_string(), false),
|
||||
@@ -209,7 +211,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
ObjectName::from(vec![Ident::new("my_schema"), Ident::new("foo")]),
|
||||
vec![(
|
||||
sqlparser::ast::Value::Number("1".to_string(), false),
|
||||
sqlparser::ast::Value::Number("2".to_string(), false)
|
||||
@@ -224,7 +226,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![
|
||||
ObjectName::from(vec![
|
||||
Ident::new("my_catalog"),
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
@@ -243,7 +245,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::new("drop")]),
|
||||
ObjectName::from(vec![Ident::new("drop")]),
|
||||
vec![(
|
||||
sqlparser::ast::Value::Number("1".to_string(), false),
|
||||
sqlparser::ast::Value::Number("2".to_string(), false)
|
||||
@@ -257,9 +259,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::with_quote(
|
||||
'`', "drop"
|
||||
),])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::with_quote('`', "drop"),
|
||||
])))
|
||||
);
|
||||
|
||||
let sql = "TRUNCATE \"drop\" FILE RANGE (\"1\", \"2\")";
|
||||
@@ -269,7 +271,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new_with_ranges(
|
||||
ObjectName(vec![Ident::with_quote('"', "drop")]),
|
||||
ObjectName::from(vec![Ident::with_quote('"', "drop")]),
|
||||
vec![(
|
||||
sqlparser::ast::Value::DoubleQuotedString("1".to_string()),
|
||||
sqlparser::ast::Value::DoubleQuotedString("2".to_string())
|
||||
@@ -286,7 +288,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::new("foo")])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![Ident::new(
|
||||
"foo"
|
||||
)])))
|
||||
);
|
||||
|
||||
let sql = "TRUNCATE TABLE foo";
|
||||
@@ -295,7 +299,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::new("foo")])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![Ident::new(
|
||||
"foo"
|
||||
)])))
|
||||
);
|
||||
|
||||
let sql = "TRUNCATE TABLE my_schema.foo";
|
||||
@@ -304,7 +310,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
])))
|
||||
@@ -316,7 +322,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
])))
|
||||
@@ -328,7 +334,7 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::new("my_catalog"),
|
||||
Ident::new("my_schema"),
|
||||
Ident::new("foo")
|
||||
@@ -341,7 +347,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::new("drop")])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![Ident::new(
|
||||
"drop"
|
||||
)])))
|
||||
);
|
||||
|
||||
let sql = "TRUNCATE `drop`";
|
||||
@@ -350,9 +358,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::with_quote(
|
||||
'`', "drop"
|
||||
),])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::with_quote('`', "drop"),
|
||||
])))
|
||||
);
|
||||
|
||||
let sql = "TRUNCATE \"drop\"";
|
||||
@@ -361,9 +369,9 @@ mod tests {
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
stmts.pop().unwrap(),
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName(vec![Ident::with_quote(
|
||||
'"', "drop"
|
||||
),])))
|
||||
Statement::TruncateTable(TruncateTable::new(ObjectName::from(vec![
|
||||
Ident::with_quote('"', "drop"),
|
||||
])))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn parser_expr_to_scalar_value_literal(expr: sqlparser::ast::Expr) -> Result
|
||||
.simplify(logical_expr)
|
||||
.context(SimplificationSnafu)?;
|
||||
|
||||
if let datafusion::logical_expr::Expr::Literal(lit) = simplified_expr {
|
||||
if let datafusion::logical_expr::Expr::Literal(lit, _) = simplified_expr {
|
||||
Ok(lit)
|
||||
} else {
|
||||
// Err(ParseSqlValue)
|
||||
@@ -106,7 +106,7 @@ impl ContextProvider for StubContextProvider {
|
||||
}
|
||||
|
||||
fn options(&self) -> &ConfigOptions {
|
||||
unimplemented!()
|
||||
self.state.config_options()
|
||||
}
|
||||
|
||||
fn udf_names(&self) -> Vec<String> {
|
||||
|
||||
@@ -118,8 +118,9 @@ impl ParserContext<'_> {
|
||||
columns: cte
|
||||
.columns
|
||||
.into_iter()
|
||||
.map(|col| TableAliasColumnDef {
|
||||
name: col.0[0].clone(),
|
||||
.flat_map(|col| col.0[0].as_ident().cloned())
|
||||
.map(|name| TableAliasColumnDef {
|
||||
name,
|
||||
data_type: None,
|
||||
})
|
||||
.collect(),
|
||||
@@ -370,7 +371,14 @@ mod tests {
|
||||
let second_cte = &hybrid_cte.cte_tables[0];
|
||||
assert!(matches!(second_cte.content, CteContent::Tql(_)));
|
||||
assert_eq!(second_cte.columns.len(), 2);
|
||||
assert_eq!(second_cte.columns[0].0[0].value, "time");
|
||||
assert_eq!(second_cte.columns[1].0[0].value, "metric_value");
|
||||
assert_eq!(
|
||||
second_cte
|
||||
.columns
|
||||
.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
"time metric_value"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,16 +31,16 @@ macro_rules! between_string {
|
||||
left: Box::new(Expr::BinaryOp {
|
||||
op: BinaryOperator::GtEq,
|
||||
left: Box::new($col.clone()),
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
$left_incl.to_string(),
|
||||
))),
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString($left_incl.to_string()).into(),
|
||||
)),
|
||||
}),
|
||||
right: Box::new(Expr::BinaryOp {
|
||||
op: BinaryOperator::Lt,
|
||||
left: Box::new($col.clone()),
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
$right_excl.to_string(),
|
||||
))),
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString($right_excl.to_string()).into(),
|
||||
)),
|
||||
}),
|
||||
}
|
||||
};
|
||||
@@ -90,20 +90,18 @@ fn partition_rules_for_uuid(partition_num: u32, ident: &str) -> Result<Vec<Expr>
|
||||
rules.push(Expr::BinaryOp {
|
||||
left: Box::new(ident_expr.clone()),
|
||||
op: BinaryOperator::Lt,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(format!(
|
||||
"{:0hex_length$x}",
|
||||
end
|
||||
)))),
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString(format!("{:0hex_length$x}", end)).into(),
|
||||
)),
|
||||
});
|
||||
} else if i == partition_num - 1 {
|
||||
// Create the rightmost rule, for example: trace_id >= 'f'.
|
||||
rules.push(Expr::BinaryOp {
|
||||
left: Box::new(ident_expr.clone()),
|
||||
op: BinaryOperator::GtEq,
|
||||
right: Box::new(Expr::Value(Value::SingleQuotedString(format!(
|
||||
"{:0hex_length$x}",
|
||||
start
|
||||
)))),
|
||||
right: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString(format!("{:0hex_length$x}", start)).into(),
|
||||
)),
|
||||
});
|
||||
} else {
|
||||
// Create the middle rules, for example: trace_id >= '1' AND trace_id < '2'.
|
||||
@@ -124,7 +122,7 @@ fn partition_rules_for_uuid(partition_num: u32, ident: &str) -> Result<Vec<Expr>
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use sqlparser::ast::Expr;
|
||||
use sqlparser::ast::{Expr, ValueWithSpan};
|
||||
use sqlparser::dialect::GenericDialect;
|
||||
use sqlparser::parser::Parser;
|
||||
use uuid::Uuid;
|
||||
@@ -220,14 +218,22 @@ mod tests {
|
||||
if let Expr::BinaryOp { left, op: _, right } = rule {
|
||||
if i == 0 {
|
||||
// Hit the leftmost rule.
|
||||
if let Expr::Value(Value::SingleQuotedString(leftmost)) = *right.clone() {
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(leftmost),
|
||||
..
|
||||
}) = *right.clone()
|
||||
{
|
||||
if uuid < leftmost {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else if i == rules.len() - 1 {
|
||||
// Hit the rightmost rule.
|
||||
if let Expr::Value(Value::SingleQuotedString(rightmost)) = *right.clone() {
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(rightmost),
|
||||
..
|
||||
}) = *right.clone()
|
||||
{
|
||||
if uuid >= rightmost {
|
||||
return i;
|
||||
}
|
||||
@@ -240,7 +246,10 @@ mod tests {
|
||||
right: inner_right,
|
||||
} = *left.clone()
|
||||
{
|
||||
if let Expr::Value(Value::SingleQuotedString(lower)) = *inner_right.clone()
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(lower),
|
||||
..
|
||||
}) = *inner_right.clone()
|
||||
{
|
||||
if let Expr::BinaryOp {
|
||||
left: _,
|
||||
@@ -248,8 +257,10 @@ mod tests {
|
||||
right: inner_right,
|
||||
} = *right.clone()
|
||||
{
|
||||
if let Expr::Value(Value::SingleQuotedString(upper)) =
|
||||
*inner_right.clone()
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(upper),
|
||||
..
|
||||
}) = *inner_right.clone()
|
||||
{
|
||||
if uuid >= lower && uuid < upper {
|
||||
return i;
|
||||
|
||||
@@ -41,10 +41,11 @@ use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema, COMMENT_KEY};
|
||||
use datatypes::types::TimestampType;
|
||||
use datatypes::value::Value;
|
||||
use snafu::ResultExt;
|
||||
use sqlparser::ast::{ExactNumberInfo, Ident, ObjectName};
|
||||
use sqlparser::ast::{ExactNumberInfo, Ident};
|
||||
|
||||
use crate::ast::{
|
||||
ColumnDef, ColumnOption, DataType as SqlDataType, TimezoneInfo, Value as SqlValue,
|
||||
ColumnDef, ColumnOption, DataType as SqlDataType, ObjectNamePartExt, TimezoneInfo,
|
||||
Value as SqlValue,
|
||||
};
|
||||
use crate::error::{
|
||||
self, ConvertToGrpcDataTypeSnafu, ConvertValueSnafu, Result,
|
||||
@@ -201,15 +202,15 @@ pub fn sql_column_def_to_grpc_column_def(
|
||||
pub fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<ConcreteDataType> {
|
||||
match data_type {
|
||||
SqlDataType::BigInt(_) | SqlDataType::Int64 => Ok(ConcreteDataType::int64_datatype()),
|
||||
SqlDataType::UnsignedBigInt(_) => Ok(ConcreteDataType::uint64_datatype()),
|
||||
SqlDataType::BigIntUnsigned(_) => Ok(ConcreteDataType::uint64_datatype()),
|
||||
SqlDataType::Int(_) | SqlDataType::Integer(_) => Ok(ConcreteDataType::int32_datatype()),
|
||||
SqlDataType::UnsignedInt(_) | SqlDataType::UnsignedInteger(_) => {
|
||||
SqlDataType::IntUnsigned(_) | SqlDataType::UnsignedInteger => {
|
||||
Ok(ConcreteDataType::uint32_datatype())
|
||||
}
|
||||
SqlDataType::SmallInt(_) => Ok(ConcreteDataType::int16_datatype()),
|
||||
SqlDataType::UnsignedSmallInt(_) => Ok(ConcreteDataType::uint16_datatype()),
|
||||
SqlDataType::SmallIntUnsigned(_) => Ok(ConcreteDataType::uint16_datatype()),
|
||||
SqlDataType::TinyInt(_) | SqlDataType::Int8(_) => Ok(ConcreteDataType::int8_datatype()),
|
||||
SqlDataType::UnsignedTinyInt(_) | SqlDataType::UnsignedInt8(_) => {
|
||||
SqlDataType::TinyIntUnsigned(_) | SqlDataType::Int8Unsigned(_) => {
|
||||
Ok(ConcreteDataType::uint8_datatype())
|
||||
}
|
||||
SqlDataType::Char(_)
|
||||
@@ -254,7 +255,10 @@ pub fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<Co
|
||||
// Vector type
|
||||
SqlDataType::Custom(name, d)
|
||||
if name.0.as_slice().len() == 1
|
||||
&& name.0.as_slice()[0].value.to_ascii_uppercase() == VECTOR_TYPE_NAME
|
||||
&& name.0.as_slice()[0]
|
||||
.to_string_unquoted()
|
||||
.to_ascii_uppercase()
|
||||
== VECTOR_TYPE_NAME
|
||||
&& d.len() == 1 =>
|
||||
{
|
||||
let dim = d[0].parse().map_err(|e| {
|
||||
@@ -275,13 +279,13 @@ pub fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<Co
|
||||
pub fn concrete_data_type_to_sql_data_type(data_type: &ConcreteDataType) -> Result<SqlDataType> {
|
||||
match data_type {
|
||||
ConcreteDataType::Int64(_) => Ok(SqlDataType::BigInt(None)),
|
||||
ConcreteDataType::UInt64(_) => Ok(SqlDataType::UnsignedBigInt(None)),
|
||||
ConcreteDataType::UInt64(_) => Ok(SqlDataType::BigIntUnsigned(None)),
|
||||
ConcreteDataType::Int32(_) => Ok(SqlDataType::Int(None)),
|
||||
ConcreteDataType::UInt32(_) => Ok(SqlDataType::UnsignedInt(None)),
|
||||
ConcreteDataType::UInt32(_) => Ok(SqlDataType::IntUnsigned(None)),
|
||||
ConcreteDataType::Int16(_) => Ok(SqlDataType::SmallInt(None)),
|
||||
ConcreteDataType::UInt16(_) => Ok(SqlDataType::UnsignedSmallInt(None)),
|
||||
ConcreteDataType::UInt16(_) => Ok(SqlDataType::SmallIntUnsigned(None)),
|
||||
ConcreteDataType::Int8(_) => Ok(SqlDataType::TinyInt(None)),
|
||||
ConcreteDataType::UInt8(_) => Ok(SqlDataType::UnsignedTinyInt(None)),
|
||||
ConcreteDataType::UInt8(_) => Ok(SqlDataType::TinyIntUnsigned(None)),
|
||||
ConcreteDataType::String(_) => Ok(SqlDataType::String(None)),
|
||||
ConcreteDataType::Float32(_) => Ok(SqlDataType::Float(None)),
|
||||
ConcreteDataType::Float64(_) => Ok(SqlDataType::Double(ExactNumberInfo::None)),
|
||||
@@ -302,7 +306,7 @@ pub fn concrete_data_type_to_sql_data_type(data_type: &ConcreteDataType) -> Resu
|
||||
)),
|
||||
ConcreteDataType::Json(_) => Ok(SqlDataType::JSON),
|
||||
ConcreteDataType::Vector(v) => Ok(SqlDataType::Custom(
|
||||
ObjectName(vec![Ident::new(VECTOR_TYPE_NAME)]),
|
||||
vec![Ident::new(VECTOR_TYPE_NAME)].into(),
|
||||
vec![v.dim.to_string()],
|
||||
)),
|
||||
ConcreteDataType::Duration(_)
|
||||
@@ -380,19 +384,19 @@ mod tests {
|
||||
ConcreteDataType::binary_datatype(),
|
||||
);
|
||||
check_type(
|
||||
SqlDataType::UnsignedBigInt(None),
|
||||
SqlDataType::BigIntUnsigned(None),
|
||||
ConcreteDataType::uint64_datatype(),
|
||||
);
|
||||
check_type(
|
||||
SqlDataType::UnsignedInt(None),
|
||||
SqlDataType::IntUnsigned(None),
|
||||
ConcreteDataType::uint32_datatype(),
|
||||
);
|
||||
check_type(
|
||||
SqlDataType::UnsignedSmallInt(None),
|
||||
SqlDataType::SmallIntUnsigned(None),
|
||||
ConcreteDataType::uint16_datatype(),
|
||||
);
|
||||
check_type(
|
||||
SqlDataType::UnsignedTinyInt(None),
|
||||
SqlDataType::TinyIntUnsigned(None),
|
||||
ConcreteDataType::uint8_datatype(),
|
||||
);
|
||||
check_type(
|
||||
@@ -406,7 +410,7 @@ mod tests {
|
||||
check_type(SqlDataType::JSON, ConcreteDataType::json_datatype());
|
||||
check_type(
|
||||
SqlDataType::Custom(
|
||||
ObjectName(vec![Ident::new(VECTOR_TYPE_NAME)]),
|
||||
vec![Ident::new(VECTOR_TYPE_NAME)].into(),
|
||||
vec!["3".to_string()],
|
||||
),
|
||||
ConcreteDataType::vector_datatype(3),
|
||||
@@ -419,7 +423,6 @@ mod tests {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
};
|
||||
|
||||
@@ -435,7 +438,6 @@ mod tests {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::NotNull,
|
||||
@@ -449,7 +451,6 @@ mod tests {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique {
|
||||
@@ -469,12 +470,11 @@ mod tests {
|
||||
name: "col".into(),
|
||||
// MILLISECOND
|
||||
data_type: SqlDataType::Timestamp(Some(3), TimezoneInfo::None),
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Default(Expr::Value(SqlValue::SingleQuotedString(
|
||||
"2024-01-30T00:01:01".to_string(),
|
||||
))),
|
||||
option: ColumnOption::Default(Expr::Value(
|
||||
SqlValue::SingleQuotedString("2024-01-30T00:01:01".to_string()).into(),
|
||||
)),
|
||||
}],
|
||||
};
|
||||
|
||||
@@ -522,7 +522,6 @@ mod tests {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
};
|
||||
assert!(!has_primary_key_option(&column_def));
|
||||
@@ -530,7 +529,6 @@ mod tests {
|
||||
let column_def = ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Unique {
|
||||
@@ -548,7 +546,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Double(ExactNumberInfo::None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
extensions: ColumnExtensions::default(),
|
||||
@@ -578,7 +575,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: "col2".into(),
|
||||
data_type: SqlDataType::String(None),
|
||||
collation: None,
|
||||
options: vec![
|
||||
ColumnOptionDef {
|
||||
name: None,
|
||||
@@ -612,12 +608,11 @@ mod tests {
|
||||
name: "col".into(),
|
||||
// MILLISECOND
|
||||
data_type: SqlDataType::Timestamp(Some(3), TimezoneInfo::None),
|
||||
collation: None,
|
||||
options: vec![ColumnOptionDef {
|
||||
name: None,
|
||||
option: ColumnOption::Default(Expr::Value(SqlValue::SingleQuotedString(
|
||||
"2024-01-30T00:01:01".to_string(),
|
||||
))),
|
||||
option: ColumnOption::Default(Expr::Value(
|
||||
SqlValue::SingleQuotedString("2024-01-30T00:01:01".to_string()).into(),
|
||||
)),
|
||||
}],
|
||||
},
|
||||
extensions: ColumnExtensions::default(),
|
||||
@@ -668,7 +663,6 @@ mod tests {
|
||||
column_def: ColumnDef {
|
||||
name: "col".into(),
|
||||
data_type: SqlDataType::Text,
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
extensions: ColumnExtensions {
|
||||
|
||||
@@ -53,7 +53,7 @@ mod tests {
|
||||
quote_style: None,
|
||||
span: Span::empty(),
|
||||
};
|
||||
let trigger_name = ObjectName(vec![ident]);
|
||||
let trigger_name = ObjectName::from(vec![ident]);
|
||||
|
||||
let drop_trigger = DropTrigger::new(trigger_name.clone(), true);
|
||||
assert_eq!(
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
use serde::Serialize;
|
||||
use sqlparser::ast::{
|
||||
Insert as SpInsert, ObjectName, Query, SetExpr, Statement, TableObject, UnaryOperator, Values,
|
||||
Insert as SpInsert, ObjectName, Query, SetExpr, Statement, TableObject, UnaryOperator,
|
||||
ValueWithSpan, Values,
|
||||
};
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser_derive::{Visit, VisitMut};
|
||||
@@ -99,7 +100,13 @@ impl Insert {
|
||||
}
|
||||
Expr::UnaryOp { op, expr } => {
|
||||
matches!(op, UnaryOperator::Minus | UnaryOperator::Plus)
|
||||
&& matches!(&**expr, Expr::Value(Value::Number(_, _)))
|
||||
&& matches!(
|
||||
&**expr,
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::Number(_, _),
|
||||
..
|
||||
})
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
})
|
||||
@@ -125,7 +132,7 @@ fn sql_exprs_to_values(exprs: &[Vec<Expr>]) -> Result<Vec<Vec<Value>>> {
|
||||
let mut vs = Vec::with_capacity(es.len());
|
||||
for expr in es.iter() {
|
||||
vs.push(match expr {
|
||||
Expr::Value(v) => v.clone(),
|
||||
Expr::Value(v) => v.value.clone(),
|
||||
Expr::Identifier(ident) => {
|
||||
if ident.quote_style.is_none() {
|
||||
// Special processing for `default` value
|
||||
@@ -146,7 +153,11 @@ fn sql_exprs_to_values(exprs: &[Vec<Expr>]) -> Result<Vec<Vec<Value>>> {
|
||||
Expr::UnaryOp { op, expr }
|
||||
if matches!(op, UnaryOperator::Minus | UnaryOperator::Plus) =>
|
||||
{
|
||||
if let Expr::Value(Value::Number(s, b)) = &**expr {
|
||||
if let Expr::Value(ValueWithSpan {
|
||||
value: Value::Number(s, b),
|
||||
..
|
||||
}) = &**expr
|
||||
{
|
||||
match op {
|
||||
UnaryOperator::Minus => Value::Number(format!("-{s}"), *b),
|
||||
UnaryOperator::Plus => Value::Number(s.to_string(), *b),
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::time::Duration as StdDuration;
|
||||
use itertools::Itertools;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use sqlparser::ast::{DataType, Expr, Interval, Value};
|
||||
use sqlparser::ast::{DataType, Expr, Interval, Value, ValueWithSpan};
|
||||
|
||||
use crate::statements::transform::TransformRule;
|
||||
|
||||
@@ -71,8 +71,14 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
fn visit_expr(&self, expr: &mut Expr) -> ControlFlow<()> {
|
||||
match expr {
|
||||
Expr::Interval(interval) => match &*interval.value {
|
||||
Expr::Value(Value::SingleQuotedString(value))
|
||||
| Expr::Value(Value::DoubleQuotedString(value)) => {
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(value),
|
||||
..
|
||||
})
|
||||
| Expr::Value(ValueWithSpan {
|
||||
value: Value::DoubleQuotedString(value),
|
||||
..
|
||||
}) => {
|
||||
if let Some(normalized_name) = normalize_interval_name(value) {
|
||||
*expr = update_existing_interval_with_value(
|
||||
interval,
|
||||
@@ -81,8 +87,14 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
}
|
||||
}
|
||||
Expr::BinaryOp { left, op, right } => match &**left {
|
||||
Expr::Value(Value::SingleQuotedString(value))
|
||||
| Expr::Value(Value::DoubleQuotedString(value)) => {
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(value),
|
||||
..
|
||||
})
|
||||
| Expr::Value(ValueWithSpan {
|
||||
value: Value::DoubleQuotedString(value),
|
||||
..
|
||||
}) => {
|
||||
if let Some(normalized_name) = normalize_interval_name(value) {
|
||||
let new_expr_value = Box::new(Expr::BinaryOp {
|
||||
left: single_quoted_string_expr(normalized_name),
|
||||
@@ -104,8 +116,14 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
} => {
|
||||
if DataType::Interval == *data_type {
|
||||
match &**cast_exp {
|
||||
Expr::Value(Value::SingleQuotedString(value))
|
||||
| Expr::Value(Value::DoubleQuotedString(value)) => {
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(value),
|
||||
..
|
||||
})
|
||||
| Expr::Value(ValueWithSpan {
|
||||
value: Value::DoubleQuotedString(value),
|
||||
..
|
||||
}) => {
|
||||
let interval_value =
|
||||
normalize_interval_name(value).unwrap_or_else(|| value.to_string());
|
||||
*expr = Expr::Cast {
|
||||
@@ -126,7 +144,7 @@ impl TransformRule for ExpandIntervalTransformRule {
|
||||
}
|
||||
|
||||
fn single_quoted_string_expr(string: String) -> Box<Expr> {
|
||||
Box::new(Expr::Value(Value::SingleQuotedString(string)))
|
||||
Box::new(Expr::Value(Value::SingleQuotedString(string).into()))
|
||||
}
|
||||
|
||||
fn update_existing_interval_with_value(interval: &Interval, value: Box<Expr>) -> Expr {
|
||||
@@ -298,9 +316,9 @@ mod tests {
|
||||
assert_eq!(
|
||||
string_expr,
|
||||
Expr::Interval(Interval {
|
||||
value: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"5 years".to_string()
|
||||
))),
|
||||
value: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("5 years".to_string()).into()
|
||||
)),
|
||||
leading_field: None,
|
||||
leading_precision: None,
|
||||
last_field: None,
|
||||
@@ -322,9 +340,9 @@ mod tests {
|
||||
assert_eq!(
|
||||
string_expr,
|
||||
Expr::Interval(Interval {
|
||||
value: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"36993906000 milliseconds".to_string()
|
||||
))),
|
||||
value: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("36993906000 milliseconds".to_string()).into()
|
||||
)),
|
||||
leading_field: None,
|
||||
leading_precision: None,
|
||||
last_field: None,
|
||||
@@ -386,9 +404,9 @@ mod tests {
|
||||
cast_to_interval_expr,
|
||||
Expr::Cast {
|
||||
kind: CastKind::Cast,
|
||||
expr: Box::new(Expr::Value(Value::SingleQuotedString(
|
||||
"3 years 2 months".to_string()
|
||||
))),
|
||||
expr: Box::new(Expr::Value(
|
||||
Value::SingleQuotedString("3 years 2 months".to_string()).into()
|
||||
)),
|
||||
data_type: DataType::Interval,
|
||||
format: None,
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use sqlparser::ast::{
|
||||
Ident, ObjectName, Value,
|
||||
};
|
||||
|
||||
use crate::ast::ObjectNamePartExt;
|
||||
use crate::error::Result;
|
||||
use crate::statements::alter::AlterTableOperation;
|
||||
use crate::statements::create::{CreateExternalTable, CreateTable};
|
||||
@@ -36,7 +37,7 @@ use crate::statements::{sql_data_type_to_concrete_data_type, TimezoneInfo};
|
||||
/// - `INT16` for `smallint`
|
||||
/// - `INT32` for `int`
|
||||
/// - `INT64` for `bigint`
|
||||
/// - And `UINT8`, `UINT16` etc. for `UnsignedTinyint` etc.
|
||||
/// - And `UINT8`, `UINT16` etc. for `TinyIntUnsigned` etc.
|
||||
/// - TinyText, MediumText, LongText for `Text`.
|
||||
pub(crate) struct TypeAliasTransformRule;
|
||||
|
||||
@@ -75,12 +76,12 @@ impl TransformRule for TypeAliasTransformRule {
|
||||
fn visit_expr(&self, expr: &mut Expr) -> ControlFlow<()> {
|
||||
fn cast_expr_to_arrow_cast_func(expr: Expr, cast_type: String) -> Function {
|
||||
Function {
|
||||
name: ObjectName(vec![Ident::new("arrow_cast")]),
|
||||
name: ObjectName::from(vec![Ident::new("arrow_cast")]),
|
||||
args: sqlparser::ast::FunctionArguments::List(FunctionArgumentList {
|
||||
args: vec![
|
||||
FunctionArg::Unnamed(FunctionArgExpr::Expr(expr)),
|
||||
FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value(
|
||||
Value::SingleQuotedString(cast_type),
|
||||
Value::SingleQuotedString(cast_type).into(),
|
||||
))),
|
||||
],
|
||||
duplicate_treatment: None,
|
||||
@@ -156,16 +157,16 @@ pub(crate) fn get_type_by_alias(data_type: &DataType) -> Option<DataType> {
|
||||
// Which means 8 bytes in postgres (not 8 bits).
|
||||
// See https://docs.rs/sqlparser/latest/sqlparser/ast/enum.DataType.html#variant.Int8
|
||||
DataType::Custom(name, tokens) if name.0.len() == 1 && tokens.is_empty() => {
|
||||
get_data_type_by_alias_name(name.0[0].value.as_str())
|
||||
get_data_type_by_alias_name(name.0[0].to_string_unquoted().as_str())
|
||||
}
|
||||
DataType::Int8(None) => Some(DataType::TinyInt(None)),
|
||||
DataType::Int16 => Some(DataType::SmallInt(None)),
|
||||
DataType::Int32 => Some(DataType::Int(None)),
|
||||
DataType::Int64 => Some(DataType::BigInt(None)),
|
||||
DataType::UInt8 => Some(DataType::UnsignedTinyInt(None)),
|
||||
DataType::UInt16 => Some(DataType::UnsignedSmallInt(None)),
|
||||
DataType::UInt32 => Some(DataType::UnsignedInt(None)),
|
||||
DataType::UInt64 => Some(DataType::UnsignedBigInt(None)),
|
||||
DataType::UInt8 => Some(DataType::TinyIntUnsigned(None)),
|
||||
DataType::UInt16 => Some(DataType::SmallIntUnsigned(None)),
|
||||
DataType::UInt32 => Some(DataType::IntUnsigned(None)),
|
||||
DataType::UInt64 => Some(DataType::BigIntUnsigned(None)),
|
||||
DataType::Float32 => Some(DataType::Float(None)),
|
||||
DataType::Float64 => Some(DataType::Double(ExactNumberInfo::None)),
|
||||
DataType::Bool => Some(DataType::Boolean),
|
||||
@@ -203,10 +204,10 @@ pub(crate) fn get_data_type_by_alias_name(name: &str) -> Option<DataType> {
|
||||
"INT16" => Some(DataType::SmallInt(None)),
|
||||
"INT32" => Some(DataType::Int(None)),
|
||||
"INT64" => Some(DataType::BigInt(None)),
|
||||
"UINT8" => Some(DataType::UnsignedTinyInt(None)),
|
||||
"UINT16" => Some(DataType::UnsignedSmallInt(None)),
|
||||
"UINT32" => Some(DataType::UnsignedInt(None)),
|
||||
"UINT64" => Some(DataType::UnsignedBigInt(None)),
|
||||
"UINT8" => Some(DataType::TinyIntUnsigned(None)),
|
||||
"UINT16" => Some(DataType::SmallIntUnsigned(None)),
|
||||
"UINT32" => Some(DataType::IntUnsigned(None)),
|
||||
"UINT64" => Some(DataType::BigIntUnsigned(None)),
|
||||
"FLOAT32" => Some(DataType::Float(None)),
|
||||
"FLOAT64" => Some(DataType::Double(ExactNumberInfo::None)),
|
||||
// String type alias
|
||||
@@ -260,19 +261,19 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
get_data_type_by_alias_name("Uint8"),
|
||||
Some(DataType::UnsignedTinyInt(None))
|
||||
Some(DataType::TinyIntUnsigned(None))
|
||||
);
|
||||
assert_eq!(
|
||||
get_data_type_by_alias_name("UINT16"),
|
||||
Some(DataType::UnsignedSmallInt(None))
|
||||
Some(DataType::SmallIntUnsigned(None))
|
||||
);
|
||||
assert_eq!(
|
||||
get_data_type_by_alias_name("UINT32"),
|
||||
Some(DataType::UnsignedInt(None))
|
||||
Some(DataType::IntUnsigned(None))
|
||||
);
|
||||
assert_eq!(
|
||||
get_data_type_by_alias_name("uint64"),
|
||||
Some(DataType::UnsignedBigInt(None))
|
||||
Some(DataType::BigIntUnsigned(None))
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use sqlparser::ast::{Expr, ObjectName, SetExpr, SqlOption, TableFactor, Value};
|
||||
use sqlparser::ast::{Expr, ObjectName, SetExpr, SqlOption, TableFactor, Value, ValueWithSpan};
|
||||
|
||||
use crate::ast::ObjectNamePartExt;
|
||||
use crate::error::{InvalidSqlSnafu, InvalidTableOptionValueSnafu, Result};
|
||||
use crate::statements::create::SqlOrTql;
|
||||
|
||||
@@ -32,7 +33,7 @@ pub fn format_raw_object_name(name: &ObjectName) -> String {
|
||||
for ident in self.name.0.iter() {
|
||||
write!(f, "{delim}")?;
|
||||
delim = ".";
|
||||
write!(f, "{}", ident.value)?;
|
||||
write!(f, "{}", ident.to_string_unquoted())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -49,9 +50,19 @@ pub fn parse_option_string(option: SqlOption) -> Result<(String, String)> {
|
||||
.fail();
|
||||
};
|
||||
let v = match value {
|
||||
Expr::Value(Value::SingleQuotedString(v)) | Expr::Value(Value::DoubleQuotedString(v)) => v,
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::SingleQuotedString(v),
|
||||
..
|
||||
})
|
||||
| Expr::Value(ValueWithSpan {
|
||||
value: Value::DoubleQuotedString(v),
|
||||
..
|
||||
}) => v,
|
||||
Expr::Identifier(v) => v.value,
|
||||
Expr::Value(Value::Number(v, _)) => v.to_string(),
|
||||
Expr::Value(ValueWithSpan {
|
||||
value: Value::Number(v, _),
|
||||
..
|
||||
}) => v.to_string(),
|
||||
value => return InvalidTableOptionValueSnafu { key, value }.fail(),
|
||||
};
|
||||
let k = key.value.to_lowercase();
|
||||
|
||||
Reference in New Issue
Block a user