Adhoc query with USE KEYS clause

Hello,

I have a query that I am attempting to use the adhoc flag with the following query:


      val statement =
        s"""
           |SELECT meta().id as topic, array_count(m.subscribers) as subscriberCount
           |FROM $CURRENT_BUCKET_IDENTIFIER m
           |USE KEYS ${"$1"}""".stripMargin

      N1qlQuery.parameterized(statement, JsonArray.from(JsonArray.from(List("1","2","3").asJava)), n1qlParams.maxParallelism(4).adhoc(false))

However I am getting the following error:

Caused by: com.couchbase.client.core.CouchbaseException: N1qlQuery Error - {"msg":"Unable to add name: duplicate name: df627095ff69bbb205fa1a69575eb6483059e0ac","code":4060}
	at com.couchbase.client.java.query.core.N1qlQueryExecutor$11$4.call(N1qlQueryExecutor.java:513)
	at com.couchbase.client.java.query.core.N1qlQueryExecutor$11$4.call(N1qlQueryExecutor.java:508)
	at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
	at rx.internal.operators.NotificationLite.accept(NotificationLite.java:135)
	at rx.internal.operators.OperatorOnBackpressureBuffer$BufferSubscriber.accept(OperatorOnBackpressureBuffer.java:156)
	at rx.internal.util.BackpressureDrainManager.drain(BackpressureDrainManager.java:198)
	at rx.internal.operators.OperatorOnBackpressureBuffer$BufferSubscriber.onNext(OperatorOnBackpressureBuffer.java:151)
	at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
	at rx.internal.operators.NotificationLite.accept(NotificationLite.java:135)
	... 41 common frames omitted

Is it not possible to use the adhoc with the USE KEYS clause? Things work fine when I set adhoc to true.

Thanks,

K

Prepare statements can have USE KEYS . i.e adhoc=true|false should work with USE KEYS. cc @marcog

4060 means that the statement already exists, so the PREPARE statement that the SDK is silently preparing can’t be inserted in the cache.
@daschl could it be that when preparing across all nodes the SDK tries to prepare on the same node twice?

Hello @Marco_Greco @daschl,

Any updates on this?

Thanks,

K