Skip to content

feat(opencypher): support numeric scalar functions in WHERE and aggregates (fixes #216) - #217

Open
Vivek77741 wants to merge 2 commits into
hydra-db:mainfrom
Vivek77741:feat/opencypher-numeric-scalar-functions
Open

Vivek77741 wants to merge 2 commits into
hydra-db:mainfrom
Vivek77741:feat/opencypher-numeric-scalar-functions

Conversation

@Vivek77741

Copy link
Copy Markdown

Fixes #216

Motivation & Summary

In standard OpenCypher (and ISO GQL), numeric scalar functions are essential for performing mathematical filtering and calculations on node and relationship properties. Previously, HydraDB's OpenCypher parser and execution engine lacked support for these functions, rejecting queries such as MATCH (n:Item) WHERE abs(n.delta) > 5 RETURN n.id or RETURN collect(abs(n.delta)) with parse or unsupported query errors.

This PR adds support for standard numeric scalar functions:

  • abs(n): Absolute value of integers (Integer and SignedInteger) and floats.
  • ceil(n): Smallest integer greater than or equal to n (preserving integers, ceiling floats).
  • floor(n): Largest integer less than or equal to n (preserving integers, flooring floats).
  • round(n): Nearest integer rounding for numeric values (preserving integers, rounding floats).
  • sign(n): Signum indicator (-1, 0, or 1) for numeric values.

Changes

  • AST & Expression Lowering (src/query/opencypher.rs):
    • Extended RowExpression with Abs, Ceil, Floor, Round, and Sign variants wrapping Box<RowExpression>.
    • In lower_row_expression, lowered sys::CYPHER_AST_APPLY_OPERATOR invocations for single-argument abs, ceil, floor, round, and sign calls.
    • Formatted function call names in row_expression_name for fallback column aliases.
    • Added parser unit test lowers_numeric_scalar_function_expressions.
  • Query Execution Engine (src/shard/query.rs):
    • Evaluated Abs, Ceil, Floor, Round, and Sign in eval_row_expression for row predicate comparisons.
    • Evaluated Abs, Ceil, Floor, Round, and Sign in expression_query_value for aggregate projections.
    • Missing and non-numeric property values safely propagate as RowScalarValue::Missing and None (preserving three-valued logic).
    • Added unit test test_eval_row_expression_numeric_scalar_functions verifying execution across Integer, SignedInteger, Float, and missing values.
  • Documentation (cypher-compat.md):
    • Documented abs, ceil, floor, round, and sign support in WHERE comparisons and aggregate expressions.

@Vivek77741
Vivek77741 requested a review from a team September 21, 2026 18:29
@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previously reported aggregate-type limitation is now enforced during lowering, and aggregate evaluator coverage has been completed.

Findings

  1. P2 Aggregate Evaluators Lack Coverage

Summary

Adds numeric scalar-function support to OpenCypher row predicates and compatible aggregate arguments.

  • Lowers and evaluates abs, ceil, floor, round, and sign.
  • Supports these functions under collect and count, while explicitly rejecting them under integer-only sum and avg.
  • Documents the supported aggregate combinations.
  • Adds evaluator and end-to-end coverage for predicates, aggregate execution, missing values, and rejected aggregate combinations.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Q[OpenCypher query] --> L[Lower scalar function to RowExpression]
    L --> W{Usage context}
    W -->|WHERE comparison| E[Evaluate RowScalarValue]
    W -->|collect or count| A[Evaluate QueryValue and accumulate]
    W -->|sum or avg| R[Reject during lowering]
Loading

Reviews (2) · Last reviewed commit: "fix(query): restrict numeric scalar func..."

Comment thread src/query/opencypher.rs
Comment thread src/shard/query.rs Outdated
Comment on lines +9382 to +9392
// expression_query_value
assert_eq!(
expression_query_value(&row, &expr_abs_neg).unwrap(),
Some(QueryValue::Property(VertexPropertyValue::Integer(15)))
);
assert_eq!(
expression_query_value(&row, &expr_abs_missing).unwrap(),
None
);

// Predicate matching

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Aggregate Evaluators Lack Coverage

The aggregate-value evaluator separately implements all five new functions, but this test exercises expression_query_value only for abs. It never runs ceil, floor, round, or sign through an aggregate, and there is no parser-to-executor test for the documented aggregate syntax. Add end-to-end aggregate cases so differences between eval_row_expression and expression_query_value do not go unnoticed.

Knowledge Base Used: openCypher query interface

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@openhack-agent

Copy link
Copy Markdown

@Vivek77741 Only collaborators with push access can ask OpenHack to act on this repository.

@openhack-agent

Copy link
Copy Markdown

✅ OpenHack Summary

Security review of feat(opencypher): support numeric scalar functions in WHERE and aggregates (fixes #216). 4 changed files; 0 findings at or above the low reporting threshold.

P1: Critical 0   P2: High 0   P3: Medium 0   P4: Low 0

Confidence Score: 5/5

No reportable security findings were detected in this scan.

Security merge-readiness rubric: 1 = critical, 2 = high, 3 = medium, 4 = low, 5 = no reportable findings. This score reflects scan findings, not a guarantee of correctness or complete coverage.

Files Needing Attention: None

Important Files Changed
  • cypher-compat.md (modified)
  • src/query/opencypher.rs (modified)
  • src/shard/query.rs (modified)
  • src/tests.rs (modified)

Last reviewed commit: 7b40d4b · View review on OpenHack


TIP: Mention @openhack-agent in a PR comment to request a review or ask a question. Use @openhack-agent fix all for every finding, or @openhack-agent fix unresolved threads for open review threads only.

@openhack-agent openhack-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OpenHack reviewed this commit. See the OpenHack Summary for the confidence score and fix actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: support numeric scalar functions (abs, ceil, floor, round, sign) in OpenCypher queries

1 participant