DATACOUCH-276 - Don't escape the order by property as a whole.

Escape each nested level and concatenate with a period

Original pull request: #141.
This commit is contained in:
Subhashni Balakrishnan
2017-04-10 07:23:27 -07:00
committed by Oliver Gierke
parent 109a9f81d6
commit 30dfbbbdb4
2 changed files with 21 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors
* Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -149,7 +149,16 @@ public class N1qlUtils {
for (Sort.Order order : sort) {
String orderProperty = order.getProperty();
//FIXME the order property should be converted to its corresponding fieldName
Expression orderFieldName = i(orderProperty);
String[] orderPropertyParts = orderProperty.split("\\.");
StringBuilder sb = new StringBuilder();
for (String part:orderPropertyParts) {
if (sb.length() != 0) {
sb.append(".");
}
sb.append(i(part).toString());
}
Expression orderFieldName = x(sb.toString());
if (order.isIgnoreCase()) {
orderFieldName = lower(TypeFunctions.toString(orderFieldName));
}

View File

@@ -148,4 +148,14 @@ public class N1qlUtilsTest {
assertEquals(expected, real);
}
@Test
public void testOrderByWithNestedField() throws Exception {
CouchbaseConverter converter = mock(CouchbaseConverter.class);
com.couchbase.client.java.query.dsl.Sort[] realSort =
N1qlUtils.createSort(new Sort("party.attendees"), converter);
assertEquals("`party`.`attendees` ASC", realSort[0].toString());
verifyZeroInteractions(converter);
}
}