-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix listIndexes bug with double quoted columnName in the index target from indexMetadata #1772
Conversation
src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/CQLSAIIndex.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/CQLSAIIndex.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/CQLSAIIndex.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok this looks quite complicated despite small size of diffs.
I am not super happy with the way things are handled but it may be necessary to fix the issue so that's ok.
But what really would be needed would be a test to show that fix works, if at all possible. And will guard against regression (avoid bug from reappearing due to changes)
…oted-problem # Conflicts: # src/main/java/io/stargate/sgv2/jsonapi/service/schema/tables/ApiIndexType.java # src/test/java/io/stargate/sgv2/jsonapi/api/v1/tables/CreateTableIndexIntegrationTest.java
I would not have merged this, it is a very good candidate to write a unit test , so I have re-opened the ticket #1770 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 on this merging, it makes some assumptions about things in the CQL target value that are risks, removes some validation checks , and adds a new enum rather than use the existing ApiIndexFunction
*/ | ||
private static Pattern INDEX_TARGET_PATTERN = Pattern.compile("^(\\w+)?(?:\\((\\w+)\\))?$"); | ||
private static final Pattern TARGET_REGEX = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is copied from the CQL class, we should add the name of the CQL class
functionName = matcher.group(1); | ||
} else { | ||
columnName = target; | ||
cqlIndexType = CqlIndexType.VALUES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this, why is the default Values ?
What about what this is an index on a text field ?
columnName = TWO_QUOTES.matcher(columnName).replaceAll(QUOTE); | ||
} | ||
|
||
return new IndexTarget(CqlIdentifier.fromInternal(columnName), cqlIndexType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this stop using existing ApiIndexFunction ?
switch (this) { | ||
case KEYS: | ||
return "keys"; | ||
case KEYS_AND_VALUES: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this called KEY_AND_VALUES when it is the entries ?
|
||
public static CqlIndexType fromString(String s) { | ||
if ("".equals(s)) return SIMPLE; | ||
else if ("values".equals(s)) return VALUES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a case sensitive match and duplicates the logic in toString
else if ("entries".equals(s)) return KEYS_AND_VALUES; | ||
else if ("full".equals(s)) return FULL; | ||
|
||
throw new AssertionError("Unrecognized index target type " + s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be IllegalArgument we have not used AssertionError anywhere in the code
@@ -268,13 +268,6 @@ protected ApiIndexDef create( | |||
.formatted(ApiIndexType.VECTOR, apiIndexType)); | |||
} | |||
|
|||
// also, we must not have an index function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check removed ?
if (indexTarget.indexFunction() == null && apiColumnDef.type().isPrimitive()) { | ||
// If cqlIndexType is values, and the column is a scalar | ||
// then it is a regular index on primitive types | ||
if (indexTarget.cqlIndexType() == CQLSAIIndex.CqlIndexType.VALUES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels risky - we are inferring the VALUES function when it is not defined in the CQL for the index and then using that inferred value. The previous code did not infer a function when there was none defined.
@@ -186,13 +186,6 @@ protected ApiIndexDef create( | |||
.formatted(ApiIndexType.REGULAR, apiIndexType)); | |||
} | |||
|
|||
// also, we should not have an index function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this check removed, there is no function for a regular index
What this PR does:
Summary, we got something like this, columnName is doubleQuoted in index target.
Reproduction:
Table
Index
(unknown-returning) List indexes
Which issue(s) this PR fixes:
Fixes #1770
Checklist