8000 Clarify parser precedence and query test comments by adityamukho · Pull Request #990 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/query/datalog/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3833,9 +3833,8 @@ mod pushdown_tests {

#[test]
fn test_not_clause_ordering_correctness() {
// Two `not` clauses given in expensive-first source order; results must be
// identical regardless of which order the optimizer chooses to evaluate them.
// This is a correctness regression guard — semantics must not change.
// The source puts the more expensive `not` clause first. The result
// must be the same whichever clause the optimizer evaluates first.
let storage = FactStorage::new();
let executor = DatalogExecutor::new(storage);

Expand Down
20 changes: 11 additions & 9 deletions src/query/datalog/parser/statement.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! `transact` and `retract` statements, read one fact at a time (#550, spec
//! `2026-10-21-streaming-transactions-design.md` §3).
//!
//! A statement's errors are found in phases (spec §3.3): 1 tokens, 2 EDN
//! structure, 3 the command, 4 each fact's shape, 5 materialisation, 6 valid
//! windows. Today's whole-input code runs each phase over the whole statement
//! before the next, so it reports the first error of the earliest phase that
//! has one. The reader keeps that order in one pass that holds one fact at a
//! time: it records the error of the earliest phase found so far, runs only the
//! phases before it from then on, and reports it at the end of the input.
//! The parser checks each statement in six phases (spec §3.3): 1 tokens,
//! 2 EDN structure, 3 the command, 4 fact structure and options,
//! 5 materialisation, and 6 valid-time windows. The whole-input parser checks
//! the entire statement at each phase before moving to the next. The streaming
//! reader keeps one fact at a time but reports the same error: the first one
//! from the earliest failing phase. When it finds an error, it saves that
//! error and checks only earlier phases in the remaining input. If an earlier
//! phase fails later, that error takes precedence. It reports the saved error
//! at the end of the input.

use super::{Lexer, Parser, Token, parse_valid_time_map};
use crate::db::VALID_FROM_USE_TX_TIME;
Expand Down Expand Up @@ -378,8 +380,8 @@ fn read_facts(
}
}

/// Phase 4 for one fact: its shape and per-fact map, as `parse_transact` /
/// `parse_retract` check each fact.
/// Check one fact's vector and options map using the same rules as
/// `parse_transact` and `parse_retract` (phase 4).
fn fact_pattern(kind: Kind, fact: &EdnValue, defaults: Defaults) -> Result<Pattern> {
match kind {
Kind::Transact => {
Expand Down
34 changes: 18 additions & 16 deletions src/query/engine/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,12 +1800,13 @@ fn negation_bodies_run_per_row_or_once() {
assert!(read <= 150, "the body is read once");
}

/// `or` / `or-join` shapes (#546 PR 2), as `(find, clauses)`: branches
/// probed and keyed, new variables, keywords meeting refs, attributes, floats
/// and long strings as keys, branches reading outer variables, metadata and
/// the valid time, a branch with `not`, branches naming different outer
/// variables or no join variable, an `or` with nothing before it, a cross
/// product, deferred `not`s and expressions after an `or`.
/// `or` and `or-join` cases (#546 PR 2), as `(find, clauses)`.
/// Cover branches that use probes or join keys, newly bound variables,
/// keywords joining refs, and attributes, floats and long strings as keys.
/// Also cover branches that read outer variables, metadata or valid time,
/// a branch with `not`, different or missing join variables, a leading `or`,
/// a cross product,
/// and deferred `not` clauses and expressions after an `or`.
fn disjunctions() -> Vec<(&'static str, &'static str)> {
vec![
// Correlated: the branch's entity is imported.
Expand Down Expand Up @@ -3005,9 +3006,9 @@ fn value_probe_matches_as_joins_do() {
}
}

/// #721: a value probe that meets an entity no recorded keyword names, in
/// the middle of a batch, finishes as a hash join: the rows probed before
/// it, the rest of that batch and every later batch each join once.
/// If a value probe reaches an entity with no recorded keyword name partway
/// through a batch, the query finishes with a hash join (#721). The rows
/// already probed, the rest of that batch and all later batches each join once.
#[test]
fn value_probe_falls_back_mid_batch() {
// Six :tag values are refs, the others keywords, so probes by keyword
Expand Down Expand Up @@ -3062,9 +3063,9 @@ fn memory_db(dir: &std::path::Path, n: usize, limit: usize) -> Minigraf {
.unwrap()
}

/// One shape per operator that holds state, the operator that holds it
/// first, and the entities its database needs: more than one batch of
/// answer rows, few enough to stay fast.
/// One case per stateful operator: the first operator to hold state, the
/// number of entities in the fixture, and the query. Each fixture produces
/// more than one batch of results but stays small enough to run quickly.
const MEMORY_SHAPES: [(&str, usize, &str); 5] = [
(
"HashJoin",
Expand Down Expand Up @@ -4549,10 +4550,11 @@ fn ignored_aggregate_arguments_do_not_hide_upstream_failures() {
}
}

/// #863: the path events a nightly acceptance test reads. A width-10 tree of
/// 1,110 edges, pending: one leaf's ancestors take the small in-memory
/// alternative (#723). Checkpointed, 16 demanded leaves join their parents
/// by bound-value AVET probes (#721), and the alternative is not taken.
/// Check the path events read by nightly acceptance tests (#863) on a tree
/// of width 10 with 1,110 edges. With pending data, an ancestor query for one
/// leaf uses the small in-memory alternative (#723). After checkpointing,
/// the query selects 16 leaves with `:s/demand` and joins them to their parents
/// using bound-value AVET probes (#721) instead of the alternative.
fn count(db: &Minigraf, query: &str) -> usize {
let QueryResult::QueryResults { results, .. } = db.execute(query).expect("query") else {
panic!("expected query results");
Expand Down
Loading
0