8000 feat: add count(SelectQuery) support to Neo4J, Solr, Tinkerpop, OrientDB, and Oracle NoSQL by dearrudam · Pull Request #347 · eclipse-jnosql/jnosql-databases · GitHub 8000
[go: up one dir, main page]

Skip to content

Conversation

@dearrudam
Copy link
Contributor
@dearrudam dearrudam commented Dec 18, 2025

Summary

This PR implements count(SelectQuery) support across five database drivers (Neo4J, Solr, Tinkerpop, OrientDB, and Oracle NoSQL), enabling optimized counting with complex query criteria instead of fetching and counting results in memory.

Motivation

Currently, counting entities with complex query criteria requires fetching all results into memory and counting them, which is inefficient and resource-intensive. This PR introduces native count query support for each database, leveraging their built-in count capabilities for significantly better performance.

Implementation Details

Neo4J

  • Added count(SelectQuery) method to DefaultNeo4JDatabaseManager
  • Updated Neo4JQueryBuilder to generate optimized Cypher count queries
  • Utilizes Cypher's native COUNT() function for efficient counting
  • Added comprehensive unit tests for count query builder

Solr

  • Added count(SelectQuery) method to DefaultSolrDocumentManager
  • Refactored query construction with helper methods for improved code reuse
  • Leverages Solr's native count capabilities
  • Added comprehensive test coverage for SelectQuery count operations

Tinkerpop

  • Added count(SelectQuery) method to DefaultTinkerpopGraphDatabaseManager
  • Implements counting using Gremlin's native count step
  • Ensures efficient graph traversal for count operations
  • Enhanced test coverage for entity manager count operations

OrientDB

  • Added count(SelectQuery) method to DefaultOrientDBDocumentManager
  • Extended QueryOSQLConverter to generate OSQL count queries with proper condition handling
  • Enhanced QueryOSQLFactory to support count query generation
  • Improved URL handling in OrientDBDocumentManagerFactory for better connection management
  • Enhanced OrientDB container initialization for integration testing
  • Fixed alias handling in count queries
  • Updated README with database host configuration details
  • Significantly expanded test coverage with 225+ lines of new query converter tests

Oracle NoSQL

  • Enhanced AbstractQueryBuilder for better condition handling
  • Added SelectCountBuilder for dedicated count query support
  • Improved query builder condition handling and validation
  • Updated DefaultOracleNoSQLDocumentManager to support SelectQuery count operations
  • Fixed return types and condition handling in query builders

Test Coverage

  • Added 31 commits with comprehensive test coverage
  • 28 files changed: +817 additions, -192 deletions
  • Tests cover:
    • Basic count operations with and without conditions
    • Complex filtered queries with various operators
    • Null parameter validation and exception handling
    • Edge cases and error conditions
    • Integration tests with proper container setup
  • Enhanced OrientDB integration tests with improved configuration
  • Added unit tests for all new count query builders

Documentation

  • Updated CHANGELOG.adoc with count query features for all five database managers
  • Updated OrientDB README.adoc with host configuration details
  • Added inline documentation for new methods and query builders

Breaking Changes

None. This is a backward-compatible feature addition that extends existing functionality.

Performance Impact

This change significantly improves performance for count operations with query criteria by:

  • Eliminating unnecessary data transfer from database to application
  • Leveraging native database count optimizations (Cypher COUNT, AQL LENGTH, N1QL COUNT, etc.)
  • Reducing memory consumption by avoiding in-memory result sets
  • Using database-optimized query execution paths

Related Issues

Part of the count query optimization initiative to improve performance across all JNoSQL database drivers.


Note: This PR builds upon previous work that added count support to MongoDB, Cassandra, ArangoDB, and Couchbase, completing the count(SelectQuery) implementation across the major database drivers in the JNoSQL ecosystem.

Implemented a new method to build count queries for SelectQuery,
enhancing the query capabilities for counting entities in Neo4J.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented unit tests for building count queries
with and without conditions in Neo4JQueryBuilder,
ensuring correct Cypher query generation and parameter
binding for the SelectQuery interface.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a count method for executing count queries
on entities using the Neo4J database, enhancing query
capabilities and ensuring proper error handling.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a test to verify the count functionality
using SelectQuery, ensuring correct behavior and
handling of null queries.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented tests for counting entities by collection name
and by SelectQuery, ensuring correct behavior and exception
handling for null inputs.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a count method for SelectQuery to enhance
query capabilities and improve performance in counting
entities within the graph database.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a test to verify the count functionality
using SelectQuery, ensuring accurate counting of
entities in the graph database.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
…anagers

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Refactored Neo4JQueryBuilderTest to utilize the new
buildCountQuery method for generating count queries,
ensuring accurate query construction for counting entities.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented tests for counting documents using SelectQuery,
ensuring correct behavior for both valid and null inputs.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
…mentation

