Spring data N1Ql field is an array

Hey Guys,

I have a following simple data structure:

class Product {
private List <\String> categories;
}

Does Spring Data SDK support a field generated query against this sort of thing?

I saw that Java SDK supports the following:

SELECT * FROM bucket
UNNEST bucket.categories AS cat
WHERE bucket._class="package.Product"
AND
LOWER(cat) in [“light bulbs”]

Thanks !

hey @yev

Unfortunately no, support for arrays in query derivation isn’t in place and the framework cannot generate UNNEST type queries as of now.

But you can always provide custom method implementations (following the standard Spring Data procedures) or do an inline query (where you write most of the query statement as a String in the @Query() annotation).

Thanks @simonbasle

I got it working via @Query.

I was also trying the DSL, but wasn’t having much luck, any chance for a quick look/correction below?

   Statement statement = select("*")
            .from(i("bucket"))
            .unnest(x("bucket.categories").as(x("cat")))
            .where(x("bucket._class").eq(s("package.Product")))
            .and(x("cat").in(x("$categories"))))
            .limit(10);

    JsonObject placeholderValues = JsonObject.create().put("categories", category);
    N1qlQuery q = N1qlQuery.parameterized(statement, placeholderValues);
    for (N1qlQueryRow row : bucket.query(q)) {
        System.out.println(row);
    }

For the DSL, I think compared to your original request your missing the array brackets around the $category in the IN clause.

@simonbasle I assumed brackets were going to be generated, duh. Thank you !