Skip to content
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

IndexMetadata.describe is not appending ; after "CREATE CUSTOM INDEX" #1917

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

pprazenica
Copy link

The method IndexMetadata.decribe can create two types of indexes:

  1. CUSTOM INDEX
    
  2. INDEX
    

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.

@pprazenica
Copy link
Author

Dear @ekaterinadimitrova2 , @hhughes , what is your view on this? Can we officially fix the describe method for custom indexes?

Copy link
Contributor

@SiyaoIsHiding SiyaoIsHiding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';");
  }
}

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.

2 participants