Skip to content

Conversation

@martin-georgiev
Copy link
Owner

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

Summary by CodeRabbit

  • New Features

    • Expanded PostgreSQL aggregation support with the addition of XML_AGG alongside other aggregation functions.
  • Documentation

    • Updated and reorganized integration guides to clearly outline aggregation function configuration for multiple frameworks.
  • Tests

    • Introduced tests to validate the behavior of the new XML_AGG aggregation functionality.

@martin-georgiev martin-georgiev enabled auto-merge (squash) March 29, 2025 03:03
@coveralls
Copy link

Coverage Status

coverage: 93.202% (+0.1%) from 93.097%
when pulling 6a02ad2 on xmlagg
into 4cdc638 on main.

@coderabbitai
Copy link

coderabbitai bot commented Mar 29, 2025

Walkthrough

This pull request introduces a new PostgreSQL aggregation function, xmlagg, for use within the Doctrine ORM framework. The update includes documentation changes to list and detail the function, modifications to integration files for Doctrine, Laravel, and Symfony to reorganize and extend custom function mappings, and the addition of an implementation class with corresponding tests. These changes ensure that the new aggregation function is properly implemented, registered, and tested across various integration points.

Changes

File(s) Change Summary
docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md Added new entry for the xmlagg function registered as XML_AGG and implemented by MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\XmlAgg.
docs/INTEGRATING-WITH-DOCTRINE.md, docs/INTEGRATING-WITH-LARAVEL.md, docs/INTEGRATING-WITH-SYMFONY.md Updated the registration of custom aggregation functions. Reorganized function mappings by removing and re-adding functions (including ARRAY_AGG, STRING_AGG, JSON_*, and now XML_AGG) under a dedicated aggregation section.
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAgg.php Introduced the XmlAgg class implementing PostgreSQL’s XMLAGG() function with parsing and SQL generation logic.
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php Added a new test class for XmlAgg to validate SQL and DQL outputs across various use cases.

Sequence Diagram(s)

sequenceDiagram
    participant DQL
    participant DoctrineORM
    participant XML_AGG_Function
    participant Database

    DQL->>DoctrineORM: Submit query using XML_AGG
    DoctrineORM->>XML_AGG_Function: Parse XML_AGG function call
    XML_AGG_Function-->>DoctrineORM: Return SQL fragment for XMLAGG
    DoctrineORM->>Database: Execute query with generated SQL
Loading

Possibly related PRs

Poem

I’m just a rabbit in a digital field,
Hopping over code with a zeal that's real.
XML_AGG now joins our parade,
Bringing structured queries in a neat cascade.
With Doctrine, Laravel, and Symfony in sight,
I nibble on changes from morning till night!
🥕🐇

✨ 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAgg.php (1)

47-55: SQL generation handles ordering elegantly.
The combination of expression dispatching and optional ordering is well-structured. Consider adding additional safety checks if you anticipate expressions that might be empty or invalid, though Doctrine usually guards against that scenario.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php (1)

29-36: Consider adding advanced usage tests.
PostgreSQL XMLAGG can wrap XML elements or handle concatenated XML content. You might include tests involving multiple expressions or XML-specific syntax (e.g., xmlelement(name foo, e.text1)).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4cdc638 and 6a02ad2.

📒 Files selected for processing (6)
  • docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md (1 hunks)
  • docs/INTEGRATING-WITH-DOCTRINE.md (1 hunks)
  • docs/INTEGRATING-WITH-LARAVEL.md (1 hunks)
  • docs/INTEGRATING-WITH-SYMFONY.md (1 hunks)
  • src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAgg.php (1 hunks)
  • tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.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/XmlAggTest.php
🧠 Learnings (1)
docs/INTEGRATING-WITH-SYMFONY.md (1)
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#277
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonExistsTest.php:10-0
Timestamp: 2025-03-26T16:52:34.228Z
Learning: The implementation of JSON_EXISTS in this library supports only the basic form with two parameters (target_json, path_text) and doesn't support additional features like strict mode (third boolean parameter), ON ERROR clause, or other advanced PostgreSQL JSON_EXISTS capabilities due to DQL limitations.
🧬 Code Definitions (1)
tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAgg.php (1)
  • XmlAgg (22-56)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest
  • GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
  • GitHub Check: sloth
🔇 Additional comments (8)
docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md (1)

