Skip to content

MOD-10153: New APPLY function case()#6332

Merged
nafraf merged 17 commits intomasterfrom
nafraf_case-func
Jun 20, 2025
Merged

MOD-10153: New APPLY function case()#6332
nafraf merged 17 commits intomasterfrom
nafraf_case-func

Conversation

@nafraf
Copy link
Collaborator

@nafraf nafraf commented Jun 17, 2025

Description:

Add a conditional case() function to aggregation pipeline APPLY stage for ternary conditional logic.

A clear and concise description of what the PR is solving, including:

  1. Current:
    Query error when trying to APPLY expression on results of a UNION QUERY where results could be present in the TEXT query but not in the VECTOR query.
  2. Change:
    Implement new function case(condition, if_true, if_false)
  3. Outcome:

Which additional issues this PR fixes

  1. MOD-10153

Main objects this PR modified

  1. ...

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

@nafraf nafraf marked this pull request as ready for review June 17, 2025 17:41
@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.87%. Comparing base (8e3a0c6) to head (f6e469e).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/aggregate/functions/string.c 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6332      +/-   ##
==========================================
- Coverage   88.89%   88.87%   -0.03%     
==========================================
  Files         247      247              
  Lines       41275    41291      +16     
  Branches     3483     3483              
==========================================
+ Hits        36693    36696       +3     
- Misses       4539     4552      +13     
  Partials       43       43              
Flag Coverage Δ
flow 81.45% <87.50%> (-0.11%) ⬇️
unit 46.86% <75.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nafraf nafraf requested review from Copilot and oshadmi June 17, 2025 20:26

This comment was marked as outdated.

@nafraf nafraf requested a review from Copilot June 17, 2025 22:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new APPLY stage function, case(), for supporting ternary conditional logic in aggregation pipelines. The changes include new test cases covering various scenarios for the case() function, placeholder registration of the case() function in the function registry, and its evaluation implementation in the expression evaluation code.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/pytests/test_case.py New tests for validating the case() function with different conditions.
src/aggregate/functions/string.c Registers the new case() function with a placeholder implementation.
src/aggregate/expr/expression.c Implements evalFuncCase() to properly evaluate the case() function logic.
Comments suppressed due to low confidence (1)

src/aggregate/functions/string.c:279

  • Consider expanding the comment for func_case to clarify that it serves solely for function registration and that its execution logic is deferred to evalFuncCase in expression.c.
int func_case(ExprEval *ctx, RSValue *argv, size_t argc, RSValue *result) {

@nafraf nafraf requested a review from raz-mon June 19, 2025 13:40
Copy link
Collaborator

@oshadmi oshadmi left a comment

Choose a reason for hiding this comment

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

😎 Few comments

oshadmi
oshadmi previously approved these changes Jun 19, 2025
@oshadmi oshadmi enabled auto-merge June 19, 2025 22:23
@oshadmi oshadmi added this pull request to the merge queue Jun 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 19, 2025
@nafraf nafraf added this pull request to the merge queue Jun 20, 2025
Merged via the queue into master with commit f338602 Jun 20, 2025
21 checks passed
@nafraf nafraf deleted the nafraf_case-func branch June 20, 2025 01:43
@redisearch-backport-pull-request
Copy link
Contributor

Backport failed for 2.10, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 2.10
git worktree add -d .worktree/backport-6332-to-2.10 origin/2.10
cd .worktree/backport-6332-to-2.10
git switch --create backport-6332-to-2.10
git cherry-pick -x f338602a603ffe2fdd9498b2feb4f34e4ae444a3

redisearch-backport-pull-request bot pushed a commit that referenced this pull request Jun 20, 2025
* WIP: Implement func_case

* Add tests

* Test nested case

* Rename testNestedCase to testNestedCaseAndGroup

* Add test for invalid apply expressions

* Remove TODO comment

* Fix flaky test

* Test with document which doesn't have neither of the fields.

* Add unit tests

* Add tests for NULL and missing fields

* Add more unit tests

* refactor evalFuncCase and update test cases for func_case handling

* Fix typo

* Refactor testCaseWithLogicalOperators and testCaseWithMissingFields to improve product classification and result validation

* Add test with deep nesting of case

* One more simple test

---------

Co-authored-by: oshadmi <[email protected]>
(cherry picked from commit f338602)
@redisearch-backport-pull-request
Copy link
Contributor

Successfully created backport PR for 8.0:

nafraf added a commit that referenced this pull request Jun 20, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jun 20, 2025
* MOD-10153: New APPLY function case() (#6332)

(cherry picked from commit f338602)

* Guard case() by ENABLE_UNSTABLE_FEATURES

* Add argument validation for case() function and corresponding tests

* Fix func_case function signature

* Free arg list in parser

* Remove unnecessary error handling for unknown function names in parser
github-merge-queue bot pushed a commit that referenced this pull request Jun 26, 2025
* MOD-10153: New APPLY function case() (#6332)

* WIP: Implement func_case

* Add tests

* Test nested case

* Rename testNestedCase to testNestedCaseAndGroup

* Add test for invalid apply expressions

* Remove TODO comment

* Fix flaky test

* Test with document which doesn't have neither of the fields.

* Add unit tests

* Add tests for NULL and missing fields

* Add more unit tests

* refactor evalFuncCase and update test cases for func_case handling

* Fix typo

* Refactor testCaseWithLogicalOperators and testCaseWithMissingFields to improve product classification and result validation

* Add test with deep nesting of case

* One more simple test

---------

Co-authored-by: oshadmi <[email protected]>
(cherry picked from commit f338602)

* Guarde case() by search-enable-unstable-features

* Enable Unstable features for unit-tests

---------

Co-authored-by: nafraf <[email protected]>
Co-authored-by: oshadmi <[email protected]>
Co-authored-by: nafraf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants