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

Change the test that verify the query AST to use EXPLAIN instead #2194

Draft
wants to merge 3 commits into
base: mamcx/planner-printer
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ enum-as-inner = "0.6"
enum-map = "2.6.3"
env_logger = "0.10"
ethnum = { version = "1.5.0", features = ["serde"] }
expect-test = "1.5.0"
flate2 = "1.0.24"
foldhash = "0.1.4"
fs-err = "2.9.0"
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ derive_more.workspace = true
dirs.workspace = true
enum-as-inner.workspace = true
enum-map.workspace = true
expect-test.workspace = true
flate2.workspace = true
fs2.workspace = true
futures.workspace = true
Expand Down
19 changes: 19 additions & 0 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,15 @@ fn default_row_count_fn(db: Identity) -> RowCountFn {
#[cfg(any(test, feature = "test"))]
pub mod tests_utils {
use super::*;
use crate::sql::ast::{SchemaViewer, TableSchemaView};
use core::ops::Deref;
use durability::EmptyHistory;
use expect_test::Expect;
use spacetimedb_lib::identity::AuthCtx;
use spacetimedb_lib::{bsatn::to_vec, ser::Serialize};
use spacetimedb_paths::FromPathUnchecked;
use spacetimedb_physical_plan::plan::tests_utils::*;
use spacetimedb_physical_plan::printer::ExplainOptions;
use tempfile::TempDir;

/// A [`RelationalDB`] in a temporary directory.
Expand Down Expand Up @@ -1600,6 +1605,20 @@ pub mod tests_utils {
Self(log)
}
}

pub fn expect_query<T: TableSchemaView + StateView>(tx: &T, sql: &str, expect: Expect) {
let auth = AuthCtx::for_testing();
let schema = SchemaViewer::new(tx, &auth);

check_query(&schema, ExplainOptions::default(), sql, expect)
}

pub fn expect_sub<T: TableSchemaView + StateView>(tx: &T, sql: &str, expect: Expect) {
let auth = AuthCtx::for_testing();
let schema = SchemaViewer::new(tx, &auth);

check_sub(&schema, ExplainOptions::default(), sql, expect)
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/sql/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pub(crate) fn compile_to_ast<T: TableSchemaView + StateView>(
) -> Result<Vec<SqlAst>, DBError> {
// NOTE: The following ensures compliance with the 1.0 sql api.
// Come 1.0, it will have replaced the current compilation stack.
compile_sql_stmt(sql_text, &SchemaViewer::new(tx, auth))?;
compile_sql_stmt(sql_text, &SchemaViewer::new(tx, auth), false)?;

let dialect = PostgreSqlDialect {};
let ast = Parser::parse_sql(&dialect, sql_text).map_err(|error| DBError::SqlParser {
Expand Down
Loading
Loading