Fix ArrayIndexOutOfBoundsException on String queries that use paging. (#1197)

Closes #1155.

Co-authored-by: mikereiche <michael.reiche@couchbase.com>
This commit is contained in:
Michael Reiche
2021-08-23 13:06:57 -07:00
committed by GitHub
parent dffd203a57
commit f0880daf7a
6 changed files with 62 additions and 39 deletions

View File

@@ -114,18 +114,26 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
Long countFancyExpression(@Param("projectIds") List<String> projectIds, @Param("planIds") List<String> planIds,
@Param("active") Boolean active);
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE 0 = 1" )
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE anything = 'count(*)'") // looks like count query, but is not
Long countBad();
@Query("SELECT count(*) FROM `#{#n1ql.bucket}`" )
@Query("SELECT count(*) FROM `#{#n1ql.bucket}`")
Long countGood();
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Page<Airport> findAllByIataNot(String iata, Pageable pageable);
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata != $1")
Page<Airport> getAllByIataNot(String iata, Pageable pageable);
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Optional<Airport> findByIdAndIata(String id, String iata);
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE #{#n1ql.filter} " + " #{#projectIds != null ? 'AND blah IN $1' : ''} "
+ " #{#planIds != null ? 'AND blahblah IN $2' : ''} " + " #{#active != null ? 'AND false = $3' : ''} ")
Long countOne();
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
// @Meta

View File

@@ -39,7 +39,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import com.couchbase.client.java.kv.UpsertOptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -89,6 +88,7 @@ import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.java.json.JsonArray;
import com.couchbase.client.java.kv.GetResult;
import com.couchbase.client.java.kv.MutationState;
import com.couchbase.client.java.kv.UpsertOptions;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;
@@ -187,10 +187,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
assertEquals(person.getSalutation(), result.contentAsObject().get("prefix"));
Person person2 = personRepository.findById(person.getId().toString()).get();
assertEquals(person.getSalutation(), person2.getSalutation());
// needs fix from datacouch_1184
//List<Person> persons3 = personRepository.findBySalutation("Mrs");
//assertEquals(1, persons3.size());
//assertEquals(person.getSalutation(), persons3.get(0).getSalutation());
List<Person> persons3 = personRepository.findBySalutation("Mrs");
assertEquals(1, persons3.size());
assertEquals(person.getSalutation(), persons3.get(0).getSalutation());
} finally {
personRepository.deleteById(person.getId().toString());
}
@@ -442,6 +441,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
void count() {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
airportRepository.countOne();
try {
airportRepository.saveAll(
Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT)))
@@ -450,6 +450,11 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
Long count = airportRepository.countFancyExpression(asList("JFK"), asList("jfk"), false);
assertEquals(1, count);
Pageable sPageable = PageRequest.of(0, 2).withSort(Sort.by("iata"));
Page<Airport> sPage = airportRepository.getAllByIataNot("JFK", sPageable);
assertEquals(iatas.length - 1, sPage.getTotalElements());
assertEquals(sPageable.getPageSize(), sPage.getContent().size());
Pageable pageable = PageRequest.of(0, 2).withSort(Sort.by("iata"));
Page<Airport> aPage = airportRepository.findAllByIataNot("JFK", pageable);
assertEquals(iatas.length - 1, aPage.getTotalElements());
@@ -476,13 +481,13 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
}
}
@Test
void badCount(){
@Test
void badCount() {
assertThrows(CouchbaseQueryExecutionException.class, () -> airportRepository.countBad());
}
@Test
void goodCount(){
@Test
void goodCount() {
airportRepository.countGood();
}