Exception in SDK Analytics

I have query that I test ed using Workbench UI Analytics tab and query worked successfully.
When I run the same query in SDK I get Exception:

   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Couchbase.Core.Buckets.RequestExecuterBase.RetryRequest[TRequest,TResult](Func`1 getServer, Func`3 sendRequest, Func`3 canRetry, TRequest request) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\Core\Buckets\RequestExecuterBase.cs:line 624
   at Couchbase.Core.Buckets.CouchbaseRequestExecuter.SendWithRetry[T](IAnalyticsRequest request) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\Core\Buckets\CouchbaseRequestExecuter.cs:line 1088

Query:
SELECT RAW (d1 + d2)
FROM
(SELECT
CASE WHEN distanceRunAsServer[0].distance IS NULL THEN 0
ELSE distanceRunAsServer[0].distance END as d1,
CASE WHEN distanceRunAsReciever[0].distance IS NULL THEN 0
ELSE distanceRunAsReciever[0].distance END as d2
FROM
(SELECT
(SELECT SUM(p.context.serverDistance.l) as distance
FROM CourtTracking p
WHERE p.context.tournament.tournYear = 2019
AND p.context.tournament.atpId = 7434
AND p.context.match.tourId = ‘MS010’
AND p.context.server.atpId = ‘BD06’

    				            AND p.`type`='hawkeye_point') 
    			            as distanceRunAsServer,

		            (SELECT SUM(p.context.receiverDistance.l) as distance
		            FROM CourtTracking p
		            WHERE p.context.tournament.tournYear = 2019
			            AND p.context.tournament.atpId = 7434 
			            AND p.context.match.tourId =  'MS010'
			            AND p.context.receiver.atpId = 'BD06'
			             
			            AND p.`type`='hawkeye_point') 
		            as distanceRunAsReciever)
	            AS subresults
	            ) as result;

What am I missing?

Can you post the entire Exception (including name) and Stacktrace? Can you also post the source code you are using to execute the query?

Exception:
{System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)
at Couchbase.Core.Buckets.RequestExecuterBase.RetryRequest[TRequest,TResult](Func1 getServer, Func3 sendRequest, Func`3 canRetry, TRequest request) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\Core\Buckets\RequestExecuterBase.cs:line 624
at Couchbase.Core.Buckets.CouchbaseRequestExecuter.SendWithRetry[T](IAnalyticsRequest request) in C:\Users\jmorris\repos\couchbase-net-client\Src\Couchbase\Core\Buckets\CouchbaseRequestExecuter.cs:line 1088}

CacheCouchbase.cs (class that has all couchbase sdk code e.g. GetDocumentAsync, UpsertAsync, etc.) :

public List<T> Query<T>(IAnalyticsRequest analyticsRequest, string bucketName)
        {
            var bucket = ClusterHelper.GetBucket(this.GetDefaultOrNamedBucket(bucketName));
            var result = bucket.Query<T>(analyticsRequest);

            return result?.Rows;
        }

StatsController.cs (controller that calls CacheCouchbase.cs to execute couchbase commands):

public ExpandoObject CalculateStat(string playerId, int setNum, short eventYear,
            short eventId, string matchId)
        {

            var queryRaw = @"
           SELECT RAW (d1 + d2)
                FROM
	            (SELECT 
		            CASE WHEN distanceRunAsServer[0].distance IS NULL THEN 0
		            ELSE distanceRunAsServer[0].distance END as d1,
		            CASE WHEN distanceRunAsReciever[0].distance IS NULL THEN 0
		            ELSE distanceRunAsReciever[0].distance END as d2
	            FROM
		            (SELECT  
			            (SELECT SUM(p.context.serverDistance.l) as distance
			            FROM CourtTracking p
			            WHERE p.context.tournament.tournYear = 2019
				            AND p.context.tournament.atpId = 7434 
				            AND p.context.match.tourId = 'MS010'
				            AND p.context.server.atpId = 'BD06'
				            
				            AND p.`type`='point') 
			            as distanceRunAsServer,

		            (SELECT SUM(p.context.receiverDistance.l) as distance
		            FROM CourtTracking p
		            WHERE p.context.tournament.tournYear = 2019
			            AND p.context.tournament.atpId = 7434 
			            AND p.context.match.tourId =  'MS010'
			            AND p.context.receiver.atpId = 'BD06'
			             
			            AND p.`type`='point') 
		            as distanceRunAsReciever)
	            AS subresults
	            ) as result;";

            var analiticsRequest = new AnalyticsRequest(queryRaw);
            var result = _couchbaseCacheProvider.Query<List<double>>(analiticsRequest, _bucketName);

            // will be substituded with results of query once figure out why query doesn`t work
            return new ExpandoObject();

When I run the same query in Analytics tab of workbench I get result that looks like this:
[
35.526
]

couchbase_exception_2

Issue got resolved when I changed return type of the query to be nulluble:

var result = _couchbaseCacheProvider.Query<List<double?>>(analiticsRequest, _bucketName);

1 Like