MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / apply_query_modifiers

Function apply_query_modifiers

graphlite/src/ast/parser.rs:364–405  ·  view source on GitHub ↗

Apply ORDER BY and LIMIT modifiers to any query type This is the unified approach - one function handles all query variants

(
    query: Query,
    order_clause: Option<OrderClause>,
    limit_clause: Option<LimitClause>,
)

Source from the content-addressed store, hash-verified

362/// Apply ORDER BY and LIMIT modifiers to any query type
363/// This is the unified approach - one function handles all query variants
364fn apply_query_modifiers(
365 query: Query,
366 order_clause: Option<OrderClause>,
367 limit_clause: Option<LimitClause>,
368) -> Query {
369 match (order_clause, limit_clause) {
370 // No modifiers - return query as-is
371 (None, None) => query,
372
373 // Has modifiers - apply them based on query type
374 (order, limit) => {
375 match query {
376 // For set operations, apply modifiers directly to the SetOperation struct
377 Query::SetOperation(mut set_op) => {
378 set_op.order_clause = order;
379 set_op.limit_clause = limit;
380 Query::SetOperation(set_op)
381 }
382
383 // For BasicQuery, apply modifiers directly to preserve GROUP BY/HAVING
384 // BasicQuery already has order_clause and limit_clause fields
385 Query::Basic(mut basic_query) => {
386 // Only override if not already set (basic_query parser may have consumed them)
387 if basic_query.order_clause.is_none() {
388 basic_query.order_clause = order;
389 }
390 if basic_query.limit_clause.is_none() {
391 basic_query.limit_clause = limit;
392 }
393 Query::Basic(basic_query)
394 }
395
396 // For other query types, use the Limited wrapper
397 _ => Query::Limited {
398 query: Box::new(query),
399 order_clause: order,
400 limit_clause: limit,
401 },
402 }
403 }
404 }
405}
406
407/// Parse complete query with clean precedence: core query + modifiers
408/// This implements Option 3: Restructured Parser Precedence

Callers 1

parse_set_operationFunction · 0.85

Calls 1

SetOperationClass · 0.85

Tested by

no test coverage detected