Skip to content

Support COUNT(THIS) in string-based query execution #642

@otaviojava

Description

@otaviojava

Jakarta Query defines the following grammar rule for aggregate expressions:

aggregate_expression : 'COUNT' '(' 'THIS' ')';

This allows for string-based queries such as:

SELECT COUNT(THIS) FROM Word

Eclipse JNoSQL currently supports parsing and executing string-based queries via Jakarta Query integration. However, support for this aggregation expression is not yet implemented.

Goal

Enable SELECT COUNT(THIS) FROM Entity in string-based queries and ensure it is correctly interpreted and executed within Eclipse JNoSQL.

Technical Context

Eclipse JNoSQL already provides an internal mechanism to handle count-based queries through:

SelectQuery.isCount()

Reference:
SelectQuery.java#L86–L88

When the parser detects COUNT(THIS), it should toggle the SelectQuery's isCount flag accordingly.


💡 Usage Example

SELECT COUNT(THIS) FROM Word WHERE term = 'java'

This functionality must also be compatible with Jakarta Data repositories:

@Repository
public interface WordRepository {
    @Query("SELECT COUNT(THIS) FROM Word WHERE term = 'java'")
    Long countJava();
}

✅ Tasks

  • Update the Jakarta Query parser integration in Eclipse JNoSQL to recognize the COUNT(THIS) aggregate expression.
  • When COUNT(THIS) is parsed, set SelectQuery.count to true.
  • Ensure the communication layer processes queries with isCount = true correctly.
  • Add tests to validate COUNT(THIS) queries return correct results across supported databases.
  • Verify compatibility with Jakarta Data's @Query syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions