Skip to content

ArangoDB: between operator #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
6 changes: 6 additions & 0 deletions jnosql-arangodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@
<artifactId>arangodb-java-driver-shaded</artifactId>
<version>${arango.driver}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static AQLQueryResult convert(String documentCollection,
.append(", ").append(maxResult);
} else if (maxResult > 0) {
aql.append(LIMIT).append(maxResult);
} else if(firstResult > 0) {
} else if (firstResult > 0) {
aql.append(LIMIT).append(firstResult).append(", null");
}

Expand Down Expand Up @@ -180,6 +180,12 @@ private static void definesCondition(CriteriaCondition condition,
definesCondition(documentCondition, aql, params, entity, ++localCounter);
aql.append(END_EXPRESSION);
return;
case BETWEEN:
List<Object> betweenList = ValueUtil.convertToList(document.value(), ArangoDBValueWriteDecorator.ARANGO_DB_VALUE_WRITER);
appendCondition(aql, params, entity, Element.of(document.name(), betweenList.get(0)), GREATER_EQUALS_THAN);
aql.append(AND);
appendCondition(aql, params, entity, Element.of(document.name(), betweenList.get(1)), LESSER_EQUALS_THAN);
return;
default:
throw new IllegalArgumentException("The condition does not support in AQL: " + condition.condition());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,45 @@ void shouldInsertUUID() {

}

@Test
void shouldFindBetween() {
var deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
entityManager.insert(getEntitiesWithValues());

var query = select().from(COLLECTION_NAME)
.where("age").between(22, 23)
.build();

var result = entityManager.select(query).toList();

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(result).hasSize(2);
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).contains(22, 23);
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).doesNotContain(25);
});
}

@Test
void shouldFindBetween2() {
var deleteQuery = delete().from(COLLECTION_NAME).where("type").eq("V").build();
entityManager.delete(deleteQuery);
entityManager.insert(getEntitiesWithValues());

var query = select().from(COLLECTION_NAME)
.where("age").between(22, 23)
.and("type").eq("V")
.build();

var result = entityManager.select(query).toList();

SoftAssertions.assertSoftly(softly -> {
softly.assertThat(result).hasSize(2);
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).contains(22, 23);
softly.assertThat(result).map(e -> e.find("age").orElseThrow().get(Integer.class)).doesNotContain(25);
});
}

private CommunicationEntity getEntity() {
CommunicationEntity entity = CommunicationEntity.of(COLLECTION_NAME);
Map<String, Object> map = new HashMap<>();
Expand Down Expand Up @@ -373,4 +412,27 @@ private CommunicationEntity createDocumentList() {
return entity;
}

private List<CommunicationEntity> getEntitiesWithValues() {
var lucas = CommunicationEntity.of(COLLECTION_NAME);
lucas.add(Element.of("name", "Lucas"));
lucas.add(Element.of("age", 22));
lucas.add(Element.of("location", "BR"));
lucas.add(Element.of("type", "V"));

var luna = CommunicationEntity.of(COLLECTION_NAME);
luna.add(Element.of("name", "Luna"));
luna.add(Element.of("age", 23));
luna.add(Element.of("location", "US"));
luna.add(Element.of("type", "V"));

var otavio = CommunicationEntity.of(COLLECTION_NAME);
otavio.add(Element.of("name", "Otavio"));
otavio.add(Element.of("age", 25));
otavio.add(Element.of("location", "BR"));
otavio.add(Element.of("type", "V"));


return asList(lucas, otavio, luna);
}

}
12 changes: 12 additions & 0 deletions jnosql-arangodb/src/test/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS
org.slf4j.simpleLogger.showThreadName=true
org.slf4j.simpleLogger.showLogName=true
org.slf4j.simpleLogger.showShortLogName=false

org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.log.org.testcontainers=warn

## ArangoDB communication debug level
#org.slf4j.simpleLogger.log.com.arangodb.internal.net.Communication=debug
Loading