Search in sources :

Example 1 with ReducedAnalyticsErrorContext

use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class ReactiveScope method analyticsQuery.

/**
 * Performs an Analytics query with custom {@link AnalyticsOptions} on a scope
 *
 * @param statement the Analytics query statement as a raw string.
 * @param options the custom options for this analytics query.
 * @return the {@link ReactiveAnalyticsResult} once the response arrives successfully.
 */
public Mono<ReactiveAnalyticsResult> analyticsQuery(final String statement, final AnalyticsOptions options) {
    notNull(options, "AnalyticsOptions", () -> new ReducedAnalyticsErrorContext(statement));
    AnalyticsOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment().jsonSerializer() : opts.serializer();
    return Mono.defer(() -> {
        return AnalyticsAccessor.analyticsQueryReactive(asyncScope.core(), asyncScope.analyticsRequest(statement, opts), serializer);
    });
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) AnalyticsOptions(com.couchbase.client.java.analytics.AnalyticsOptions)

Example 2 with ReducedAnalyticsErrorContext

use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class ReactiveCluster method analyticsQuery.

/**
 * Performs an Analytics query with custom {@link AnalyticsOptions}.
 *
 * @param statement the Analytics query statement as a raw string.
 * @param options the custom options for this analytics query.
 * @return the {@link ReactiveAnalyticsResult} once the response arrives successfully.
 */
public Mono<ReactiveAnalyticsResult> analyticsQuery(final String statement, final AnalyticsOptions options) {
    notNull(options, "AnalyticsOptions", () -> new ReducedAnalyticsErrorContext(statement));
    AnalyticsOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment().jsonSerializer() : opts.serializer();
    return Mono.defer(() -> {
        return AnalyticsAccessor.analyticsQueryReactive(asyncCluster.core(), asyncCluster.analyticsRequest(statement, opts), serializer);
    });
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) AnalyticsOptions(com.couchbase.client.java.analytics.AnalyticsOptions)

Example 3 with ReducedAnalyticsErrorContext

use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class AsyncScope method analyticsQuery.

/**
 * Performs an Analytics query with custom {@link AnalyticsOptions}.
 *
 * @param statement the Analytics query statement as a raw string.
 * @param options the custom options for this analytics query.
 * @return the {@link AnalyticsResult} once the response arrives successfully.
 */
public CompletableFuture<AnalyticsResult> analyticsQuery(final String statement, final AnalyticsOptions options) {
    notNull(options, "AnalyticsOptions", () -> new ReducedAnalyticsErrorContext(statement));
    AnalyticsOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment.jsonSerializer() : opts.serializer();
    return AnalyticsAccessor.analyticsQueryAsync(core, analyticsRequest(statement, opts), serializer);
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) AnalyticsOptions(com.couchbase.client.java.analytics.AnalyticsOptions)

Example 4 with ReducedAnalyticsErrorContext

use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class AsyncScope method analyticsRequest.

/**
 * Helper method to craft an analytics request.
 *
 * @param statement the statement to use.
 * @param opts the built analytics options.
 * @return the created analytics request.
 */
AnalyticsRequest analyticsRequest(final String statement, final AnalyticsOptions.Built opts) {
    notNullOrEmpty(statement, "Statement", () -> new ReducedAnalyticsErrorContext(statement));
    Duration timeout = opts.timeout().orElse(environment.timeoutConfig().analyticsTimeout());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    JsonObject query = JsonObject.create();
    query.put("statement", statement);
    query.put("timeout", encodeDurationToMs(timeout));
    query.put("query_context", AnalyticsRequest.queryContext(bucketName, scopeName));
    opts.injectParams(query);
    final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
    final String clientContextId = query.getString("client_context_id");
    final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ANALYTICS, opts.parentSpan().orElse(null));
    AnalyticsRequest request = new AnalyticsRequest(timeout, core.context(), retryStrategy, core.context().authenticator(), queryBytes, opts.priority(), opts.readonly(), clientContextId, statement, span, bucketName, scopeName);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) AnalyticsRequest(com.couchbase.client.core.msg.analytics.AnalyticsRequest) JsonObject(com.couchbase.client.java.json.JsonObject) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 5 with ReducedAnalyticsErrorContext

use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext in project couchbase-jvm-clients by couchbase.

the class AsyncCluster method analyticsQuery.

/**
 * Performs an Analytics query with custom {@link AnalyticsOptions}.
 *
 * @param statement the Analytics query statement as a raw string.
 * @param options the custom options for this analytics query.
 * @return the {@link AnalyticsResult} once the response arrives successfully.
 */
public CompletableFuture<AnalyticsResult> analyticsQuery(final String statement, final AnalyticsOptions options) {
    notNull(options, "AnalyticsOptions", () -> new ReducedAnalyticsErrorContext(statement));
    AnalyticsOptions.Built opts = options.build();
    JsonSerializer serializer = opts.serializer() == null ? environment.get().jsonSerializer() : opts.serializer();
    return AnalyticsAccessor.analyticsQueryAsync(core, analyticsRequest(statement, opts), serializer);
}
Also used : ReducedAnalyticsErrorContext(com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext) JsonSerializer(com.couchbase.client.java.codec.JsonSerializer) AnalyticsOptions(com.couchbase.client.java.analytics.AnalyticsOptions)

Aggregations

ReducedAnalyticsErrorContext (com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext)6 AnalyticsOptions (com.couchbase.client.java.analytics.AnalyticsOptions)4 JsonSerializer (com.couchbase.client.java.codec.JsonSerializer)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)2 AnalyticsRequest (com.couchbase.client.core.msg.analytics.AnalyticsRequest)2 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 Duration (java.time.Duration)2 ConnectionString (com.couchbase.client.core.util.ConnectionString)1 ConnectionStringUtil.asConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.asConnectionString)1 ConnectionStringUtil.checkConnectionString (com.couchbase.client.core.util.ConnectionStringUtil.checkConnectionString)1