Skip to content

Commit

Permalink
Follow the error msg style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ggevay committed Jan 4, 2024
1 parent b49aef0 commit 99e64b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ impl Coordinator {
// `as_of` to the first refresh. This is because we'd like queries on the MV to
// block until the first refresh (rather than to show an empty MV).
if let Some(refresh_schedule) = &refresh_schedule {
if let Some(ts) = as_of.as_option() {
let Some(rounded_up_ts) = refresh_schedule.round_up_timestamp(*ts) else {
return Err(AdapterError::MaterializedViewWouldNeverRefresh(name.item));
if let Some(as_of_ts) = as_of.as_option() {
let Some(rounded_up_ts) = refresh_schedule.round_up_timestamp(*as_of_ts) else {
return Err(AdapterError::MaterializedViewWouldNeverRefresh(
refresh_schedule.last_refresh().expect("if round_up_timestamp returned None, then there should be a last refresh"),
*as_of_ts
));
};
as_of = Antichain::from_elem(rounded_up_ts);
} else {
Expand Down
21 changes: 14 additions & 7 deletions src/adapter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use mz_ore::str::StrExt;
use mz_pgwire_common::{ErrorResponse, Severity};
use mz_repr::adt::timestamp::TimestampError;
use mz_repr::explain::ExplainError;
use mz_repr::NotNullViolation;
use mz_repr::{NotNullViolation, Timestamp};
use mz_sql::plan::PlanError;
use mz_sql::rbac;
use mz_sql::session::vars::VarError;
Expand Down Expand Up @@ -218,7 +218,7 @@ pub enum AdapterError {
/// We refuse to create the materialized view, because it would never be refreshed, so it would
/// never be queryable. This can happen when the only specified refreshes are further back in
/// the past than the initial compaction window of the materialized view.
MaterializedViewWouldNeverRefresh(String),
MaterializedViewWouldNeverRefresh(Timestamp, Timestamp),
}

impl AdapterError {
Expand Down Expand Up @@ -305,6 +305,14 @@ impl AdapterError {
AdapterError::InvalidAlter(_, e) => e.detail(),
AdapterError::Optimizer(e) => e.detail(),
AdapterError::ConnectionValidation(e) => e.detail(),
AdapterError::MaterializedViewWouldNeverRefresh(last_refresh, earliest_possible) => {
Some(format!(
"The specified last refresh is at {}, while the earliest possible time to compute the materialized \
view is {}.",
last_refresh,
earliest_possible,
))
}
_ => None,
}
}
Expand Down Expand Up @@ -481,7 +489,7 @@ impl AdapterError {
AdapterError::InvalidAlter(_, _) => SqlState::FEATURE_NOT_SUPPORTED,
AdapterError::ConnectionValidation(_) => SqlState::SYSTEM_ERROR,
// `DATA_EXCEPTION`, similarly to `AbsurdSubscribeBounds`.
AdapterError::MaterializedViewWouldNeverRefresh(_) => SqlState::DATA_EXCEPTION,
AdapterError::MaterializedViewWouldNeverRefresh(_, _) => SqlState::DATA_EXCEPTION,
}
}

Expand Down Expand Up @@ -695,12 +703,11 @@ impl fmt::Display for AdapterError {
write!(f, "invalid ALTER {t}: {e}")
}
AdapterError::ConnectionValidation(e) => e.fmt(f),
AdapterError::MaterializedViewWouldNeverRefresh(name) => {
AdapterError::MaterializedViewWouldNeverRefresh(_, _) => {
write!(
f,
"Error when creating materialized view {}: All the specified refreshes \
would be too far in the past, and thus they would never happen",
name
"all the specified refreshes of the materialized view would be too far in the past, and thus they \
would never happen"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/sqllogictest/materialized_views.slt
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ SELECT * FROM const_mv2
2

## MV that has refreshes only in the past
query error db error: ERROR: Error when creating materialized view mv_no_refresh: All the specified refreshes would be too far in the past, and thus they would never happen
query error db error: ERROR: all the specified refreshes of the materialized view would be too far in the past, and thus they would never happen
CREATE MATERIALIZED VIEW mv_no_refresh
WITH (REFRESH AT '2000-01-01 10:00')
AS SELECT * FROM t2;
Expand Down

0 comments on commit 99e64b4

Please sign in to comment.