Skip to content

Commit

Permalink
Fixes default ASC value for ORDER BY clause (#689) (#342)
Browse files Browse the repository at this point in the history
* Fixes default ASC value for ORDER BY clause (#689)

* Updates CHANGELOG.md
  • Loading branch information
subigre authored Mar 25, 2022
1 parent c0c726e commit 012c658
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Note: version releases in the 0.x.y range may introduce breaking changes.
- Walker, Flat, DTO, Validation : enhance performance of path handling (
see https://github.com/ehrbase/openEHR_SDK/pull/325, https://github.com/ehrbase/openEHR_SDK/pull/332 )
- dto: Fix handling of element wich contains a choice with one an interval (see https://github.com/ehrbase/openEHR_SDK/pull/334)
- Fixes AqlParseException while using boolean in where clause ([#338](hhttps://github.com/ehrbase/openEHR_SDK/pull/338))

- Fixes AqlParseException while using boolean in where clause ([#338](https://github.com/ehrbase/openEHR_SDK/pull/338))
- Fixes default ASC value for ORDER BY clause ([#342](https://github.com/ehrbase/openEHR_SDK/pull/342))

## 1.17.0

Expand Down
2 changes: 1 addition & 1 deletion aql/src/main/antlr4/org/ehrbase/aql/parser/Aql.g4
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ orderBySeq
: orderByExpr (COMMA orderBySeq)?;
// | orderByExpr COMMA orderBySeq ;

orderByExpr : identifiedPath (DESCENDING|ASCENDING|DESC|ASC);
orderByExpr : identifiedPath (DESCENDING|ASCENDING|DESC|ASC)?;
// | identifiedPath DESCENDING
// | identifiedPath ASCENDING
// | identifiedPath DESC
Expand Down
70 changes: 46 additions & 24 deletions aql/src/test/java/org/ehrbase/aql/parser/AqlToDtoParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,28 @@

package org.ehrbase.aql.parser;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.ehrbase.aql.binder.AqlBinder;
import org.ehrbase.aql.dto.AqlDto;
import org.ehrbase.aql.dto.condition.*;
import org.ehrbase.aql.dto.condition.ConditionDto;
import org.ehrbase.aql.dto.condition.ConditionLogicalOperatorDto;
import org.ehrbase.aql.dto.condition.ConditionLogicalOperatorSymbol;
import org.ehrbase.aql.dto.condition.MatchesOperatorDto;
import org.ehrbase.aql.dto.condition.SimpleValue;
import org.ehrbase.aql.dto.containment.ContainmentDto;
import org.ehrbase.aql.dto.containment.ContainmentExpresionDto;
import org.ehrbase.aql.dto.containment.ContainmentLogicalOperator;
import org.ehrbase.aql.dto.select.SelectFieldDto;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AqlToDtoParserTest {

@Test
Expand Down Expand Up @@ -215,6 +217,20 @@ public void parseOrderBy() {
+ " order by o0/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude ASC, e/ehr_id/value DESC";

testAql(aqlShortenedSymbols, aqlTwoOrderBy);

var sortDefault1 =
"select e/ehr_id/value as ehr_id from EHR e contains OBSERVATION o0[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]"
+ " order by o0/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude, e/ehr_id/value";
testAql(sortDefault1,
"Select e/ehr_id/value as ehr_id from EHR e contains OBSERVATION o0[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]"
+ " order by o0/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude ASCENDING, e/ehr_id/value ASCENDING");

var sortDefault2 =
"select e/ehr_id/value as ehr_id from EHR e contains OBSERVATION o0[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]"
+ " order by o0/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude DESC, e/ehr_id/value";
testAql(sortDefault2,
"Select e/ehr_id/value as ehr_id from EHR e contains OBSERVATION o0[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]"
+ " order by o0/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value/magnitude DESCENDING, e/ehr_id/value ASCENDING");
}

public void testAql(String aql, String expected) {
Expand Down Expand Up @@ -301,14 +317,14 @@ private String render(ContainmentExpresionDto containmentExpresion) {
.append(
((ContainmentLogicalOperator) containmentExpresion)
.getValues().stream()
.map(this::render)
.collect(
Collectors.joining(
(StringUtils.wrap(
((ContainmentLogicalOperator) containmentExpresion)
.getSymbol()
.toString(),
" ")))))
.map(this::render)
.collect(
Collectors.joining(
(StringUtils.wrap(
((ContainmentLogicalOperator) containmentExpresion)
.getSymbol()
.toString(),
" ")))))
.append(")");
return sb.toString();
}
Expand Down Expand Up @@ -370,21 +386,27 @@ public void parseWhereClauseWithBoolean() {
String aql;

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = true";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = true");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = true");

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value is true";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = true");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = true");

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value is not true";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value != true");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value != true");

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = false";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = false");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = false");

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value is false";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = false");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value = false");

aql = "select e/ehr_id/value from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value is not false";
testAql(aql, "Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value != false");
testAql(aql,
"Select e/ehr_id/value as F1 from EHR e contains OBSERVATION o where o/data[at0001]/items[at0024]/items[at0025]/value/value != false");
}
}

0 comments on commit 012c658

Please sign in to comment.