Skip to content

Commit 9989ec8

Browse files
authored
Merge pull request #33572 from petrosagg/sources-refactor-part2
storage: quality of life refactors (part 2)
2 parents dc9527e + fa1e997 commit 9989ec8

File tree

24 files changed

+635
-593
lines changed

24 files changed

+635
-593
lines changed

src/adapter/src/error.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,19 @@ impl AdapterError {
519519
AdapterError::SafeModeViolation(_) => SqlState::INTERNAL_ERROR,
520520
AdapterError::SubscribeOnlyTransaction => SqlState::INVALID_TRANSACTION_STATE,
521521
AdapterError::Optimizer(e) => match e {
522-
OptimizerError::PlanError(e) => {
523-
AdapterError::PlanError(e.clone()).code() // Delegate to outer
522+
OptimizerError::PlanError(PlanError::InvalidSchemaName) => {
523+
SqlState::INVALID_SCHEMA_NAME
524524
}
525+
OptimizerError::PlanError(PlanError::ColumnAlreadyExists { .. }) => {
526+
SqlState::DUPLICATE_COLUMN
527+
}
528+
OptimizerError::PlanError(PlanError::UnknownParameter(_)) => {
529+
SqlState::UNDEFINED_PARAMETER
530+
}
531+
OptimizerError::PlanError(PlanError::ParameterNotAllowed(_)) => {
532+
SqlState::UNDEFINED_PARAMETER
533+
}
534+
OptimizerError::PlanError(_) => SqlState::INTERNAL_ERROR,
525535
OptimizerError::RecursionLimitError(e) => {
526536
AdapterError::RecursionLimit(e.clone()).code() // Delegate to outer
527537
}
@@ -836,9 +846,9 @@ impl fmt::Display for AdapterError {
836846

837847
impl From<anyhow::Error> for AdapterError {
838848
fn from(e: anyhow::Error) -> AdapterError {
839-
match e.downcast_ref::<PlanError>() {
840-
Some(plan_error) => AdapterError::PlanError(plan_error.clone()),
841-
None => AdapterError::Unstructured(e),
849+
match e.downcast::<PlanError>() {
850+
Ok(plan_error) => AdapterError::PlanError(plan_error),
851+
Err(e) => AdapterError::Unstructured(e),
842852
}
843853
}
844854
}

src/postgres-util/src/replication.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ pub async fn drop_replication_slots(
140140
Ok(())
141141
}
142142

143-
pub async fn get_timeline_id(replication_client: &Client) -> Result<u64, PostgresError> {
144-
if let Some(r) = simple_query_opt(replication_client, "IDENTIFY_SYSTEM").await? {
145-
r.get("timeline")
143+
pub async fn get_timeline_id(client: &Client) -> Result<u64, PostgresError> {
144+
if let Some(r) =
145+
simple_query_opt(client, "SELECT timeline_id FROM pg_control_checkpoint()").await?
146+
{
147+
r.get("timeline_id")
146148
.expect("Returns a row with a timeline ID")
147149
.parse::<u64>()
148150
.map_err(|err| {

src/sql/src/plan/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use crate::pure::error::{
4848
};
4949
use crate::session::vars::VarError;
5050

51-
#[derive(Clone, Debug)]
51+
#[derive(Debug)]
5252
pub enum PlanError {
5353
/// This feature is not yet supported, but may be supported at some point in the future.
5454
Unsupported {

src/sql/src/plan/explain/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl HirRelationExpr {
250250
}
251251
// We only print the offset if it is not trivial, i.e., not 0.
252252
let offset_literal = offset.clone().try_into_literal_int64();
253-
if !offset_literal.clone().is_ok_and(|offset| offset == 0) {
253+
if !offset_literal.as_ref().is_ok_and(|&offset| offset == 0) {
254254
let offset = if offset.contains_parameters() {
255255
// If we are still before parameter binding, then we can't reduce it to a
256256
// literal, so just print the expression.

0 commit comments

Comments
 (0)