Is there any Java API to use N1QL?

Hello,

I’m interesting in N1QL with Couchbase. I understand that one can use:

But is there any Java API to create requests in N1QL form and then get the results?

I’m surely missing something, since it looks like this could be as if you have defined SQL but not JDBC interface, except through Web interface or CLI interface.

How do you propose to integrate such N1QL language in an application?

Thanks,
Frederic

Hello Frederic,

We are working to provide JDBC and ODBC drivers for N1QL, as well as adding N1QL support in the Couchbase client SDKs, including Java. My colleague Michael will reply with a bit more about the Java client SDK.

Correct, we are working on integrated N1QL support for the next generation of the Java SDK, which should go into a first developer preview in the next weeks. Keep an eye on the blog for announcements!

And the 2.0 SDK developer preview is up and available. We’d love to get your feedback.

Has this been released?

The Java 2.0 SDK includes experimental support for N1QL now. It was released as GA recently.

I have been trying to use it with N1QL installed on a vagrant machine… as below, but I keep getting a “CompositeException: 1 exceptions occurred.” error.

All I’m doing is a simple SELECT from the documentation. A simple GET works.

bucket.query(select("*").from(“beer-sample”).limit(10))

Is there something I’m missing?

Details below:

Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at rx.exceptions.CompositeException.getCause(CompositeException.java:89) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at ch.qos.logback.classic.spi.ThrowableProxy.(ThrowableProxy.java:58) ~[logback-classic-1.1.1.jar:na]
at ch.qos.logback.classic.spi.ThrowableProxy.(ThrowableProxy.java:61) ~[logback-classic-1.1.1.jar:na]
at ch.qos.logback.classic.spi.LoggingEvent.(LoggingEvent.java:121) ~[logback-classic-1.1.1.jar:na]
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:440) [logback-classic-1.1.1.jar:na]
Caused by: com.couchbase.client.core.config.ConfigurationException: Could not open bucket.
at com.couchbase.client.core.config.DefaultConfigurationProvider$5.call(DefaultConfigurationProvider.java:261) ~[core-io-1.0.0.jar:1.0.0]
at com.couchbase.client.core.config.DefaultConfigurationProvider$5.call(DefaultConfigurationProvider.java:258) ~[core-io-1.0.0.jar:1.0.0]
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.onError(OperatorOnErrorResumeNextViaFunction.java:76) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorDoOnEach$1.onError(OperatorDoOnEach.java:70) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMap$1.onError(OperatorMap.java:48) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
Caused by: java.lang.IllegalStateException: Could not load bucket configuration: NOT_EXISTS(Requested resource not found.
)
at com.couchbase.client.core.config.loader.HttpLoader$1.call(HttpLoader.java:93) ~[core-io-1.0.0.jar:1.0.0]
at com.couchbase.client.core.config.loader.HttpLoader$1.call(HttpLoader.java:89) ~[core-io-1.0.0.jar:1.0.0]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMerge$InnerSubscriber.emit(OperatorMerge.java:617) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(OperatorMerge.java:528) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: BucketConfigResponse.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:98) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:56) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMerge$InnerSubscriber.emit(OperatorMerge.java:617) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(OperatorMerge.java:528) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]
at rx.internal.operators.OperatorSubscribeOn$1$1$1.onNext(OperatorSubscribeOn.java:76) ~[rxjava-1.0.0-rc.3.jar:1.0.0-rc.3]

Currently if you enable N1QL you need:

  • to run it on the same machine as the couchbase node
  • every node in the cluster needs to have N1QL running

in a separate vagrant box it won’t work - I guess that’s whats happening here?

I just had this same issue. I have separate machines for an application server (WAS) and for my Couchbase cluster.

Is this still an issue for current SDK versions?

I discovered this is failing when you try to instantiate a cluster passing more than one server. In my case, it stopped failing when I left just one node. I guess this is a bug.

No. The 2.2 SDK added first class support for N1QL, so as long as you’re pointing it at a cluster that has the query service, it’ll simply be available to you. We added experimental support for N1QL to the 2.1.x series, which was shipped as an unbundled service to Couchbase before 4.0. Then once 4.0 shipped, it was promoted to supported functionality as covered in the release notes.

Can you supply some more information about the version in use and what you were trying to do in a new topic? We definitely support multiple nodes and we test with this for every micro release.