Skip to content

Feature/field to field comparison#134

Merged
brunomendola merged 25 commits intoqueritylib:mainfrom
vage88sg1:feature/field-to-field-comparison
Dec 15, 2025
Merged

Feature/field to field comparison#134
brunomendola merged 25 commits intoqueritylib:mainfrom
vage88sg1:feature/field-to-field-comparison

Conversation

@vage88sg1
Copy link
Contributor

No description provided.

Riccardo Vagelli and others added 25 commits December 5, 2025 20:05
- Add Select interface and SimpleSelect implementation
- Add NativeSelectWrapper for native select support
- Add hasSelect() and getSelect() to Query
- Add selectBy() method to QueryBuilder (renamed from select to avoid Jackson conflict)
- Add findAllProjected() method to Querity interface with default implementation
- Implement projection support in JPA module (JpaSelect, JpaSimpleSelect, JpaQueryFactory)
- Implement projection support in MongoDB module (MongodbSelect, MongodbSimpleSelect, MongodbQueryFactory)
- Implement projection support in Elasticsearch module (ElasticsearchSelect, ElasticsearchSimpleSelect, ElasticsearchQueryFactory)
- Add SELECT keyword to parser grammar
- Add SelectUtils for native select wrapper resolution
- Add tests for select in spring-web module

Note: Using SimpleSelect (concrete class) instead of Select (interface) in Query
to avoid Jackson deserialization issues with polymorphic types.
- Add SimpleSelectTest for API module
- Add JpaSelectTests for JPA module
- Add parser tests for SELECT keyword in QuerityParserTests
- Create SelectDeserializer following the same pattern as ConditionDeserializer
- Register SelectDeserializer in QuerityModule
- Change Query.select from SimpleSelect to Select interface
- Add getPropertyNames() method to Select interface
- Update JpaSelect, MongodbSelect, ElasticsearchSelect to accept Select interface
- Update QueryVisitor to use Select interface

This approach is more consistent with how Condition is handled and allows
for proper polymorphic deserialization of Select implementations.
- Create SortDeserializer following the same pattern as ConditionDeserializer and SelectDeserializer
- Register SortDeserializer in QuerityModule
- Remove @JsonTypeInfo/@JsonSubTypes annotations from Sort interface

Now all three interfaces (Condition, Select, Sort) use custom deserializers
registered in QuerityModule for consistent and predictable JSON parsing.
- Add NativeSelectWrapperTest for API module
- Add DeserializerTests for SelectDeserializer and SortDeserializer
- Add test for unsupported Select type in JpaSelectTests
- Coverage improvements:
  - querity-api: 98%
  - querity-spring-web: 99%
  - querity-jpa-common: 78%
- Add DateValueExtractorTests for Date value extraction
- Add SelectUtilsTests for NativeSelectWrapper handling
- Add SpecificationTests for JPA Specification.where()
- Add projection tests for Elasticsearch, MongoDB, and JPA
- Add additional parser tests for edge cases
- Fix DeserializerTests assertions for exception handling
- Extend JpaSelectTests with NativeSelectWrapper tests
- Configure JaCoCo to exclude ANTLR generated classes
- Add SelectTests to QuerityGenericTestSuite with tests for selectBy
- Add SelectionSpecification interface for native JPA selection expressions
- Add AliasedSelectionSpecification for selections with custom aliases
- Add JpaSelectionSpecificationSelectWrapper for native select support
- Add selectByNative tests with concat expression in JPA test classes
- Add sortByNative test with expression (cb.length) in JPA test classes
- Update README with documentation for projections and native expressions
- Update JpaSelect interface to include CriteriaBuilder parameter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Adds the ability to compare one field against another field in where conditions.
This enables queries like "startDate < endDate" or "firstName = lastName".

Features:
- New FieldReference class to represent field references in conditions
- Query language support with $ prefix syntax (e.g., startDate < $endDate)
- JSON API support with fieldRef property
- JPA implementation using CriteriaBuilder path comparisons
- MongoDB implementation using $expr with comparison operators
- Elasticsearch throws UnsupportedOperationException (not supported natively)

Supported operators for field-to-field comparison:
- EQUALS, NOT_EQUALS
- GREATER_THAN, GREATER_THAN_EQUALS
- LESSER_THAN, LESSER_THAN_EQUALS

Operators that don't support field references:
- STARTS_WITH, ENDS_WITH, CONTAINS
- IS_NULL, IS_NOT_NULL
- IN, NOT_IN

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
MongoDB $expr comparisons include null values because null is considered
"less than" any value. Added fieldToFieldComparisonIncludesNulls() method
to allow MongoDB tests to correctly filter expected results.

Also fixed Javadoc formatting in FieldReference to use {@code} tags.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documentation:
- Enhanced FieldReference Javadoc with supported/unsupported operators,
  backend support matrix, nested fields, query language syntax, JSON API
- Added SimpleCondition class-level Javadoc explaining field-to-field usage
- Improved Querity.field() and filterByField() method documentation

Tests:
- Added nested field comparison tests (address.city vs firstName)
- Added NOT condition with nested field reference test
- Tests verify both left-side and right-side nested field paths work

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- givenSelectByTwoFields: relax lastName assertion (null values may be
  excluded from projections in MongoDB/Elasticsearch)
- givenSelectByNestedField: accept both flat 'city' and nested
  'address.city' structures (Elasticsearch returns nested structure)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Relocate selectByNative tests from SpringPostgresqlQuerityJpaImplTests to QuerityJpaImplTests
- Tests validate SQL database behavior generally, not Postgres-specific edge cases
- Enhance givenSelectByTwoFields test with lastName IS_NOT_NULL filter
- Restore lastName containsKey assertion for more robust validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
# Conflicts:
#	querity-parser/src/test/java/io/github/queritylib/querity/parser/QuerityParserTests.java
#	querity-spring-web/src/test/java/io/github/queritylib/querity/spring/web/jackson/DeserializerTests.java
#	querity-test/src/main/java/io/github/queritylib/querity/test/QuerityGenericTestSuite.java
@brunomendola brunomendola merged commit e416a01 into queritylib:main Dec 15, 2025
1 of 2 checks passed
@vage88sg1 vage88sg1 deleted the feature/field-to-field-comparison branch December 18, 2025 09:32
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