Uploaded image for project: 'Spring Data for Apache Cassandra'
  1. Spring Data for Apache Cassandra
  2. DATACASS-340

Cannot clustered columns cannot be ordering in desc

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.4 (Evans SR4), 1.5 M1 (Ingalls)
    • Fix Version/s: 1.5 RC1 (Ingalls)
    • Component/s: Core
    • Labels:
      None
    • Virtual Machine:
      IBM JVM - 1.6
    • Platform:
      Standalone
    • Last commented by a User:
      true
    • Sprint:
      Kay M1

      Description

      I define my entity with @Table with multiple @PrimaryKeyColumn annotations.

      @Table(value="customer2")
      public class Customer {
      
          @PrimaryKeyColumn(ordinal = 1, type=PrimaryKeyType.PARTITIONED)
      	private UUID id;
      
      	@Column
      	@Indexed
      	private String firstName;
      
      	@Column
      	@Indexed
      	private String lastName;
      	
      	@PrimaryKeyColumn(ordinal = 2, ordering=Ordering.DESCENDING)
      	private String data;
      
      	public Customer() {
      	}
      
      	public Customer(UUID id, String firstName, String lastName) {
      		this.id = id;
      		this.firstName = firstName;
      		this.lastName = lastName;
      	}
      }

      And I get the following table generated

      CREATE TABLE toscana.customer2 (
      id timeuuid,
      data text,
      firstname text,
      lastname text,
      PRIMARY KEY (id, data)
      ) WITH CLUSTERING ORDER BY (data ASC)

      Where data is expected to be in desc order.
      In

      BasicCassandraMappingContext.java
      @Override
      	public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {
      
      		Assert.notNull(entity);
      
      		final CreateTableSpecification spec = createTable().name(entity.getTableName());
      
      		entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
      
      			@Override
      			public void doWithPersistentProperty(CassandraPersistentProperty property) {
      
      				if (property.isCompositePrimaryKey()) {
      
      					CassandraPersistentEntity<?> pkEntity = getPersistentEntity(property.getRawType());
      
      					pkEntity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
      
      						@Override
      						public void doWithPersistentProperty(CassandraPersistentProperty pkProp) {
      
      							if (pkProp.isPartitionKeyColumn()) {
      								spec.partitionKeyColumn(pkProp.getColumnName(), getDataType(pkProp));
      							} else { // it's a cluster column
      								spec.clusteredKeyColumn(pkProp.getColumnName(), getDataType(pkProp), pkProp.getPrimaryKeyOrdering());
      							}
      						}
      					});
      
      				} else {
      					if (property.isIdProperty() || property.isPartitionKeyColumn()) {
      						spec.partitionKeyColumn(property.getColumnName(), getDataType(property));
      					} else if (property.isClusterKeyColumn()) {
      						spec.clusteredKeyColumn(property.getColumnName(), getDataType(property));
      					} else {
      						spec.column(property.getColumnName(), getDataType(property));
      					}
      				}
      			}
      
      		});
      
      		if (spec.getPartitionKeyColumns().isEmpty()) {
      			throw new MappingException("no partition key columns found in the entity " + entity.getType());
      		}
      
      		return spec;
      	} 

      It looks like we didn't set the ordering for clusterKeyColumn as we do with composite primary key.

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            yuxiaof XIAO FENG YU
            Last updater:
            Oliver Drotbohm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 50 weeks, 3 days ago