factor out convert_to_grant_object
@@ -22,6 +22,7 @@ use common_planners::PlanNode;
use common_tracing::tracing;
use crate::sessions::QueryContext;
+use crate::sql::parser::ast::Query;
use crate::sql::statements::AnalyzableStatement;
use crate::sql::statements::AnalyzedResult;
@@ -40,15 +41,9 @@ pub enum DfGrantObject {
Table(Option<String>, String),
}
-#[async_trait::async_trait]
-impl AnalyzableStatement for DfGrantStatement {
- #[tracing::instrument(level = "info", skip(self, ctx), fields(ctx.id = ctx.get_id().as_str()))]
- async fn analyze(&self, ctx: Arc<QueryContext>) -> Result<AnalyzedResult> {
- Ok(AnalyzedResult::SimpleQuery(Box::new(
- PlanNode::GrantPrivilege(GrantPrivilegePlan {
- name: self.name.clone(),
- hostname: self.hostname.clone(),
- on: match &self.on {
+impl DfGrantObject {
+ pub fn convert_with_context(&self, ctx: Arc<QueryContext>) -> GrantObject {
+ match self {
DfGrantObject::Global => GrantObject::Global,
DfGrantObject::Table(database_name, table_name) => {
let database_name = database_name
@@ -62,7 +57,19 @@ impl AnalyzableStatement for DfGrantStatement {
.unwrap_or_else(|| ctx.get_current_database());
GrantObject::Database(database_name)
}
- },
+ }
+ }
+}
+
+#[async_trait::async_trait]
+impl AnalyzableStatement for DfGrantStatement {
+ #[tracing::instrument(level = "info", skip(self, ctx), fields(ctx.id = ctx.get_id().as_str()))]
+ async fn analyze(&self, ctx: Arc<QueryContext>) -> Result<AnalyzedResult> {
+ Ok(AnalyzedResult::SimpleQuery(Box::new(
+ PlanNode::GrantPrivilege(GrantPrivilegePlan {
+ name: self.name.clone(),
+ hostname: self.hostname.clone(),
+ on: self.on.convert_with_context(ctx),
priv_types: self.priv_types,
}),
)))
