Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add show search_path for pg #5328

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/frontend/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ pub fn check_permission(
validate_db_permission!(stmt, query_ctx);
}
Statement::ShowStatus(_stmt) => {}
Statement::ShowSearchPath(_stmt) => {}
Statement::DescribeTable(stmt) => {
validate_param(stmt.name(), query_ctx)?;
}
Expand Down
1 change: 1 addition & 0 deletions src/operator/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl StatementExecutor {
}
Statement::ShowIndex(show_index) => self.show_index(show_index, query_ctx).await,
Statement::ShowStatus(_) => self.show_status(query_ctx).await,
Statement::ShowSearchPath(_) => self.show_search_path(query_ctx).await,
Statement::Use(db) => self.use_database(db, query_ctx).await,
Statement::Admin(admin) => self.execute_admin_command(admin, query_ctx).await,
}
Expand Down
5 changes: 5 additions & 0 deletions src/operator/src/statement/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ impl StatementExecutor {
.await
.context(error::ExecuteStatementSnafu)
}
pub async fn show_search_path(&self, query_ctx: QueryContextRef) -> Result<Output> {
query::sql::show_search_path(query_ctx)
.await
.context(error::ExecuteStatementSnafu)
}
}

pub(crate) fn create_partitions_stmt(partitions: Vec<PartitionInfo>) -> Result<Option<Partitions>> {
Expand Down
14 changes: 14 additions & 0 deletions src/query/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,20 @@ pub async fn show_status(_query_ctx: QueryContextRef) -> Result<Output> {
Ok(Output::new_with_record_batches(records))
}

pub async fn show_search_path(_query_ctx: QueryContextRef) -> Result<Output> {
let schema = Arc::new(Schema::new(vec![ColumnSchema::new(
"search_path",
ConcreteDataType::string_datatype(),
false,
)]));
let records = RecordBatches::try_from_columns(
schema,
vec![Arc::new(StringVector::from(vec![_query_ctx.current_schema()])) as _],
)
.context(error::CreateRecordBatchSnafu)?;
Ok(Output::new_with_record_batches(records))
}

pub fn show_create_database(database_name: &str, options: OptionMap) -> Result<Output> {
let stmt = CreateDatabase {
name: ObjectName(vec![Ident {
Expand Down
6 changes: 4 additions & 2 deletions src/sql/src/parsers/show_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::error::{
use crate::parser::ParserContext;
use crate::statements::show::{
ShowColumns, ShowCreateDatabase, ShowCreateFlow, ShowCreateTable, ShowCreateTableVariant,
ShowCreateView, ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowStatus, ShowTableStatus,
ShowTables, ShowVariables, ShowViews,
ShowCreateView, ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowSearchPath, ShowStatus,
ShowTableStatus, ShowTables, ShowVariables, ShowViews,
};
use crate::statements::statement::Statement;

Expand Down Expand Up @@ -107,6 +107,8 @@ impl ParserContext<'_> {
Ok(Statement::ShowVariables(ShowVariables { variable }))
} else if self.consume_token("STATUS") {
Ok(Statement::ShowStatus(ShowStatus {}))
} else if self.consume_token("SEARCH_PATH") {
Ok(Statement::ShowSearchPath(ShowSearchPath {}))
} else {
self.unsupported(self.peek_token_as_string())
}
Expand Down
10 changes: 10 additions & 0 deletions src/sql/src/statements/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ impl Display for ShowStatus {
}
}

/// SQL structure for "SHOW SEARCH_PATH" postgres only
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut, Serialize)]
pub struct ShowSearchPath {}

impl Display for ShowSearchPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SHOW SEARCH_PATH")
}
}

#[cfg(test)]
mod tests {
use std::assert_matches::assert_matches;
Expand Down
7 changes: 5 additions & 2 deletions src/sql/src/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use crate::statements::query::Query;
use crate::statements::set_variables::SetVariables;
use crate::statements::show::{
ShowColumns, ShowCreateDatabase, ShowCreateFlow, ShowCreateTable, ShowCreateView,
ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowStatus, ShowTableStatus, ShowTables,
ShowVariables, ShowViews,
ShowDatabases, ShowFlows, ShowIndex, ShowKind, ShowSearchPath, ShowStatus, ShowTableStatus,
ShowTables, ShowVariables, ShowViews,
};
use crate::statements::tql::Tql;
use crate::statements::truncate::TruncateTable;
Expand Down Expand Up @@ -102,6 +102,8 @@ pub enum Statement {
ShowCreateView(ShowCreateView),
// SHOW STATUS
ShowStatus(ShowStatus),
// SHOW SEARCH_PATH
ShowSearchPath(ShowSearchPath),
// SHOW VIEWS
ShowViews(ShowViews),
// DESCRIBE TABLE
Expand Down Expand Up @@ -159,6 +161,7 @@ impl Display for Statement {
Statement::ShowCreateView(s) => s.fmt(f),
Statement::ShowViews(s) => s.fmt(f),
Statement::ShowStatus(s) => s.fmt(f),
Statement::ShowSearchPath(s) => s.fmt(f),
Statement::DescribeTable(s) => s.fmt(f),
Statement::Explain(s) => s.fmt(f),
Statement::Copy(s) => s.fmt(f),
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/standalone/common/system/pg_catalog.result
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ select current_schema();
| public |
+------------------+

-- search_path for pg using schema for now FIXME when support real search_path
-- SQLNESS PROTOCOL POSTGRES
show search_path;

+-------------+
| search_path |
+-------------+
| public |
+-------------+

-- make sure all the pg_catalog tables are only visible to postgres
select * from pg_catalog.pg_class;

Expand Down
4 changes: 4 additions & 0 deletions tests/cases/standalone/common/system/pg_catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ SELECT session_user is not null;
-- SQLNESS PROTOCOL POSTGRES
select current_schema();

-- search_path for pg using schema for now FIXME when support real search_path
-- SQLNESS PROTOCOL POSTGRES
show search_path;

-- make sure all the pg_catalog tables are only visible to postgres
select * from pg_catalog.pg_class;
select * from pg_catalog.pg_namespace;
Expand Down
Loading