Skip to content

Commit

Permalink
fix: unify row desc for show objects in normal and extended mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yezizp2012 committed Oct 16, 2023
1 parent e1bdf78 commit e5387f2
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 170 deletions.
158 changes: 8 additions & 150 deletions src/frontend/src/handler/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::catalog::{CatalogError, IndexCatalog};
use crate::handler::util::{col_descs_to_rows, indexes_to_rows};
use crate::handler::HandlerArgs;
use crate::session::SessionImpl;
use crate::utils::infer_stmt_row_desc::infer_show_object;

pub fn get_columns_from_table(
session: &SessionImpl,
Expand Down Expand Up @@ -95,6 +96,7 @@ pub async fn handle_show_object(
)
.into());
}
let row_desc = infer_show_object(&command);

let catalog_reader = session.env().catalog_reader();

Expand Down Expand Up @@ -146,58 +148,15 @@ pub async fn handle_show_object(
let rows = col_descs_to_rows(columns);

return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Type".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
ShowObject::Indexes { table } => {
let indexes = get_indexes_from_table(&session, table)?;
let rows = indexes_to_rows(indexes);

return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"On".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Key".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Include".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Distributed By".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
ShowObject::Connection { schema } => {
Expand Down Expand Up @@ -246,26 +205,7 @@ pub async fn handle_show_object(
})
.collect_vec();
return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Type".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Properties".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
ShowObject::Function { schema } => {
Expand All @@ -284,36 +224,7 @@ pub async fn handle_show_object(
})
.collect_vec();
return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Arguments".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Return Type".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Language".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Link".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
ShowObject::Cluster => {
Expand Down Expand Up @@ -341,41 +252,7 @@ pub async fn handle_show_object(
})
.collect_vec();
return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Addr".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"State".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Parallel Units".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Is Streaming".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Is Serving".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Is Unschedulable".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
ShowObject::Jobs => {
Expand All @@ -391,26 +268,7 @@ pub async fn handle_show_object(
})
.collect_vec();
return Ok(PgResponse::builder(StatementType::SHOW_COMMAND)
.values(
rows.into(),
vec![
PgFieldDescriptor::new(
"Id".to_owned(),
DataType::Int64.to_oid(),
DataType::Int64.type_len(),
),
PgFieldDescriptor::new(
"Statement".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Progress".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
],
)
.values(rows.into(), row_desc)
.into());
}
};
Expand Down
23 changes: 3 additions & 20 deletions src/frontend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use risingwave_pb::health::health_server::HealthServer;
use risingwave_pb::user::auth_info::EncryptionType;
use risingwave_pb::user::grant_privilege::{Action, Object};
use risingwave_rpc_client::{ComputeClientPool, ComputeClientPoolRef, MetaClient};
use risingwave_sqlparser::ast::{ObjectName, ShowObject, Statement};
use risingwave_sqlparser::ast::{ObjectName, Statement};
use risingwave_sqlparser::parser::Parser;
use thiserror::Error;
use tokio::runtime::Builder;
Expand Down Expand Up @@ -86,6 +86,7 @@ use crate::user::user_authentication::md5_hash_with_salt;
use crate::user::user_manager::UserInfoManager;
use crate::user::user_service::{UserInfoReader, UserInfoWriter, UserInfoWriterImpl};
use crate::user::UserId;
use crate::utils::infer_stmt_row_desc::infer_show_object;
use crate::{FrontendOpts, PgResponseStream};

pub(crate) mod transaction;
Expand Down Expand Up @@ -1090,25 +1091,7 @@ fn infer(bound: Option<BoundStatement>, stmt: Statement) -> Result<Vec<PgFieldDe
Statement::ShowObjects {
object: show_object,
..
} => match show_object {
ShowObject::Columns { table: _ } => Ok(vec![
PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Type".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
]),
_ => Ok(vec![PgFieldDescriptor::new(
"Name".to_owned(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
)]),
},
} => Ok(infer_show_object(&show_object)),
Statement::ShowCreateObject { .. } => Ok(vec![
PgFieldDescriptor::new(
"Name".to_owned(),
Expand Down
Loading

0 comments on commit e5387f2

Please sign in to comment.