Skip to content

N1QLExpression#keys is broken #1064

@aaronjwhiteside

Description

@aaronjwhiteside

Backstory:
We use N1QLExpression to implement a custom base repository.

Issue:
If a collection of keys are passed in invalid n1ql is generated.

expression.keys(Arrays.asList("hello", "world"));

would generate

USE KEYS `hello`, `world` 

instead of the valid

USE KEYS ["hello", "world"]

Solution: (from our workaround)

    public N1QLExpression keys(Iterable<? extends Serializable> ids) {
        StringBuilder sb = new StringBuilder();
        Iterator<?> it = ids.iterator();
        int count = 0;
        while (it.hasNext()) {
            count++;
            sb.append(s(it.next().toString()));
            if (it.hasNext()) {
                sb.append(",");
            }
        }
        return infix("USE KEYS", toString(), count > 1 ? "[" + sb.toString() + "]" : sb.toString());
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions