IndexMetadata.describe is not appending ; after "CREATE CUSTOM INDEX"#1917
Open
pprazenica wants to merge 1 commit intoapache:4.xfrom
Open
IndexMetadata.describe is not appending ; after "CREATE CUSTOM INDEX"#1917pprazenica wants to merge 1 commit intoapache:4.xfrom
pprazenica wants to merge 1 commit intoapache:4.xfrom
Conversation
Author
|
Dear @ekaterinadimitrova2 , @hhughes , what is your view on this? Can we officially fix the describe method for custom indexes? |
SiyaoIsHiding
suggested changes
May 7, 2024
Contributor
SiyaoIsHiding
left a comment
There was a problem hiding this comment.
Thank you for your contribution. Your changes look good to me. Would you change the corresponding test, please?
public class IndexMetadataTest {
@Test
public void should_describe_custom_index_class_correctly() {
IndexMetadata indexMetadata =
new DefaultIndexMetadata(
CqlIdentifier.fromCql("ks1"),
CqlIdentifier.fromCql("myTable"),
CqlIdentifier.fromCql("myName"),
IndexKind.CUSTOM,
"myTarget",
ImmutableMap.of("class_name", "com.datastax.MyClass"));
String describe = indexMetadata.describe(true);
assertThat(describe).isEqualTo(
"CREATE CUSTOM INDEX myname ON ks1.mytable (myTarget)\n"
+ "USING 'com.datastax.MyClass';");
}
}
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.
The method IndexMetadata.decribe can create two types of indexes:
When the code produces a CQL statement for the first type (custom), there is no semicolon at the end of the statement. i.e. The method produces a CQL statement as
CREATE CUSTOM INDEX mykeyspace_mytable_idx ON mykeyspace.mytable (lucene)
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds' : '1',
'schema' : '{
default_analyzer: "english",
fields: {
"template_code": {
type: "uuid"
},
"status": {
type : "string"
}
}
}'}
instead of
CREATE CUSTOM INDEX mykeyspace_mytable_idx ON mykeyspace.mytable (lucene)
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds' : '1',
'schema' : '{
default_analyzer: "english",
fields: {
"template_code": {
type: "uuid"
},
"status": {
type : "string"
}
}
}'};
The second type (a non custom index) is NOT affected by this as it contains
builder … .append(String.format(" (%s);", getTarget()));
at the end of the “else” section. The first type ends with the builder.decreaseIndent().append("}"); We should add builder.append(“;”); statement either at the end of the if section or before return builder.build(); and remove the semicolon from .append(String.format(" (%s);", getTarget()));
All other Describable classes (AggregateMetadata, FunctionMetadata, KeyspaceMetadata, UserDefinedType, DseGraphTableMetadata, DefaultDseViewMetadata) are NOT suffering from this defect.