.NET SDK N1QL Example - No results, no error, no idea

I have a VM running Ubuntu 14.04 LTS with DP4 of Couchbase 4 on it. I have manually started the couchbase query engine, like this:

/opt/couchbase/bin/cbq-engine -datastore=http://localhost:8091/pools

I can use the cbq tool and queries executed there work fine. However when I try to connect from the .NET SDK, things are not working.

Since I’m running the cbq engine from a remote shell (which I logged into via ssh) I can see that the client is not even hitting the query service (no log output on console).

A point of confusion to me is the way that the URI for the .Net sdk connection appears, at least from the samples, to be pointing only at the main port 8091 service, and not at the query service uri. Is there something I’m missing in my configuration so that the query service will resolve to a valid query service URI?

Code sample, based on Couchbase.N1QLExamples:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Couchbase.Core;
using Couchbase.Configuration.Client;

namespace Couchbase.N1QLExamples
{
    class Program
    {
       
        static void Main(string[] args)
        {
            ClientConfiguration _config = new ClientConfiguration();
            _config.Servers.Add(new Uri("http://192.168.1.122:8091/pools"));
            //_config.BucketConfigs.Add(...);
            var _cluster = new Cluster(_config);
            int count = 0;
            using (var bucket = _cluster.OpenBucket())
            {
                const string query = "SELECT count(*) AS COUNT FROM `beer-sample` ";
               // const string query = "SELECT * FROM default";
                Console.WriteLine(query);
                var result = bucket.Query<dynamic>(query);

                if (result.Metrics != null) 
                {
                     Console.WriteLine( "execution time: {0}", result.Metrics.ExecutionTime);
                }
               
                foreach (var row in result.Rows)
                {
                    Console.WriteLine(row);
                    count++; 
                }
                if (count == 0)
                {
                    Console.WriteLine("No rows found.");  // This just as probably means the query is invalid, as any other thing. Welcome to the wild world of NoSQL.
                }
                else
                {
                    Console.WriteLine("%d rows found", count);
                }
            }
            _cluster.Dispose();
            Console.Read();
        }
    }
}

I expected an error, and I get no error, just a silent zero row result.

If I remove the _config.Servers.Add(new Uri(“http://192.168.1.122:8091/pools”)) then the SDK also silently fails, presumably after trying to talk to the query service on localhost, and not finding one there. I do not much like the idea that configuring an invalid URI, or using a default URI, will just silently result in all queries returning zero results, and SUCCEEDING.

I get some useful error when I run using Python SDK, from same client PC. Operation Not Supported - Couldn’t schedule n1ql query.

One wishes that the various language SDKs had equivalent levels of error detection and error reporting.

# Python 3.4.3, with couchbase-2.0.1.win32-py3.4.exe

from couchbase import Couchbase
from couchbase.exceptions import CouchbaseError
from couchbase.bucket import Bucket
from couchbase.n1ql import N1QLQuery, N1QLError

#c = Couchbase.connect(bucket='beer-sample', host='localhost')
c = Bucket('couchbase://192.168.1.122/beer-sample')


def demo3():
    print('a');
    q =  N1QLQuery("select count(*) AS COUNT from `beer-sample`");
    print('b');
    for row in c.n1ql_query(q):
        pprint(row.raw)
# raises
#   couchbase.exceptions.NotSupportedError: <RC=0x13[Operation not supported],
#                   Couldn't schedule n1ql query, C Source=(src\n1ql.c,82demo3()

@wpostma

The .NET SDK doesn’t yet support CB 4.0 DP, however it will be there for CB 4.0 Beta: https://issues.couchbase.com/browse/NCBC-833

Note that port 8091 is the Administration REST API, the client must point to it bootstrap; you wouldn’t bootstrap to a query node. The point of NCBC-833 is to enable the client to pick up the query node information while bootstrapping - once it gets that information from the cluster map, then it will route N1QL queries to the correct node in the cluster.

We’ll likely publish a DP build for this feature of the .NET SDK in the next week or so.

-Jeff

1 Like