Implemented a new count method in DefaultSolrDocumentManager
to allow counting documents based on a SelectQuery, improving
query capabilities and performance.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Updated the Neo4J query builder to utilize count queries
and added a count method for SelectQuery in the Solr
Document Manager implementation to enhance query capabilities.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Modified the count query in Neo4JQueryBuilder to return
the count with an alias for better clarity in results.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
@otaviojava
Copy link
Contributor

Amazing @dearrudam as the previous one, don't forget tod o the backport on 1.1

Implemented a new method to generate count queries
for the SelectQuery, enhancing the query capabilities
of the QueryOSQLConverter.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a new method to convert SelectQuery to a count query,
enhancing the query capabilities for counting documents.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Refactored the URL handling logic to ensure proper formatting
of host URLs based on their type (embedded or remote),
enhancing the robustness of the OrientDB connection setup.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Added tests for creating document manager factories for both
remote and embedded databases, and included checks for
unsupported URL formats to ensure proper exception handling.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a count method that executes a count query
against the database, returning the total number of results
for a given SelectQuery. This enhances the querying capabilities
of the document manager.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Set up a GenericContainer for OrientDB to facilitate
testing with a local instance, improving the reliability
of database interactions during development.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Enhanced the test setup by adding necessary packages
and dependencies to improve integration testing for
the DefaultOrientDBTemplate.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a test to verify the count functionality
with a select query in the OrientDBDocumentManager,
ensuring accurate counting of inserted entities.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Refactored the integration test setup by adding necessary
packages and removing obsolete system property settings
to improve test reliability and maintainability.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Enhanced the integration test setup by adding necessary
packages for OrientDBTemplate and Converters, ensuring
better compatibility and functionality in tests.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Clarified the configuration property for `jnosql.orientdb.host`
to specify options for remote and embedded databases,
including a link to the OrientDB Javadoc for further details.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented count query functionality in QueryOSQLConverter
and QueryOSQLFactory, improved URL handling, and enhanced
tests for OrientDBDocumentConfiguration.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Changed the return value from 0l to 0L for clarity
and to adhere to Java conventions regarding long literals.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
@dearrudam dearrudam changed the title Optimize count queries Add count(SelectQuery) support to Neo4J, Solr, Tinkerpop, and OrientDB Dec 21, 2025
@dearrudam dearrudam marked this pull request as ready for review December 21, 2025 01:08
…tBuilder for OracleNoSQL count queries support

Updated the condition method to support a new parameter
indicating whether the query is for a count operation,
allowing for optimized handling of ID conditions.

Introduced SelectCountBuilder class to facilitate
building SQL count queries, enhancing query capabilities
for the Oracle database integration.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Modified the condition method calls in DeleteBuilder and SelectBuilder
to include an additional parameter for improved query handling.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Refactored assertions to use assertSoftly for better readability
and added a new test to verify count queries with specific
conditions in the OracleNoSQLDocumentManagerTest.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
Implemented a new count method that accepts a SelectQuery
object, allowing for more flexible counting of query results
in the DefaultOracleNoSQLDocumentManager.

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
…tBuilder for OracleNoSQL support

Signed-off-by: Maximillian Arruda <dearrudam@gmail.com>
@eclipse-jnosql eclipse-jnosql deleted a comment from Copilot AI Dec 21, 2025
@dearrudam dearrudam changed the title Add count(SelectQuery) support to Neo4J, Solr, Tinkerpop, and OrientDB feat: add count(SelectQuery) support across all database drivers Dec 21, 2025
@dearrudam dearrudam changed the title feat: add count(SelectQuery) support across all database drivers feat: add count(SelectQuery) support to Neo4J, Solr, Tinkerpop, OrientDB, and Oracle NoSQL Dec 21, 2025
@dearrudam dearrudam requested a review from otaviojava December 21, 2025 02:43
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

0