Skip to content

Conversation

@martin-georgiev
Copy link
Owner

@martin-georgiev martin-georgiev commented Mar 30, 2025

Summary by CodeRabbit

  • New Features

    • Array manipulation functions (append, prepend, remove, and replace) have been updated to support a broader range of input types, including handling of null values.
    • Enhanced behavior for JSON update functions improves the clarity of output expectations.
  • Tests

    • Comprehensive test cases have been added and refined to ensure the correct processing of null values in array operations and to validate the improved output formats for JSON updates.

…`, `array_prepend()`, `array_remove()` and improve test scenarios for `NULL`
@coderabbitai
Copy link

coderabbitai bot commented Mar 30, 2025

Walkthrough

This pull request updates the node mapping in the SQL AST functions for handling arrays. In the functions for appending, prepending, removing, and replacing array elements, the mapping for ArithmeticPrimary has been replaced by one or more mappings for NewValue. In addition, the associated tests have been extended with new scenarios—including handling of null values—and the JSONB test has been restructured for enhanced clarity in its expected SQL/DQL outputs.

Changes

File(s) Change Summary
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppend.php
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrepend.php
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemove.php
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplace.php
Modified the customizeFunction method: removed the ArithmeticPrimary node mapping and introduced one or more mappings for NewValue to change the supported input node types.
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppendTest.php
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrependTest.php
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemoveTest.php
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplaceTest.php
Added test cases to verify that appending, prepending, removing, and replacing array elements correctly handle null values, including validations of SQL and DQL statements generated by the functions.
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbSetLaxTest.php Restructured expected SQL and DQL outputs by replacing plain SQL strings with descriptive associative array keys, thereby enhancing the semantic clarity and maintainability of the test cases.

Sequence Diagram(s)

sequenceDiagram
    participant U as User Query
    participant P as Doctrine Parser
    participant F as Array Function (e.g., ArrayAppend)
    participant S as SQL Generator

    U->>P: Submit query with array operation
    P->>F: Parse query and call customizeFunction
    F-->>P: Configure node mapping (now using NewValue)
    P->>S: Generate SQL/DQL based on updated mapping
    S-->>U: Return SQL/DQL result
Loading

Possibly related PRs

Poem

I'm a clever rabbit, hopping through code,
Shifting old mappings to a fresh new mode.
From ArithmeticPrimary to NewValue delight,
Our SQL and tests now dance in the light.
With each leap, our queries feel just right – hop on! 🐰


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1ccac and ff161f4.

📒 Files selected for processing (9)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppend.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrepend.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemove.php (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplace.php (1 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppendTest.php (2 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrependTest.php (2 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemoveTest.php (2 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplaceTest.php (2 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbSetLaxTest.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/**/*.php`: Use the PostgreSQL official documentation to verify that tests include comprehensive use cases and example SQL que...

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/**/*.php: Use the PostgreSQL official documentation to verify that tests include comprehensive use cases and example SQL queries for the tested SQL functions and operators.

  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplaceTest.php
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppendTest.php
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrependTest.php
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemoveTest.php
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbSetLaxTest.php
🧬 Code Definitions (4)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppend.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseFunction.php (1)
  • addNodeMapping (62-65)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrepend.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseFunction.php (1)
  • addNodeMapping (62-65)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplace.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseFunction.php (1)
  • addNodeMapping (62-65)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemove.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseFunction.php (1)
  • addNodeMapping (62-65)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest
  • GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
  • GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest
  • GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest
  • GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0
  • GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
  • GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest
  • GitHub Check: sloth
🔇 Additional comments (14)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplace.php (1)

21-22: Appropriate node mapping update to support NULL values

Good change replacing ArithmeticPrimary with NewValue node mappings. This modification enables proper handling of NULL values in the ARRAY_REPLACE function, which is fully supported by PostgreSQL's native implementation. The change aligns well with the function's expected behavior according to PostgreSQL documentation.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppend.php (1)

21-21: Appropriate node mapping update to support NULL values

Good change replacing ArithmeticPrimary with NewValue node mapping. This modification enables proper handling of NULL values in the ARRAY_APPEND function, which is fully supported by PostgreSQL's native implementation. The change maintains the function prototype while extending the types of values that can be appended to arrays.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrepend.php (1)

20-20: Appropriate node mapping update to support NULL values

Good change replacing ArithmeticPrimary with NewValue node mapping. This modification enables proper handling of NULL values in the ARRAY_PREPEND function, which is fully supported by PostgreSQL's native implementation. The parameter order (value first, then array) is correctly maintained.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayReplaceTest.php (2)

25-27: Good test coverage for NULL value scenarios

The additional test cases for expected SQL statements properly verify the NULL handling capabilities added to the ARRAY_REPLACE function. All three possible NULL scenarios are covered: NULL as search value, NULL as replacement value, and NULL for both. The SQL syntax correctly uses lowercase 'null' as expected by PostgreSQL.


37-39: Comprehensive DQL test scenarios

The DQL statements provide good coverage for NULL scenarios matching the expected SQL outputs. The use of uppercase 'NULL' in DQL follows SQL standard conventions, while the generated SQL correctly uses lowercase 'null'. These test cases align well with PostgreSQL's documentation for the array_replace function, which supports NULL values as both search and replacement parameters.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemove.php (1)

21-21: Great addition to support NULL value handling.

This change correctly enables NULL value support for the array_remove() function by using NewValue instead of ArithmeticPrimary for node mapping. This aligns with PostgreSQL's documentation which indicates that array_remove() should be able to handle NULL values as input arguments.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayRemoveTest.php (2)

25-25: Good test coverage for NULL value handling.

Appropriate test case added for verifying that array_remove() can handle NULL values. The expected SQL statement properly uses lowercase 'null' which matches PostgreSQL's syntax.


35-35: Consistent DQL test case.

The DQL statement test correctly uses the uppercase 'NULL' keyword which is consistent with DQL syntax standards. This test ensures that NULL values are properly handled in the DQL to SQL conversion process.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPrependTest.php (2)

25-25: Good test coverage for NULL value handling.

Appropriate test case added for verifying that array_prepend() can handle NULL values. The expected SQL statement properly uses lowercase 'null' which matches PostgreSQL's syntax.


35-35: Consistent DQL test case.

The DQL statement test correctly uses the uppercase 'NULL' keyword which is consistent with DQL syntax standards. This test ensures that NULL values are properly handled in the DQL to SQL conversion process.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayAppendTest.php (2)

25-25: Good test coverage for NULL value handling.

Appropriate test case added for verifying that array_append() can handle NULL values. The expected SQL statement properly uses lowercase 'null' which matches PostgreSQL's syntax.


35-35: Consistent DQL test case.

The DQL statement test correctly uses the uppercase 'NULL' keyword which is consistent with DQL syntax standards. This test ensures that NULL values are properly handled in the DQL to SQL conversion process.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbSetLaxTest.php (2)

22-29: Great improvement to test readability and coverage!

The restructured SQL statements with descriptive keys significantly enhance test clarity by explicitly indicating what each test case verifies. I particularly appreciate the explicit test case for NULL handling (line 23), which directly supports the PR objective of adding NULL value support.

The test cases comprehensively cover the PostgreSQL jsonb_set_lax function's capabilities, including property modifications at various nesting levels, array manipulation, parameterized queries, and different data types.


36-43: Consistent improvement in DQL test structure

The parallel restructuring of DQL statements maintains consistency between SQL and DQL tests, making the test suite more maintainable. The consistent naming between SQL and DQL test cases also makes it easier to understand the relationship between the two.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@martin-georgiev martin-georgiev merged commit 396856f into main Mar 30, 2025
46 of 49 checks passed
@martin-georgiev martin-georgiev deleted the null-value-support branch March 30, 2025 00:14
This was referenced Mar 30, 2025
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.

2 participants