Skip to main content

waratah_text/
rebuild.rs

1//! The text index rebuild CORE: one implementation, two shells.
2//!
3//! The startup auto-build (compute startup, streaming over RPC) and the
4//! offline `waratah text rebuild-index` CLI share everything below their IO
5//! shells: term classification (the six string-literal families), lexical
6//! resolution (registry for hash-referenced values and language tags), and
7//! per-page document frames. The shells own transport only — the same split
8//! the geo rebuild uses, so the two paths can never drift.
9//!
10//! The walk is compute-driven (the partition lacks registry access): it
11//! scans O-axis head terms over the six string type-byte prefixes, resolves
12//! hash-referenced lexicals, and posts `TextIndexDoc` frames. The partition
13//! commits and reloads its reader per frame, so a frame is searchable when
14//! its RPC returns. `FinishTextIndexRebuild` stamps
15//! `epoch = max commit_ts observed on the partition` under the lease.
16//!
17//! Rebuild safety mirrors the plan's wipe rule: the STARTUP build wipes
18//! first (nothing is serving, a crash leaves no epoch and the next start
19//! wipes again); a build started WHILE SERVING is additive (an in-progress
20//! write's document may be committed while its row is not yet visible to
21//! the walk, so a wipe could delete it and the walk would not re-derive it).
22
23use std::collections::HashSet;
24
25use waratah_compute::{ComputeError, HexastoreGeo, HexastoreScan, StringResolve};
26use waratah_storage::{
27    DomainScanHit, EncodedTerm, IndexPermutation, SnapshotId, StrHash, TextIndexDoc,
28    encode_term_bytes,
29};
30
31/// Head page for the discovery walk (same shape as the geo driver).
32pub const HEAD_PAGE: u64 = 50_000;
33
34/// The six string-literal type bytes (`waratah_storage::encode::binary`
35/// keeps them crate-private; the wire layout is stable, and the geo driver
36/// shell declares its own copies of the same table).
37const TYPE_SMALL_STRING_LITERAL: u8 = 16;
38const TYPE_BIG_STRING_LITERAL: u8 = 17;
39const TYPE_SMALL_SMALL_LANG_STRING_LITERAL: u8 = 20;
40const TYPE_SMALL_BIG_LANG_STRING_LITERAL: u8 = 21;
41const TYPE_BIG_SMALL_LANG_STRING_LITERAL: u8 = 22;
42const TYPE_BIG_BIG_LANG_STRING_LITERAL: u8 = 23;
43
44/// O-axis head prefixes covering every indexed string-literal family: one
45/// bare byte each (values and language tags both discoverable, hash-referenced
46/// or inline).
47pub fn text_head_prefixes() -> Vec<Vec<u8>> {
48    [
49        TYPE_SMALL_STRING_LITERAL,
50        TYPE_BIG_STRING_LITERAL,
51        TYPE_SMALL_SMALL_LANG_STRING_LITERAL,
52        TYPE_SMALL_BIG_LANG_STRING_LITERAL,
53        TYPE_BIG_SMALL_LANG_STRING_LITERAL,
54        TYPE_BIG_BIG_LANG_STRING_LITERAL,
55    ]
56    .into_iter()
57    .map(|byte| vec![byte])
58    .collect()
59}
60
61/// Whether a walked head term is an indexed string-literal family.
62pub fn is_text_term(term: &EncodedTerm) -> bool {
63    matches!(
64        term,
65        EncodedTerm::SmallStringLiteral(_)
66            | EncodedTerm::BigStringLiteral { .. }
67            | EncodedTerm::SmallSmallLangStringLiteral { .. }
68            | EncodedTerm::SmallBigLangStringLiteral { .. }
69            | EncodedTerm::BigSmallLangStringLiteral { .. }
70            | EncodedTerm::BigBigLangStringLiteral { .. }
71    )
72}
73
74/// The registry hashes one string-literal term needs resolved (value and,
75/// for the big-language variants, the language tag).
76pub fn hashes_of(term: &EncodedTerm) -> Vec<StrHash> {
77    match term {
78        EncodedTerm::BigStringLiteral { value_id } => vec![*value_id],
79        EncodedTerm::SmallBigLangStringLiteral { language_id, .. } => vec![*language_id],
80        EncodedTerm::BigSmallLangStringLiteral { value_id, .. } => vec![*value_id],
81        EncodedTerm::BigBigLangStringLiteral {
82            value_id,
83            language_id,
84        } => {
85            vec![*value_id, *language_id]
86        }
87        _ => Vec::new(),
88    }
89}
90
91/// Assemble the document for one resolved string literal.
92///
93/// `resolved` answers the hashes of [`hashes_of`] positionally. A missing
94/// hash (registry miss) returns `None`: the index is a superset by
95/// contract, but a missing LEXICAL cannot be searched, so skipping keeps
96/// the document set honest (the rebuild report surfaces it; the direct
97/// evaluation road skips the value for the same reason).
98pub(crate) fn document_for(
99    term: &EncodedTerm,
100    resolved: &[Option<String>],
101) -> Option<TextIndexDoc> {
102    let term_bytes = encode_term_bytes(term);
103    let (lexical, language) = match term {
104        EncodedTerm::SmallStringLiteral(value) => (value.as_str().to_owned(), None),
105        EncodedTerm::BigStringLiteral { .. } => {
106            let Some(Some(lexical)) = resolved.first() else {
107                return None;
108            };
109            (lexical.clone(), None)
110        }
111        EncodedTerm::SmallSmallLangStringLiteral { value, language } => (
112            value.as_str().to_owned(),
113            Some(language.as_str().to_owned()),
114        ),
115        EncodedTerm::SmallBigLangStringLiteral { value, .. } => {
116            let Some(Some(language)) = resolved.first() else {
117                return None;
118            };
119            (value.as_str().to_owned(), Some(language.clone()))
120        }
121        EncodedTerm::BigSmallLangStringLiteral { language, .. } => {
122            let Some(Some(lexical)) = resolved.first() else {
123                return None;
124            };
125            (lexical.clone(), Some(language.as_str().to_owned()))
126        }
127        EncodedTerm::BigBigLangStringLiteral { .. } => {
128            let (Some(Some(lexical)), Some(Some(language))) = (resolved.first(), resolved.get(1))
129            else {
130                return None;
131            };
132            (lexical.clone(), Some(language.clone()))
133        }
134        _ => return None,
135    };
136    Some(TextIndexDoc {
137        term: term_bytes,
138        predicate: Vec::new(),
139        lexical,
140        language,
141    })
142}
143
144/// Totals of one rebuild pass.
145#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
146pub struct RebuildReport {
147    /// Distinct string literals walked (every family member).
148    pub terms_walked: u64,
149    /// Documents posted (terms whose lexical resolved).
150    pub docs_posted: u64,
151    /// Terms skipped because a registry hash did not resolve. Non-zero means
152    /// the epoch was NOT stamped: the index stays untrusted and the next
153    /// start retries the walk.
154    pub unresolved: u64,
155    /// Terms skipped because their lexical exceeds the indexed-lexical limit
156    /// (`MAX_INDEXED_LEXICAL_BYTES`). Same consequence as `unresolved`: no
157    /// document for a visible row, so no stamp.
158    pub oversized: u64,
159    /// The stamped build epoch; 0 when nothing was stamped (a lease lost
160    /// before finish, or unresolved / oversized terms above).
161    pub epoch: u64,
162}
163
164impl RebuildReport {
165    /// One-line summary for the startup log / CLI output.
166    pub fn summary(&self) -> String {
167        format!(
168            "{} terms walked, {} documents posted, {} unresolved, {} oversized, epoch {}",
169            self.terms_walked, self.docs_posted, self.unresolved, self.oversized, self.epoch
170        )
171    }
172
173    /// True when every walked term carries its document — the stamp gate:
174    /// a visible row without its document is the silently-missing-candidate
175    /// state, so a walk with [`RebuildReport::unresolved`] or
176    /// [`RebuildReport::oversized`] terms must not stamp the epoch.
177    pub fn is_complete(&self) -> bool {
178        self.unresolved == 0 && self.oversized == 0
179    }
180}
181
182/// One walked batch's assembled outcome.
183#[derive(Debug, Default)]
184pub struct RebuildBatch {
185    /// Documents to post, in term order (each within the indexed-lexical
186    /// limit).
187    pub docs: Vec<TextIndexDoc>,
188    /// Terms whose registry hashes did not resolve.
189    pub unresolved: u64,
190    /// Terms whose lexical exceeds the indexed-lexical limit.
191    pub oversized: u64,
192}
193
194/// Assemble one walked batch of `(predicate, literal)` documents.
195///
196/// Pairs each walked object term with its positional slice of `resolved` — the
197/// concatenation of every term's [`hashes_of`] results, resolved in order —
198/// and with the predicates that reference it (`predicates_by_object`, one list
199/// per term, from the O-axis `OPSG` domain scan). An object under several
200/// predicates becomes one document per predicate, which is the index's
201/// `(predicate, literal)` identity. `allow`, when set, restricts the posted
202/// documents to the configured predicate allowlist; an object with no allowed
203/// predicate is intentionally unindexed and is not a missed document.
204///
205/// Both rebuild drivers (the startup shell over RPC clients, the offline CLI
206/// over direct store handles) walk with their own scan and resolve surfaces and
207/// share THIS core, so document assembly and the indexed-lexical gate cannot
208/// drift between them.
209pub fn assemble_batch(
210    terms: &[EncodedTerm],
211    predicates_by_object: &[Vec<EncodedTerm>],
212    resolved: &[Option<String>],
213    allow: Option<&HashSet<waratah_storage::StrHash>>,
214) -> RebuildBatch {
215    assert_eq!(
216        terms.len(),
217        predicates_by_object.len(),
218        "one predicate list per walked object"
219    );
220    let mut batch = RebuildBatch::default();
221    let mut seen: HashSet<Vec<u8>> = HashSet::new();
222    let mut offset = 0usize;
223    for (index, term) in terms.iter().enumerate() {
224        let needed = hashes_of(term).len();
225        let slice = &resolved[offset..offset + needed];
226        offset += needed;
227        // The allowlist gate runs BEFORE resolution: an object with no allowed
228        // predicate is not going to be indexed, so a missing lexical for it
229        // must not block the stamp.
230        let allowed: Vec<&EncodedTerm> = predicates_by_object[index]
231            .iter()
232            .filter(|predicate| match predicate {
233                EncodedTerm::NamedNode { iri_id } => {
234                    allow.is_none_or(|allow| allow.contains(iri_id))
235                }
236                _ => false,
237            })
238            .collect();
239        if allowed.is_empty() {
240            continue;
241        }
242        let Some(shape) = document_for(term, slice) else {
243            batch.unresolved += 1;
244            continue;
245        };
246        // A lexical above the indexed-lexical limit cannot become a document:
247        // skip it and count it — the stamp gate refuses the epoch while any
248        // term lacks its document.
249        if shape.lexical.len() > waratah_storage::text_index::MAX_INDEXED_LEXICAL_BYTES {
250            batch.oversized += 1;
251            continue;
252        }
253        for predicate in allowed {
254            let predicate_bytes = encode_term_bytes(predicate);
255            if !seen.insert(waratah_storage::text_index::text_index_key(
256                &predicate_bytes,
257                &shape.term,
258            )) {
259                continue;
260            }
261            batch.docs.push(TextIndexDoc {
262                term: shape.term.clone(),
263                predicate: predicate_bytes,
264                lexical: shape.lexical.clone(),
265                language: shape.language.clone(),
266            });
267        }
268    }
269    batch
270}
271
272/// Group `(object, predicate)` domain-scan hits into one predicate list per
273/// walked object, aligned with `terms`.
274///
275/// The domain scan emits hits in constraint order and `terms` is the sorted
276/// constraint list, so a single forward merge is linear in both inputs. The
277/// merge asserts that ordering instead of assuming it: a hit whose constraint
278/// is behind the cursor means the caller's contract broke, and silently
279/// ignoring the hit (or attaching it to a later object) would index a
280/// predicate under the wrong literal — a wrong answer, not a slow one.
281pub fn group_predicates(terms: &[EncodedTerm], hits: &[DomainScanHit]) -> Vec<Vec<EncodedTerm>> {
282    let mut out = vec![Vec::new(); terms.len()];
283    let mut index = 0;
284    for hit in hits {
285        while index < terms.len() && terms[index] != hit.constraint {
286            index += 1;
287        }
288        assert!(
289            index < terms.len(),
290            "domain-scan hits must be grouped in `terms` order: {:?} is not a walked object at \
291             or after the previous hit's constraint",
292            hit.constraint
293        );
294        out[index].push(hit.term.clone());
295    }
296    out
297}
298
299/// Drive one full text-index rebuild against `hexastore` + `registry`.
300///
301/// The caller has already decided the WIPE policy (`RebuildTextIndexRequest`
302/// carries it): the startup shell passes `wipe = true`, the CLI-repair shell
303/// `wipe = false`. Returns `None` when another driver holds the lease (the
304/// caller waits on Describe, like the geo driver).
305pub async fn drive_text_rebuild<H, R>(
306    hexastore: &H,
307    registry: &R,
308    analyzer: &str,
309    seed_chars: u32,
310    fingerprint: &str,
311    allow: Option<&HashSet<StrHash>>,
312    wipe: bool,
313) -> Result<Option<RebuildReport>, ComputeError>
314where
315    H: HexastoreScan + HexastoreGeo + Sync,
316    R: StringResolve + Sync,
317{
318    let status_to_compute = |status: tonic::Status| {
319        ComputeError::UnsupportedSparql(format!("text rebuild RPC failed: {status}"))
320    };
321    let (started, _already, lease_token) = hexastore
322        .rebuild_text_index(analyzer, seed_chars, fingerprint, wipe)
323        .await
324        .map_err(status_to_compute)?;
325    if !started {
326        return Ok(None);
327    }
328    let mut report = RebuildReport::default();
329    let renew = || async {
330        hexastore
331            .renew_text_rebuild_lease(lease_token)
332            .await
333            .map_err(status_to_compute)
334    };
335    // Discovery + document frames in one pass: page the O-axis heads over
336    // the string prefixes, resolve this page's hashes in one registry RPC,
337    // post the documents, renew the lease. Distinct terms per page: the
338    // head scan already returns distinct heads.
339    let prefixes = text_head_prefixes();
340    let mut cursor: Option<EncodedTerm> = None;
341    loop {
342        let terms = hexastore
343            .scan_axis_head(
344                IndexPermutation::Opsg,
345                SnapshotId::latest(),
346                HEAD_PAGE,
347                cursor.as_ref(),
348                None,
349                None,
350                false,
351                &prefixes,
352            )
353            .await
354            .map_err(status_to_compute)?;
355        if terms.is_empty() {
356            break;
357        }
358        let strings: Vec<StrHash> = terms.iter().flat_map(hashes_of).collect();
359        let resolved = if strings.is_empty() {
360            Vec::new()
361        } else {
362            registry
363                .resolve_strings(&strings)
364                .await
365                .map_err(status_to_compute)?
366        };
367        // One `OPSG` domain scan per page resolves the predicates that
368        // reference each object: the head walk gives distinct objects, the
369        // domain scan gives the `(predicate, object)` pairs the index keys on.
370        // The O partition serves both, so a page costs one extra scan, not
371        // one per object.
372        let hits = hexastore
373            .scan_domain(
374                IndexPermutation::Opsg,
375                &terms,
376                SnapshotId::latest(),
377                0,
378                None,
379                None,
380                None,
381                None,
382                false,
383            )
384            .await
385            .map_err(status_to_compute)?;
386        let predicates_by_object = group_predicates(&terms, &hits);
387        // Walk the per-term hash slices positionally (shared core with the
388        // offline CLI — see `assemble_batch`).
389        let batch = assemble_batch(&terms, &predicates_by_object, &resolved, allow);
390        report.terms_walked += terms.len() as u64;
391        report.docs_posted += batch.docs.len() as u64;
392        report.unresolved += batch.unresolved;
393        report.oversized += batch.oversized;
394        if !batch.docs.is_empty() {
395            hexastore
396                .put_text_index(&batch.docs)
397                .await
398                .map_err(status_to_compute)?;
399        }
400        cursor = terms.last().cloned();
401        renew().await?;
402    }
403    // A walk that skipped terms WITHOUT documents must NOT stamp: a visible
404    // row without its document is the silently-missing-candidate state —
405    // both query forms would drop it from a TRUSTED index. That covers
406    // registry misses (unresolved) and lexicals above the indexed-lexical
407    // limit (oversized). Release the lease without stamping: the index
408    // stays untrusted (`text:query` fails with the repair hint, string
409    // functions answer exactly) and the next start retries the walk.
410    if !report.is_complete() {
411        hexastore
412            .finish_text_index_rebuild(lease_token, false)
413            .await
414            .map_err(status_to_compute)?;
415        eprintln!(
416            "text rebuild-index: {} lexical(s) unresolved in the registry, {} above the \
417             indexed-lexical limit; epoch NOT stamped — the index stays untrusted and the \
418             next startup retries the walk",
419            report.unresolved, report.oversized
420        );
421        return Ok(Some(report));
422    }
423    report.epoch = hexastore
424        .finish_text_index_rebuild(lease_token, true)
425        .await
426        .map_err(status_to_compute)?;
427    Ok(Some(report))
428}
429
430#[cfg(test)]
431mod tests {
432    use super::*;
433
434    fn small(value: &str) -> waratah_storage::SmallString {
435        value.parse().expect("short inline string")
436    }
437
438    #[test]
439    fn prefixes_cover_exactly_the_six_families() {
440        let prefixes = text_head_prefixes();
441        assert_eq!(prefixes.len(), 6);
442        for prefix in &prefixes {
443            assert_eq!(prefix.len(), 1, "bare type bytes, no hash narrowing");
444        }
445        // Bare type-byte walk finds every family member.
446        for term in [
447            EncodedTerm::SmallStringLiteral(small("abc")),
448            EncodedTerm::BigStringLiteral {
449                value_id: StrHash::new("long"),
450            },
451            EncodedTerm::SmallSmallLangStringLiteral {
452                value: small("hallo"),
453                language: small("de"),
454            },
455            EncodedTerm::SmallBigLangStringLiteral {
456                value: small("hi"),
457                language_id: StrHash::new("en"),
458            },
459            EncodedTerm::BigSmallLangStringLiteral {
460                value_id: StrHash::new("long"),
461                language: small("fr"),
462            },
463            EncodedTerm::BigBigLangStringLiteral {
464                value_id: StrHash::new("long"),
465                language_id: StrHash::new("fr"),
466            },
467        ] {
468            assert!(is_text_term(&term), "{term:?} must classify as text");
469        }
470        assert!(!is_text_term(&EncodedTerm::NamedNode {
471            iri_id: StrHash::new("http://ex/")
472        }));
473    }
474
475    #[test]
476    fn documents_assemble_from_inline_and_resolved_lexicals() {
477        // Inline value, inline language.
478        let inline = EncodedTerm::SmallSmallLangStringLiteral {
479            value: small("salut"),
480            language: small("fr"),
481        };
482        let doc = document_for(&inline, &[]).expect("inline lexical assembles");
483        // Resolved value, inline language.
484        let big_small = EncodedTerm::BigSmallLangStringLiteral {
485            value_id: StrHash::new("long lexical"),
486            language: small("en"),
487        };
488        let big_doc = document_for(&big_small, &[Some("long lexical".into())])
489            .expect("resolved lexical assembles");
490        assert_eq!(doc.lexical, "salut");
491        assert_eq!(doc.language.as_deref(), Some("fr"));
492        assert_eq!(doc.term, encode_term_bytes(&inline));
493        assert_eq!(big_doc.lexical, "long lexical");
494        assert_eq!(big_doc.language.as_deref(), Some("en"));
495        assert_eq!(big_doc.term, encode_term_bytes(&big_small));
496    }
497
498    #[test]
499    fn a_registry_miss_skips_the_term_and_counts_it() {
500        let term = EncodedTerm::BigStringLiteral {
501            value_id: StrHash::new("missing"),
502        };
503        assert!(document_for(&term, &[None]).is_none());
504    }
505
506    #[test]
507    fn assemble_batch_classifies_docs_unresolved_and_oversized() {
508        // Three terms in one walked batch: an inline small literal (no
509        // registry hashes), a big literal whose lexical resolves, and a big
510        // literal above the indexed-lexical limit. The positional slicing
511        // must stay aligned across the mixed hash counts.
512        let inline = EncodedTerm::SmallStringLiteral(small("inline"));
513        let big = EncodedTerm::BigStringLiteral {
514            value_id: StrHash::new("big"),
515        };
516        let oversized = EncodedTerm::BigStringLiteral {
517            value_id: StrHash::new("huge"),
518        };
519        let terms = vec![inline, big.clone(), oversized];
520        let big_lexical = "b".to_owned();
521        let huge_lexical = "h".repeat(waratah_storage::text_index::MAX_INDEXED_LEXICAL_BYTES + 1);
522        let resolved = vec![Some(big_lexical), Some(huge_lexical)];
523        let predicate = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/predicate"));
524        let predicates_by_object = vec![
525            vec![predicate.clone()],
526            vec![predicate.clone()],
527            vec![predicate.clone()],
528        ];
529
530        let batch = assemble_batch(&terms, &predicates_by_object, &resolved, None);
531        assert_eq!(batch.docs.len(), 2, "inline + resolved big");
532        assert_eq!(batch.unresolved, 0);
533        assert_eq!(batch.oversized, 1, "the over-limit lexical");
534        assert_eq!(batch.docs[0].lexical, "inline");
535        assert_eq!(batch.docs[1].lexical, "b");
536
537        // A registry miss classifies as unresolved, not oversized.
538        let batch = assemble_batch(&[big], &[vec![predicate]], &[None], None);
539        assert_eq!(batch.unresolved, 1);
540        assert!(batch.docs.is_empty());
541    }
542
543    #[test]
544    fn assemble_batch_keys_one_document_per_allowed_predicate_pair() {
545        let term = EncodedTerm::SmallStringLiteral(small("report"));
546        let name = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/name"));
547        let note = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/note"));
548
549        // The same literal under two predicates posts two documents: the
550        // document identity is `(predicate, literal)`.
551        let batch = assemble_batch(
552            std::slice::from_ref(&term),
553            &[vec![name.clone(), note.clone()]],
554            &[],
555            None,
556        );
557        assert_eq!(batch.docs.len(), 2);
558
559        // The allowlist gates before resolution: the excluded predicate's
560        // document never materializes.
561        let allow: HashSet<StrHash> = [StrHash::new("http://ex/name")].into_iter().collect();
562        let batch = assemble_batch(&[term], &[vec![name.clone(), note]], &[], Some(&allow));
563        assert_eq!(batch.docs.len(), 1);
564        assert_eq!(batch.docs[0].predicate, encode_term_bytes(&name));
565
566        // An object with no allowed predicate is intentionally unindexed and
567        // is not a missed document.
568        let only_note = HashSet::from([StrHash::new("http://ex/missing")]);
569        let batch = assemble_batch(
570            &[EncodedTerm::SmallStringLiteral(small("x"))],
571            &[vec![name]],
572            &[],
573            Some(&only_note),
574        );
575        assert!(batch.docs.is_empty());
576        assert_eq!(batch.unresolved, 0);
577        assert_eq!(batch.oversized, 0);
578    }
579
580    #[test]
581    fn group_predicates_aligns_hits_with_the_walked_objects() {
582        let a = EncodedTerm::SmallStringLiteral(small("a"));
583        let b = EncodedTerm::SmallStringLiteral(small("b"));
584        let p = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/p"));
585        let q = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/q"));
586        let hits = vec![
587            DomainScanHit {
588                constraint: a.clone(),
589                term: p.clone(),
590            },
591            DomainScanHit {
592                constraint: a.clone(),
593                term: q.clone(),
594            },
595            DomainScanHit {
596                constraint: b.clone(),
597                term: p.clone(),
598            },
599        ];
600        let grouped = group_predicates(&[a, b], &hits);
601        assert_eq!(grouped[0], vec![p.clone(), q]);
602        assert_eq!(grouped[1], vec![p]);
603    }
604
605    #[test]
606    #[should_panic(expected = "grouped in `terms` order")]
607    fn group_predicates_rejects_hits_that_go_backwards() {
608        // A domain scan that emitted a later object's hits before an earlier
609        // object's would have its second hit silently dropped by a forward
610        // merge (or attached to the wrong object). The merge must fail loudly.
611        let a = EncodedTerm::SmallStringLiteral(small("a"));
612        let b = EncodedTerm::SmallStringLiteral(small("b"));
613        let p = EncodedTerm::from(&oxrdf::NamedNode::new_unchecked("http://ex/p"));
614        let hits = vec![
615            DomainScanHit {
616                constraint: b.clone(),
617                term: p.clone(),
618            },
619            DomainScanHit {
620                constraint: a.clone(),
621                term: p,
622            },
623        ];
624        let _ = group_predicates(&[a, b], &hits);
625    }
626}