Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ functionsReturningBoolean

orderByClause: ORDER BY orderByItem (',' orderByItem)* ;

orderByItem: singleValuedObjectPathExpression (ASC | DESC)? ;
orderByItem: (singleValuedObjectPathExpression | simpleSubpath) (ASC | DESC)? ;

groupByClause: GROUP BY groupByItem (',' groupByItem)* ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void setAttribute(SoqlAttribute attribute) {
}

public String getOrderByPart(String rootVariable) {
if (getAsParam(rootVariable).equals(rootVariable)) {
// Ordering by the entity identifier
return SoqlConstants.ASC.equals(orderingBy) ? rootVariable + " " : orderingBy + "(" + rootVariable + ") ";
}
String param = attribute.requiresFilter() ? getAsParam(rootVariable).substring(1) : attribute.getValue().substring(1);
return orderingBy + "(?" + param + ") ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ private SoqlNode linkObjectPathExpression(ParserRuleContext ctx) {
}
setIris(firstNode);
if (currentNode.getIri().isEmpty()) {
currentNode.getParent().clearChildren();
if (currentNode.getParent() != null) {
currentNode.getParent().clearChildren();
}
this.isInObjectIdentifierExpression = true;
}
return firstNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,24 @@ void parseQueryHandlesVariableCorrespondingToEntityIdentifier() {
" . ?personUri " + strUri(Vocabulary.p_p_username) + " ?username . }";
parseAndAssertEquality(expectedSparql, soql);
}

/**
* Bug #439
*/
@Test
void parseQuerySupportsOrderingByEntityIdentifier() {
final String soql = "SELECT p FROM Person p ORDER BY p.uri";
final String expectedSparql = "SELECT ?x WHERE { ?x a " + strUri(Vocabulary.c_Person) + " . } ORDER BY ?x";
parseAndAssertEquality(expectedSparql, soql);
}

/**
* Bug #439 - alternative syntax
*/
@Test
void parseQuerySupportsOrderingByEntity() {
final String soql = "SELECT p FROM Person p ORDER BY p";
final String expectedSparql = "SELECT ?x WHERE { ?x a " + strUri(Vocabulary.c_Person) + " . } ORDER BY ?x";
parseAndAssertEquality(expectedSparql, soql);
}
}
Loading