Пример #1
0
        public async Task CreateDataverseAsync(string dataverseName, CreateAnalyticsDataverseOptions?options = null)
        {
            options ??= new CreateAnalyticsDataverseOptions();

            _logger.LogInformation("Attempting to create dataverse with name {dataverseName}",
                                   _redactor.MetaData(dataverseName));

            try
            {
                if (string.IsNullOrWhiteSpace(dataverseName))
                {
                    throw new InvalidArgumentException("dataverseName is a required parameter");
                }

                var ignoreStr = options.IgnoreIfExistsValue ? " IF NOT EXISTS" : string.Empty;
                var statement = $"CREATE DATAVERSE `{dataverseName}`{ignoreStr}";
                await _client
                .QueryAsync <dynamic>(statement, queryOptions => queryOptions.CancellationToken(options.TokenValue))
                .ConfigureAwait(false);
            }
            catch (DataverseExistsException)
            {
                _logger.LogError("Failed to create dataverse with name {dataverseName} because it already exists.",
                                 _redactor.MetaData(dataverseName));
                throw;
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to create dataverse with name {dataverseName}",
                                 _redactor.MetaData(dataverseName));
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Sends a request for a N1QL query to the server.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type" /> T of the body for each row (or document) result.</typeparam>
        /// <param name="queryRequest">A <see cref="IQueryRequest" /> object.</param>
        /// <param name="cancellationToken">Token which can cancel the query.</param>
        /// <returns></returns>
        async Task <IQueryResult <T> > IServer.SendAsync <T>(IQueryRequest queryRequest, CancellationToken cancellationToken)
        {
            IQueryResult <T> result;

            if (_isDown)
            {
                result = HandleNodeUnavailable <T>(queryRequest);
            }
            else
            {
                try
                {
                    queryRequest.BaseUri(CachedQueryBaseUri);
                    if (queryRequest.IsStreaming)
                    {
                        result = await _streamingQueryClient.QueryAsync <T>(queryRequest, cancellationToken).ContinueOnAnyContext();
                    }
                    else
                    {
                        result = await QueryClient.QueryAsync <T>(queryRequest, cancellationToken).ContinueOnAnyContext();
                    }
                }
                catch (Exception e)
                {
                    result = new QueryResult <T>
                    {
                        Exception = e,
                        Message   = e.Message,
                        Success   = false
                    };
                }
            }
            return(result);
        }
Пример #3
0
        public static Task <IQueryResult <T> > QueryAsync <T>(this IQueryClient client, string statement, Action <QueryOptions> configureOptions)
        {
            var options = new QueryOptions();

            configureOptions(options);

            return(client.QueryAsync <T>(statement, options));
        }
Пример #4
0
        public async Task BuildDeferredIndexesAsync(string bucketName, BuildDeferredQueryIndexOptions?options = null)
        {
            options ??= BuildDeferredQueryIndexOptions.Default;
            _logger.LogInformation("Attempting to build deferred query indexes on bucket {bucketName}",
                                   _redactor.MetaData(bucketName));
            try
            {
                var indexes = await this.GetAllIndexesAsync(bucketName,
                                                            queryOptions => queryOptions.CancellationToken(options.TokenValue)
                                                            ).ConfigureAwait(false);

                var tasks = new List <Task>();
                foreach (var index in indexes.Where(i => i.State == "pending" || i.State == "deferred"))
                {
                    var statement = $"BUILD INDEX ON {bucketName}({index.Name}) USING GSI;";
                    tasks.Add(_queryClient.QueryAsync <dynamic>(statement,
                                                                queryOptions => queryOptions.CancellationToken(options.TokenValue)
                                                                ));
                }

                await Task.WhenAll(tasks).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Error trying to build deferred query indexes on {bucketName}",
                                 _redactor.MetaData(bucketName));
                throw;
            }
        }
        public async Task BuildDeferredAsync(string bucketName, BuildDeferredQueryIndexOptions options)
        {
            Logger.LogInformation($"Attempting to build deferred query indexes on bucket {bucketName}");

            try
            {
                var indexes = await this.GetAllAsync(bucketName,
                                                     queryOptions => queryOptions.WithCancellationToken(options.CancellationToken)
                                                     );

                var tasks = new List <Task>();
                foreach (var index in indexes.Where(i => i.State == "pending" || i.State == "deferred"))
                {
                    var statement = $"BUILD INDEX ON {bucketName}({index.Name}) USING GSI;";
                    tasks.Add(_queryClient.QueryAsync <dynamic>(statement,
                                                                queryOptions => queryOptions.WithCancellationToken(options.CancellationToken)
                                                                ));
                }

                await Task.WhenAll(tasks);
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Error trying to build deferred query indexes on {bucketName}");
                throw;
            }
        }
Пример #6
0
        public Task <IQueryResult <T> > Query <T>(string statement, QueryParameter parameters = null, IQueryOptions options = null)
        {
            if (_queryClient == null)
            {
                _queryClient = new QueryClient(_configuration);
            }

            //re-use older API by mapping parameters to new API
            options?.AddNamedParameter(parameters?.NamedParameters.ToArray());
            options?.AddPositionalParameter(parameters?.PostionalParameters.ToArray());

            return(_queryClient.QueryAsync <T>(statement, options));
        }