Skip to content

Fix #542: correct the couchbase-source statement example - #3009

Merged
oscerd merged 1 commit into
apache:mainfrom
oscerd:ci-issue-542-statement
Sep 7, 2026
Merged

Fix #542: correct the couchbase-source statement example#3009
oscerd merged 1 commit into
apache:mainfrom
oscerd:ci-issue-542-statement

Conversation

@oscerd

@oscerd oscerd commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Fixing a defect I introduced in #3007.

The statement example shipped there does not work:

        example: "SELECT * FROM `travel-sample` LIMIT 10"

and it fails in the worst possible way — the source polls happily, logs nothing alarming, and emits no exchanges at all.

Two requirements, neither obvious

Both found by running the Kamelet against a live Couchbase while writing the integration test in #3008.

1. The document id must be aliased as __id. CouchbaseConsumer does:

String id = row.getString(SQL_DOCUMENT_ID_ALIAS);   // "__id"
if (id == null) {
    LOG.warn("Row does not contain '{}' field. ... Skipping row.", ...);
    continue;
}

A query without META().id AS __id has every row skipped — at WARN level, so a route looks healthy and simply never fires.

2. The keyspace is the collection, not the bucket. The consumer runs the query through scope.query(...), so FROM <bucket> resolves to <bucket>._default.<bucket>:

Keyspace not found in CB datastore: default:mybucket._default.mybucket

The collection — normally _default — is what belongs there.

The change

-        description: The N1QL query to run against the bucket on each poll. Used unless useView is true.
+        description: >-
+          The N1QL query to run against the bucket on each poll. Used unless useView is true.
+          The query runs in the bucket scope, so the keyspace is the collection - use _default
+          for the default collection rather than the bucket name. It must also alias the document
+          id as __id, because rows without that field are skipped.
-        example: "SELECT * FROM `travel-sample` LIMIT 10"
+        example: "SELECT META().id AS __id, * FROM _default"

Description only — no template or behavioural change. The example now matches exactly what the integration test in #3008 uses and is proven to work against a real cluster.

Kept separate from #3008 deliberately: that PR adds a test, this one corrects a Kamelet, and they are reviewable independently even though the same investigation produced both.

script/validator reports no errors and mvn clean install passes with tests from the repository root.


Claude Code on behalf of Andrea Cosentino

The example shipped in apache#3007 -- SELECT * FROM `travel-sample` LIMIT 10 --
does not work, and fails in the worst way: the source polls happily and
emits nothing.

Two requirements, both found by running the Kamelet against a live cluster
while writing the integration test in apache#3008:

CouchbaseConsumer reads row.getString("__id") and skips any row without
that field, logging a warning rather than failing. A query that does not
alias the document id as __id therefore produces no exchanges at all.

The consumer runs the query through scope.query(...), so the keyspace
resolves as <bucket>._default.<what-you-wrote>. Naming the bucket gives
<bucket>._default.<bucket> and fails with "Keyspace not found"; the
collection, normally _default, is what belongs there.

The example now matches what the integration test actually uses, and the
description states both requirements so the next person does not have to
rediscover them from a silent no-op.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tz352mt7yzGWLfvYTBo2Dk
@oscerd
oscerd merged commit 2714beb into apache:main Sep 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant