Repository navigation
HCK-18354: escape index key names in the reverse-engineering WHERE clause - #75
Merged
Merged
Conversation
…ause Without a primary index, the plugin reads documents with a WHERE clause on the leading key of an index. The key name was not escaped, so a field name with a space (like "New field1") made the query fail with a syntax error, and the collection was skipped as empty. Key names are now wrapped in backticks, each part of a nested path separately. Indexes without a simple key (Array, Metadata, function only) are skipped instead of crashing. Co-authored-by: Cursor <cursoragent@cursor.com>
|
serhii-filonenko
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Jira: [HCK-18354](https://hackolade.atlassian.net/browse/HCK-18354)
Problem
Reverse-engineering a collection that has no primary index imports nothing when its first index is on a field whose name has a space (like
New field1). The log shows:It was found after applying an alter script that drops the primary index (HCK-18345).
Why
Without a primary index, Couchbase can't read all documents of a collection. So the plugin adds a WHERE clause on the leading key of an index, which lets Couchbase use that index. The key name was put in the query without backticks:
WHERE New field1 LIKE '%'. Couchbase requires backticks around any field name that is not a simple word, so the query failed. The plugin then got 0 documents and skipped the collection as empty.The same happens with other characters. A hyphen is common (
first-name) and is worse, because there is no error:first-nameis read as "first minus name", and the query silently returns nothing.Also, if the first index of the collection was an Array, Metadata or function-only index, it has no simple key and the code crashed the same way.
Fix
In
reverse_engineering/helpers/queryHelper.js:`New field1`,`address`.`zip code`.INFER, which was already the fallback for this case.Limit
A field whose name really contains a dot would be split by mistake. The plugin already loses this information when it reads the index keys (it removes the backticks). It's rare, and would be a separate ticket.
Tests
npm test: 157 passed. Newtest/reverse_engineering/queryHelper.test.js: space, hyphen, nested path, leading key, indexes without simple key, primary index, and an index read fromsystem:indexeswith the key`New field1`.