103-103: Documentation entry looks good.
This new row for xmlagg is consistent with the rest of the table and aligns with PostgreSQL function naming conventions.

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAgg.php (3)

14-21: DocBlock includes practical references.
Thank you for referencing the PostgreSQL 17 docs and highlighting usage details. This helps developers quickly understand the function’s purpose.


22-30: Sensible approach in defining the function prototype.
Your use of setFunctionPrototype('xmlagg(%s%s)') with node mapping for StringPrimary matches the typical pattern for handling user-provided expressions.


32-46: Parser logic is comprehensive.
Properly matching and parsing identifiers, parentheses, and the optional order-by clause ensures robust handling of the XML_AGG syntax.

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php (1)

19-27: Thorough coverage of basic and ordered usage.
You have done a commendable job covering both basic usage and ordering scenarios. This ensures core functionalities of XML_AGG are tested.

docs/INTEGRATING-WITH-DOCTRINE.md (1)

35-43: Aggregation Functions Registration Updated

The reorganization of the custom string functions under the "aggregation functions" section is clear and logically grouped. The new XML_AGG function is registered alongside the other aggregation functions, and its fully qualified class name appears correct. Please ensure that the corresponding documentation in AVAILABLE-FUNCTIONS-AND-OPERATORS.md is updated accordingly.

docs/INTEGRATING-WITH-SYMFONY.md (1)

169-177: Consistent Addition of XML_AGG in Symfony Config

The YAML configuration now clearly separates the aggregation functions into their own block. The new XML_AGG entry is correctly registered alongside ARRAY_AGG, JSON_AGG, and the others. This reorganization aligns well with the changes made in the Doctrine integration documentation.

docs/INTEGRATING-WITH-LARAVEL.md (1)

174-182: Laravel Integration: Aggregation Functions Reorganized

The custom string functions mapping in the Laravel configuration has been reorganized to include a dedicated "aggregation functions" section. The addition of the XML_AGG function is consistent with the changes in the Doctrine and Symfony integrations. Ensure that any related Laravel integration tests are updated to recognize and validate the new function mapping if applicable.

Comment on lines +1 to +9
<?php

declare(strict_types=1);

namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsTexts;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\XmlAgg;

Copy link

@coderabbitai coderabbitai bot Mar 29, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Missing TestCase import.
You extend TestCase but it's not explicitly imported here. Ensure you have the necessary import (e.g., use PHPUnit\Framework\TestCase;) or are otherwise inheriting correctly.


🏁 Script executed:

#!/bin/bash
# Verify that `TestCase` is properly imported or declared in this namespace
rg -A 2 $'class XmlAggTest' tests/

Length of output: 329


Attention: Missing TestCase Import

The file tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php extends TestCase, but it currently does not include an explicit import for it. To ensure clarity and avoid potential issues with autoloading, please add the following import at the top of the file (below the namespace declaration):

use PHPUnit\Framework\TestCase;
  • Location: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php
  • Action: Add the import statement for PHPUnit\Framework\TestCase.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Are you ignoring that all tests in this namespace rely on Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase?

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

@martin-georgiev You're absolutely right, and I apologize for the oversight! I see that tests in this namespace are extending the custom Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase class rather than PHPUnit's TestCase. Since the TestCase class is in the same namespace, no import statement is needed. Thank you for the correction.


🏁 Script executed:

#!/bin/bash
# Check if a custom TestCase class exists in the namespace
echo "Checking for a custom TestCase class in the tests directory:"
find tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ -name "TestCase.php"

echo -e "\nExamining how other test files in the same namespace extend TestCase:"
grep -r "class .* extends TestCase" tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ --include="*.php" | grep -v TestCase.php | head -n 3

Length of output: 968


@martin-georgiev You're absolutely right, and I apologize for the oversight! I see that the project has a custom `TestCase` class located at `tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php`, and all other test files in this namespace extend it without needing an import. Since this custom TestCase class is in the same namespace as the test class, no import statement is required. Thank you for the correction.
✏️ Learnings added
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:15.897Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase, and therefore don't need an explicit import.

Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:15.897Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), not PHPUnit's TestCase, and therefore don't need an explicit import statement.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Code Analysis Tools

Tool Analysis Results

CodeRabbit ran static analysis tools on your files and found the following:

No specific issues were found in your files. You can proceed with your changes.

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.

3 participants