Skip to content

Counter table raw queries: Codec not found #1524

@soheilrahsaz

Description

@soheilrahsaz

Using Spring Boot 3.3.4, With a test Counter table:

@Table
public class ViewCount {
    @PrimaryKey
    private Integer id;
    @CassandraType(type = CassandraType.Name.COUNTER)
    private Integer count;
}
CREATE TABLE spring_cassandra.viewcount (
    id int PRIMARY KEY,
    count counter
) 

And this repository:

public interface ViewCountRepository extends CassandraRepository<ViewCount, Integer> {

    @Query("SELECT * FROM ViewCount WHERE count > :count ALLOW FILTERING")
    List<ViewCount> findViewCountGreaterThan(Integer count);

    @Query("UPDATE ViewCount SET count= count+ :count WHERE id= :id")
    void incrementViewCount(Integer id, Integer count);
}

Both of these tests will fail:

@SpringBootTest
class ViewCountRepositoryTest {

    @Autowired
    ViewCountRepository viewCountRepository;

    @Test
    void testIncrement() {
        viewCountRepository.incrementViewCount(5, 1);
    }

    @Test
    void testGetByCount() {
        viewCountRepository.findViewCountGreaterThan(2);
    }
}

With Exception:

Caused by: com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [COUNTER <-> java.lang.Integer]
at com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.createCodec(CachingCodecRegistry.java:667)
at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:97)
at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:94)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2276)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2154)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$Segment.get(LocalCache.java:2044)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache.get(LocalCache.java:3951)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache.getOrLoad(LocalCache.java:3973)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4957)
at com.datastax.oss.driver.shaded.guava.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4963)
at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry.getCachedCodec(DefaultCodecRegistry.java:119)
at com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.codecFor(CachingCodecRegistry.java:263)
at com.datastax.oss.driver.internal.core.data.ValuesHelper.encodePreparedValues(ValuesHelper.java:114)
at com.datastax.oss.driver.internal.core.cql.DefaultPreparedStatement.boundStatementBuilder(DefaultPreparedStatement.java:189)
at org.springframework.data.cassandra.core.PreparedStatementDelegate.bind(PreparedStatementDelegate.java:59)
at org.springframework.data.cassandra.core.CassandraTemplate$PreparedStatementHandler.bindValues(CassandraTemplate.java:1004)
at org.springframework.data.cassandra.core.cql.CqlTemplate.query(CqlTemplate.java:402)
... 21 more

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions