use of com.couchbase.client.java.analytics.AnalyticsResult in project couchbase-jvm-clients by couchbase.
the class AnalyticsCollectionIntegrationTest method performsDataverseCollectionQuery.
@Test
void performsDataverseCollectionQuery() {
cluster.analyticsQuery("ALTER COLLECTION `" + bucket.name() + "`.`" + scopeName + "`.`" + collectionName + "` ENABLE ANALYTICS");
// REQUEST_PLUS makes query hang
// AnalyticsOptions opts = AnalyticsOptions.analyticsOptions().scanConsistency(AnalyticsScanConsistency.REQUEST_PLUS);
// Ensure doc ingested by analytics
waitUntilCondition(() -> singletonMap(delimitedDataverseName, singletonMap(collectionName, 0L)).equals(analytics.getPendingMutations()));
Scope scope = cluster.bucket(config().bucketname()).scope(scopeName);
AnalyticsResult result = scope.analyticsQuery("SELECT * FROM `" + bucket.name() + "`.`" + scopeName + "`.`" + collectionName + "` WHERE `" + collectionName + "`.foo=\"bar\"");
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertFalse(rows.isEmpty());
}
use of com.couchbase.client.java.analytics.AnalyticsResult in project couchbase-jvm-clients by couchbase.
the class AnalyticsCollectionIntegrationTest method performsDataverseQuery.
@Test
void performsDataverseQuery() {
// default
analytics.createDataset(dataset, bucket.name());
analytics.createDataverse(dataverse);
analytics.createDataset(dataset, bucket.name(), createDatasetAnalyticsOptions().dataverseName(dataverse));
// REQUEST_PLUS makes query hang
// AnalyticsOptions opts = AnalyticsOptions.analyticsOptions().scanConsistency(AnalyticsScanConsistency.REQUEST_PLUS).timeout(Duration.ofSeconds(300));
AnalyticsResult result = cluster.analyticsQuery("SELECT * FROM " + dataverse + "." + dataset + " where " + dataset + ".test= \"hello\"");
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertFalse(!rows.isEmpty());
AnalyticsMetaData meta = result.metaData();
assertFalse(meta.clientContextId().isEmpty());
assertTrue(meta.signature().isPresent());
assertFalse(meta.requestId().isEmpty());
assertEquals(AnalyticsStatus.SUCCESS, meta.status());
assertFalse(meta.metrics().elapsedTime().isZero());
assertFalse(meta.metrics().executionTime().isZero());
assertEquals(rows.size(), meta.metrics().resultCount());
// assertEquals(rows.size(), meta.metrics().processedObjects()); // fails
// assertTrue(meta.metrics().resultSize() > 0); // fails
assertTrue(meta.warnings().isEmpty());
// assertEquals(1, meta.metrics().errorCount()); //fails
}
use of com.couchbase.client.java.analytics.AnalyticsResult in project couchbase-jvm-clients by couchbase.
the class AnalyticsIntegrationTest method canSetCustomContextId.
@Test
void canSetCustomContextId() {
String contextId = "mycontextid";
AnalyticsResult result = cluster.analyticsQuery("SELECT DataverseName FROM Metadata.`Dataverse`", analyticsOptions().clientContextId(contextId));
assertEquals(result.metaData().clientContextId(), contextId);
}
use of com.couchbase.client.java.analytics.AnalyticsResult in project couchbase-jvm-clients by couchbase.
the class AnalyticsIntegrationTest method performsDataverseQuery.
@Test
void performsDataverseQuery() {
AnalyticsResult result = cluster.analyticsQuery("SELECT DataverseName FROM Metadata.`Dataverse`");
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertFalse(rows.isEmpty());
for (JsonObject row : rows) {
assertNotNull(row.get("DataverseName"));
}
AnalyticsMetaData meta = result.metaData();
assertFalse(meta.clientContextId().isEmpty());
assertTrue(meta.signature().isPresent());
assertFalse(meta.requestId().isEmpty());
assertEquals(AnalyticsStatus.SUCCESS, meta.status());
assertFalse(meta.metrics().elapsedTime().isZero());
assertFalse(meta.metrics().executionTime().isZero());
assertEquals(rows.size(), meta.metrics().resultCount());
assertEquals(rows.size(), meta.metrics().processedObjects());
assertTrue(meta.metrics().resultSize() > 0);
assertTrue(meta.warnings().isEmpty());
assertEquals(0, meta.metrics().errorCount());
}
use of com.couchbase.client.java.analytics.AnalyticsResult in project connectors-se by Talend.
the class CouchbaseInput method init.
@PostConstruct
public void init() {
Cluster cluster = service.openConnection(configuration.getDataSet().getDatastore());
Bucket bucket = cluster.bucket(configuration.getDataSet().getBucket());
collection = service.openDefaultCollection(cluster, configuration.getDataSet().getBucket());
if (configuration.isCreatePrimaryIndex()) {
cluster.queryIndexes().createPrimaryIndex(bucket.name(), CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
}
columnsSet = new HashSet<>();
if (configuration.getSelectAction() == SelectAction.ANALYTICS) {
AnalyticsResult analyticsResult = null;
try {
analyticsResult = cluster.analyticsQuery(configuration.getQuery());
} catch (CouchbaseException e) {
LOG.error(i18n.queryResultError(e.getMessage()));
throw new ComponentException(i18n.queryResultError(e.getMessage()));
}
queryResultsIterator = analyticsResult.rowsAsObject().iterator();
} else {
// DSL API (Statement, AsPath classes etc. was deprecated, cannot use it anymore!)
// In most cases, a simple string statement is the best replacement.
QueryResult n1qlResult;
StringBuilder statementBuilder;
switch(configuration.getSelectAction()) {
case ALL:
statementBuilder = new StringBuilder();
statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
if (!configuration.getLimit().isEmpty()) {
statementBuilder.append(" LIMIT ").append(configuration.getLimit().trim());
}
n1qlResult = cluster.query(statementBuilder.toString());
break;
case N1QL:
/*
* should contain "meta().id as `_meta_id_`" field for non-json (binary) documents
*/
n1qlResult = cluster.query(configuration.getQuery());
break;
case ONE:
statementBuilder = new StringBuilder();
statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
statementBuilder.append(" USE KEYS \"").append(configuration.getDocumentId()).append("\"");
n1qlResult = cluster.query(statementBuilder.toString());
break;
default:
throw new ComponentException("Select action: '" + configuration.getSelectAction() + "' is unsupported");
}
queryResultsIterator = n1qlResult.rowsAsObject().iterator();
}
}
Aggregations