spring-projects / spring-projects/spring-data-couchbase

implement AnalyticsQuery

Open
#1,496 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
284
Forks
197
PR merge metrics
No merged PRs in 30d

Description

package org.springframework.data.couchbase.core.query;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.domain.Airport;
import org.springframework.data.couchbase.domain.Config;
import org.springframework.data.couchbase.util.Capabilities;
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.couchbase.util.JavaIntegrationTests;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;

import java.util.List;

@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
@SpringJUnitConfig(Config.class)
public class queryExample extends JavaIntegrationTests {
	@Autowired CouchbaseTemplate template;

	@Test
	public void queryTest() {
		N1QLExpression expression = N1QLExpression.x("SQL++ Query");
		N1QLQuery query = buildQuery(expression, QueryScanConsistency.REQUEST_PLUS);
		List<Airport> airports = template.findByQuery(Airport.class).matching(query).all();
		System.err.println("airports: "+airports);
	}

	public static N1QLQuery buildQuery(N1QLExpression expression, QueryScanConsistency scanConsistency) {
		QueryOptions opts = QueryOptions.queryOptions().scanConsistency(scanConsistency);
		return new N1QLQuery(expression, opts);
	}

	@Test
	public void analyticsTest() {
		N1QLExpression expression = N1QLExpression.x("SQL++ Query");
		AnalyticsQuery query = buildAnalytics(expression, QueryScanConsistency.REQUEST_PLUS);
		List<Airport> airports = template.findByQuery(Airport.class).matching(query).all();
		System.err.println("airports: "+airports);
	}

	private AnalyticsQuery buildAnalytics(N1QLExpression expression, QueryScanConsistency scanConsistency) {
		QueryOptions opts = QueryOptions.queryOptions().scanConsistency(scanConsistency);
		return new AnalyticsQuery(expression, opts);
	}

}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides an example using N1QLQuery and the requested AnalyticsQuery through CouchbaseTemplate.findByQuery(...).matching(...).all(). Compare the existing N1QLQuery path with the AnalyticsQuery usage, then verify completion by making analyticsTest compile and execute with the supplied QueryOptions and scan consistency.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.