jnosql icon indicating copy to clipboard operation
jnosql copied to clipboard

Support COUNT(THIS) in string-based query execution

Open otaviojava opened this issue 3 months ago • 0 comments

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.

otaviojava avatar Sep 15 '25 18:09 otaviojava