Skip to content

Fix N1QLExpression keys. #1115

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 7 commits into from
Mar 31, 2021
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 @@ -262,13 +262,14 @@ public N1QLExpression returning(N1QLExpression right) {
public N1QLExpression keys(Iterable<? extends Serializable> ids) {
StringBuilder sb = new StringBuilder();
Iterator<?> it = ids.iterator();
// TODO: really? Lets do better.
sb.append("[");
while (it.hasNext()) {
sb.append(i(it.next().toString()));
sb.append(s(it.next().toString()));
if (it.hasNext()) {
sb.append(",");
}
}
sb.append("]");
return infix("USE KEYS", toString(), sb.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import com.couchbase.client.java.json.JsonArray;

import java.util.Arrays;

/**
* @author Mauro Monti
*/
Expand Down Expand Up @@ -251,6 +253,15 @@ void testFalse() {
assertEquals("not( (`name`) )", c.export());
}

@Test
void testKeys() {
N1QLExpression expression = N1QLExpression.x("");
assertEquals(" USE KEYS [\"a\",\"b\"]", expression.keys(Arrays.asList("a", "b")).toString());
assertEquals(" USE KEYS [\"a\"]", expression.keys(Arrays.asList("a")).toString());
assertEquals(" USE KEYS []", expression.keys(Arrays.asList()).toString());
}


@Test // https://github.com/spring-projects/spring-data-couchbase/issues/1066
void testCriteriaCorrectlyEscapedWhenUsingMetaOnLHS() {
final String bucketName = "sample-bucket";
Expand Down