mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-19 22:40:40 +00:00
fix: remove incorrect table_idents_to_full_name (#967)
This commit is contained in:
@@ -25,7 +25,6 @@ use std::str::FromStr;
|
||||
|
||||
use api::helper::ColumnDataTypeWrapper;
|
||||
use common_base::bytes::Bytes;
|
||||
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
|
||||
use common_time::Timestamp;
|
||||
use datatypes::data_type::DataType;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
@@ -35,8 +34,7 @@ use datatypes::value::Value;
|
||||
use snafu::{ensure, OptionExt, ResultExt};
|
||||
|
||||
use crate::ast::{
|
||||
ColumnDef, ColumnOption, ColumnOptionDef, DataType as SqlDataType, Expr, ObjectName,
|
||||
Value as SqlValue,
|
||||
ColumnDef, ColumnOption, ColumnOptionDef, DataType as SqlDataType, Expr, Value as SqlValue,
|
||||
};
|
||||
use crate::error::{
|
||||
self, ColumnTypeMismatchSnafu, ConvertToGrpcDataTypeSnafu, InvalidSqlValueSnafu,
|
||||
@@ -44,36 +42,6 @@ use crate::error::{
|
||||
UnsupportedDefaultValueSnafu,
|
||||
};
|
||||
|
||||
// TODO(LFC): Get rid of this function, use session context aware version of "table_idents_to_full_name" instead.
|
||||
// Current obstacles remain in some usage in Frontend, and other SQLs like "describe", "drop" etc.
|
||||
/// Converts maybe fully-qualified table name (`<catalog>.<schema>.<table>` or `<table>` when
|
||||
/// catalog and schema are default) to tuple.
|
||||
pub fn table_idents_to_full_name(obj_name: &ObjectName) -> Result<(String, String, String)> {
|
||||
match &obj_name.0[..] {
|
||||
[table] => Ok((
|
||||
DEFAULT_CATALOG_NAME.to_string(),
|
||||
DEFAULT_SCHEMA_NAME.to_string(),
|
||||
table.value.clone(),
|
||||
)),
|
||||
[schema, table] => Ok((
|
||||
DEFAULT_CATALOG_NAME.to_string(),
|
||||
schema.value.clone(),
|
||||
table.value.clone(),
|
||||
)),
|
||||
[catalog, schema, table] => Ok((
|
||||
catalog.value.clone(),
|
||||
schema.value.clone(),
|
||||
table.value.clone(),
|
||||
)),
|
||||
_ => error::InvalidSqlSnafu {
|
||||
msg: format!(
|
||||
"expect table name to be <catalog>.<schema>.<table>, <schema>.<table> or <table>, actual: {obj_name}",
|
||||
),
|
||||
}
|
||||
.fail(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_string_to_value(
|
||||
column_name: &str,
|
||||
s: String,
|
||||
@@ -368,6 +336,7 @@ mod tests {
|
||||
use common_time::timestamp::TimeUnit;
|
||||
use datatypes::types::BooleanType;
|
||||
use datatypes::value::OrderedFloat;
|
||||
use sqlparser::ast::ObjectName;
|
||||
|
||||
use super::*;
|
||||
use crate::ast::{Ident, TimezoneInfo};
|
||||
|
||||
@@ -12,12 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use api::v1::{alter_expr, AddColumn, AlterExpr, DropColumn};
|
||||
use sqlparser::ast::{ColumnDef, Ident, ObjectName, TableConstraint};
|
||||
|
||||
use crate::error::UnsupportedAlterTableStatementSnafu;
|
||||
use crate::statements::{sql_column_def_to_grpc_column_def, table_idents_to_full_name};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct AlterTable {
|
||||
table_name: ObjectName,
|
||||
@@ -52,45 +48,3 @@ pub enum AlterTableOperation {
|
||||
/// `RENAME <new_table_name>`
|
||||
RenameTable { new_table_name: String },
|
||||
}
|
||||
|
||||
/// Convert `AlterTable` statement to `AlterExpr` for gRPC
|
||||
impl TryFrom<AlterTable> for AlterExpr {
|
||||
type Error = crate::error::Error;
|
||||
|
||||
fn try_from(value: AlterTable) -> Result<Self, Self::Error> {
|
||||
let (catalog_name, schema_name, table_name) = table_idents_to_full_name(&value.table_name)?;
|
||||
|
||||
let kind = match value.alter_operation {
|
||||
AlterTableOperation::AddConstraint(_) => {
|
||||
return UnsupportedAlterTableStatementSnafu {
|
||||
msg: "ADD CONSTRAINT not supported yet.",
|
||||
}
|
||||
.fail();
|
||||
}
|
||||
AlterTableOperation::AddColumn { column_def } => {
|
||||
alter_expr::Kind::AddColumns(api::v1::AddColumns {
|
||||
add_columns: vec![AddColumn {
|
||||
column_def: Some(sql_column_def_to_grpc_column_def(column_def)?),
|
||||
is_key: false,
|
||||
}],
|
||||
})
|
||||
}
|
||||
AlterTableOperation::DropColumn { name } => {
|
||||
alter_expr::Kind::DropColumns(api::v1::DropColumns {
|
||||
drop_columns: vec![DropColumn { name: name.value }],
|
||||
})
|
||||
}
|
||||
AlterTableOperation::RenameTable { new_table_name } => {
|
||||
alter_expr::Kind::RenameTable(api::v1::RenameTable { new_table_name })
|
||||
}
|
||||
};
|
||||
let expr = AlterExpr {
|
||||
catalog_name,
|
||||
schema_name,
|
||||
table_name,
|
||||
kind: Some(kind),
|
||||
};
|
||||
|
||||
Ok(expr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ use sqlparser::parser::ParserError;
|
||||
|
||||
use crate::ast::{Expr, Value};
|
||||
use crate::error::{self, Result};
|
||||
use crate::statements::table_idents_to_full_name;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Insert {
|
||||
@@ -26,13 +25,6 @@ pub struct Insert {
|
||||
}
|
||||
|
||||
impl Insert {
|
||||
pub fn full_table_name(&self) -> Result<(String, String, String)> {
|
||||
match &self.inner {
|
||||
Statement::Insert { table_name, .. } => table_idents_to_full_name(table_name),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn table_name(&self) -> &ObjectName {
|
||||
match &self.inner {
|
||||
Statement::Insert { table_name, .. } => table_name,
|
||||
|
||||
Reference in New Issue
Block a user