Added doc notes on the filter clause and the ilike predicate

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2021-08-04 22:00:48 +02:00 committed by Jan Schatteman
parent 89d16bddc8
commit 3ec8b27b2a
4 changed files with 59 additions and 15 deletions

View File

@ -1148,6 +1148,8 @@ The supported aggregate functions are:
For floating point values (other than `BigDecimal`) the result type is `Double`. For floating point values (other than `BigDecimal`) the result type is `Double`.
For `BigInteger` values, the result type is `BigInteger`. For `BigDecimal` values, the result type is `BigDecimal`. For `BigInteger` values, the result type is `BigInteger`. For `BigDecimal` values, the result type is `BigDecimal`.
Aggregations often appear with grouping. For information on grouping see <<hql-group-by>>.
[[hql-aggregate-functions-example]] [[hql-aggregate-functions-example]]
.Aggregate function examples .Aggregate function examples
==== ====
@ -1157,7 +1159,16 @@ include::{sourcedir}/HQLTest.java[tags=hql-aggregate-functions-example]
---- ----
==== ====
Aggregations often appear with grouping. For information on grouping see <<hql-group-by>>. All of these aggregate functions also support the inclusion of a specific *filter clause*
[[hql-aggregate-functions-filter-example]]
.Filter clause example
====
[source, JAVA, indent=0]
----
include::{sourcedir}/HQLTest.java[tags=hql-aggregate-functions-filter-example]
----
====
[[hql-exp-functions]] [[hql-exp-functions]]
=== Scalar functions === Scalar functions
@ -1780,6 +1791,20 @@ include::{sourcedir}/HQLTest.java[tags=hql-like-predicate-escape-example]
---- ----
==== ====
[[hql-ilike-predicate]]
=== Ilike predicate
Performs a case-insensitive like comparison on string values. The syntax is:
[[hql-ilike-predicate-bnf]]
[source, JAVA, indent=0]
----
include::{extrasdir}/predicate_ilike_bnf.txt[]
----
The semantics are identical to those of the aforementioned <<hql-like-predicate>>, with the sole difference that the comparison is now case insensitive.
[[hql-between-predicate]] [[hql-between-predicate]]
=== Between predicate === Between predicate

View File

@ -0,0 +1,4 @@
ilike_expression ::=
string_expression
[NOT] ILIKE pattern_value
[ESCAPE escape_character]

View File

@ -1178,6 +1178,22 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
}); });
} }
@Test
public void test_hql_aggregate_functions_filter_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::hql-aggregate-functions-filter-example[]
List<Object[]> callCount = entityManager.createQuery(
"select p.number, count(c) filter(where c.duration < 30) " +
"from Call c " +
"join c.phone p " +
"group by p.number", Object[].class )
.getResultList();
//end::hql-aggregate-functions-filter-example[]
assertNotNull(callCount.get( 0 ));
});
}
@Test @Test
@SkipForDialect(value = DerbyDialect.class, comment = "See https://issues.apache.org/jira/browse/DERBY-2072") @SkipForDialect(value = DerbyDialect.class, comment = "See https://issues.apache.org/jira/browse/DERBY-2072")
public void test_hql_concat_function_example() { public void test_hql_concat_function_example() {

View File

@ -400,20 +400,20 @@ whereClause
predicate predicate
//highest to lowest precedence //highest to lowest precedence
: LEFT_PAREN predicate RIGHT_PAREN # GroupedPredicate : LEFT_PAREN predicate RIGHT_PAREN # GroupedPredicate
| expression IS (NOT)? NULL # IsNullPredicate | expression IS (NOT)? NULL # IsNullPredicate
| expression IS (NOT)? EMPTY # IsEmptyPredicate | expression IS (NOT)? EMPTY # IsEmptyPredicate
| expression (NOT)? IN inList # InPredicate | expression (NOT)? IN inList # InPredicate
| expression (NOT)? BETWEEN expression AND expression # BetweenPredicate | expression (NOT)? BETWEEN expression AND expression # BetweenPredicate
| expression (NOT)? (LIKE | ILIKE) expression (likeEscape)? # LikePredicate | expression (NOT)? (LIKE | ILIKE) expression (likeEscape)? # LikePredicate
| expression comparisonOperator expression # ComparisonPredicate | expression comparisonOperator expression # ComparisonPredicate
| EXISTS (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # ExistsCollectionPartPredicate | EXISTS (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # ExistsCollectionPartPredicate
| EXISTSexpression # ExistsPredicate | EXISTS expression # ExistsPredicate
| expression (NOT)? MEMBER OF path # MemberOfPredicate | expression (NOT)? MEMBER OF path # MemberOfPredicate
| NOT predicate # NegatedPredicate | NOT predicate # NegatedPredicate
| predicate AND predicate # AndPredicate | predicate AND predicate # AndPredicate
| predicate OR predicate # OrPredicate | predicate OR predicate # OrPredicate
| expression # BooleanExpressionPredicate | expression # BooleanExpressionPredicate
; ;
comparisonOperator comparisonOperator
@ -1060,4 +1060,3 @@ identifier
logUseOfReservedWordAsIdentifier( getCurrentToken() ); logUseOfReservedWordAsIdentifier( getCurrentToken() );
} }
; ;