Skip to content

Commit

Permalink
JAVA-2174: Metadata.needsQuote should accept empty strings (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekl007 authored and adutra committed Mar 1, 2019
1 parent 9e0bac6 commit 79d0e4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [improvement] JAVA-1950: Log server side warnings returned from a query.
- [improvement] JAVA-2123: Allow to use QueryBuilder for building queries against Materialized Views.
- [bug] JAVA-2082: Avoid race condition during cluster close and schema refresh.
- [bug] JAVA-2174: Metadata.needsQuote should accept empty strings.


### 3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,16 @@ public static String quoteIfNecessary(String id) {
/**
* We don't need to escape an identifier if it matches non-quoted CQL3 ids ([a-z][a-z0-9_]*), and
* if it's not a CQL reserved keyword.
*
* <p>When 'Migrating from compact storage' after DROP COMPACT STORAGE on the table, it can have a
* column with an empty name. (See JAVA-2174 for the reference) For that case, we need to escape
* empty column name.
*/
private static boolean needsQuote(String s) {
// this method should only be called for C*-provided identifiers,
// so we expect it to be non-null and non-empty.
assert s != null && !s.isEmpty();
// so we expect it to be non-null
assert s != null;
if (s.isEmpty()) return true;
char c = s.charAt(0);
if (!(c >= 97 && c <= 122)) // a-z
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public void escapeId_should_quote_reserved_cql_keywords() {
assertThat(Metadata.quoteIfNecessary("columnfamily")).isEqualTo("\"columnfamily\"");
}

/** @jira_ticket JAVA-2174 */
@Test(groups = "unit")
public void escapeId_should_quote_empty_keyword() {
assertThat(Metadata.quoteIfNecessary("")).isEqualTo("\"\"");
}

@Test(groups = "unit")
public void should_detect_reserved_keywords_in_upper_case() {
assertThat(Metadata.isReservedCqlKeyword("COLUMNFAMILY")).isTrue();
Expand Down

0 comments on commit 79d0e4c

Please sign in to comment.