Skip to content

Commit

Permalink
Allow to see the context of a Unsupported query for a subscription (#621
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mamcx authored Dec 1, 2023
1 parent 6efcdfa commit bb4a78f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use hex::FromHexError;
use thiserror::Error;

use crate::client::ClientActorId;
use crate::sql::query_debug_info::QueryDebugInfo;
use spacetimedb_lib::buffer::DecodeError;
use spacetimedb_lib::{PrimaryKey, ProductValue};
use spacetimedb_primitives::{ColId, IndexId, TableId};
Expand Down Expand Up @@ -92,6 +93,8 @@ pub enum SubscriptionError {
Empty,
#[error("Queries with side effects not allowed: {0:?}")]
SideEffect(Crud),
#[error("Unsupported query on subscription: {0:?}")]
Unsupported(QueryDebugInfo),
}

#[derive(Error, Debug)]
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/subscription/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,10 @@ mod tests {
"SELECT * FROM lhs JOIN rhs ON lhs.id = rhs.id WHERE lhs.x < 10",
];
for join in joins {
assert!(compile_read_only_query(&db, &tx, &auth, join).is_err(), "{join}");
match compile_read_only_query(&db, &tx, &auth, join) {
Err(DBError::Subscription(SubscriptionError::Unsupported(_))) => (),
x => panic!("Unexpected: {x:?}"),
}
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/subscription/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::time::Instant;

use crate::db::datastore::locking_tx_datastore::MutTxId;
use crate::db::db_metrics::{DB_METRICS, MAX_QUERY_CPU_TIME};
use crate::error::DBError;
use crate::error::{DBError, SubscriptionError};
use crate::execution_context::{ExecutionContext, WorkloadType};
use crate::sql::query_debug_info::QueryDebugInfo;
use crate::subscription::query::{run_query, OP_TYPE_FIELD_NAME};
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct SupportedQuery {

impl SupportedQuery {
pub fn new(expr: QueryExpr, info: QueryDebugInfo) -> Result<Self, DBError> {
let kind = query::classify(&expr).context("Unsupported query expression")?;
let kind = query::classify(&expr).ok_or_else(|| SubscriptionError::Unsupported(info.clone()))?;
Ok(Self { kind, expr, info })
}

Expand Down Expand Up @@ -128,7 +128,7 @@ impl AsRef<QueryExpr> for SupportedQuery {
}

/// A set of [supported][`SupportedQuery`] [`QueryExpr`]s.
#[derive(Deref, DerefMut, PartialEq, From, IntoIterator)]
#[derive(Debug, Deref, DerefMut, PartialEq, From, IntoIterator)]
pub struct QuerySet(BTreeSet<SupportedQuery>);

impl From<SupportedQuery> for QuerySet {
Expand Down

1 comment on commit bb4a78f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark in progress...

Please sign in to comment.