-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(expr): support pg_get_indexdef (#14073)
- Loading branch information
1 parent
73fddec
commit 695651b
Showing
8 changed files
with
173 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
mod cast_regclass; | ||
mod col_description; | ||
pub mod context; | ||
mod pg_get_indexdef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::fmt::Write; | ||
|
||
use risingwave_expr::{capture_context, function, ExprError, Result}; | ||
use thiserror_ext::AsReport; | ||
|
||
use super::context::{CATALOG_READER, DB_NAME}; | ||
use crate::catalog::CatalogReader; | ||
|
||
#[function("pg_get_indexdef(int4) -> varchar")] | ||
fn pg_get_indexdef(oid: i32, writer: &mut impl Write) -> Result<()> { | ||
pg_get_indexdef_impl_captured(oid, 0, writer) | ||
} | ||
|
||
#[function("pg_get_indexdef(int4, int4, boolean) -> varchar")] | ||
fn pg_get_indexdef_col( | ||
oid: i32, | ||
column_no: i32, | ||
_pretty_bool: bool, | ||
writer: &mut impl Write, | ||
) -> Result<()> { | ||
pg_get_indexdef_impl_captured(oid, column_no, writer) | ||
} | ||
|
||
#[capture_context(CATALOG_READER, DB_NAME)] | ||
fn pg_get_indexdef_impl( | ||
catalog: &CatalogReader, | ||
db_name: &str, | ||
oid: i32, | ||
column_no: i32, | ||
writer: &mut impl Write, | ||
) -> Result<()> { | ||
let ans = if column_no == 0 { | ||
catalog | ||
.read_guard() | ||
.get_index_by_id(db_name, oid as u32) | ||
.map_err(|e| ExprError::InvalidParam { | ||
name: "oid", | ||
reason: e.to_report_string().into(), | ||
})? | ||
.index_table | ||
.create_sql() | ||
} else { | ||
catalog | ||
.read_guard() | ||
.get_index_by_id(db_name, oid as u32) | ||
.map_err(|e| ExprError::InvalidParam { | ||
name: "oid", | ||
reason: e.to_report_string().into(), | ||
})? | ||
.get_column_def(column_no as usize - 1) | ||
.unwrap_or_default() | ||
}; | ||
write!(writer, "{}", ans).unwrap(); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters