spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
379 stars 311 forks source link

Take in account the @Indexed attributes when creating a table [DATACASS-377] #545

Closed spring-projects-issues closed 7 years ago

spring-projects-issues commented 7 years ago

Marc Pynaert opened DATACASS-377 and commented

I'm looking to enable the index creation on the table creation, but I can't get it to work. After looking at the documentation http://docs.spring.io/spring-data/cassandra/docs/1.5.0.RC1/reference/html/#mapping.usage-annotations, @Indexed doesn't appear in the list even though it's in org.springframework.data.cassandra.mapping package and its javadoc says:

Identifies a secondary index in the table on a single, non-key column.
The name of the index. If {@literal null} or empty, then the index name will be generated by Cassandra and will be
unknown unless column metadata is used to discover the generated index name.

Which could let think Spring Data Cassandra handles the index creation.

Here's my model:

@Table("my_object")
public class MyObject {

    @PrimaryKeyColumn(name = "e", type = PrimaryKeyType.PARTITIONED, ordinal = 1)
    @CassandraType(type = DataType.Name.TEXT)
    private MyEnum e;

    @PrimaryKeyColumn(name = "id", type = PrimaryKeyType.CLUSTERED, ordinal = 2)
    @CassandraType(type = DataType.Name.UUID)
    private UUID id;

    @Column("value")
    @Indexed("value_idx")
    private String value;

    // Getters & setters omitted
}

Here is the description of the table created:

CREATE TABLE test.my_object (
    e text,
    id uuid,
    value text,
    PRIMARY KEY (e, id)
) WITH CLUSTERING ORDER BY (id ASC)
...

I would have expected:

CREATE TABLE test.my_object (
    e text,
    id uuid,
    value text,
    PRIMARY KEY (e, id)
) WITH CLUSTERING ORDER BY (id ASC)
...
CREATE INDEX value_idx ON test.my_object (value);

Issue Links:

1 votes, 3 watchers

spring-projects-issues commented 7 years ago

Mark Paluch commented

Thanks for the ticket and the extensive description. There's no schema generation support for @Indexed yet, see DATACASS-213

spring-projects-issues commented 7 years ago

Mark Paluch commented

Will be implemented with DATACASS-213