Spring Data Cassandra,允许过滤

q5iwbnjs  于 2021-06-13  发布在  Cassandra
关注(0)|答案(1)|浏览(340)

我有下表

CREATE TABLE magazines.magazine_name (
    frequency smallint,
    magazine_id varchar,
    magazine_name varchar,
    PRIMARY KEY (magazine_id,magazine_name)
);

我应该使用allow filter annotation来执行以下存储库方法吗

@Query("SELECT * from magazine_name where magazine_id = ?0")
MagazineName findMagazineCQlQuery(String id);

因为我得到了以下选项:

org.springframework.data.cassandra.CassandraInvalidQueryException:Query; 
CQL[com.datastax.oss.driver.internal.core.cql.DefaultSimpleStatement@c78c2039]; 
Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. 
If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING; 

nested exception is 
 com.datastax.oss.driver.api.core.servererrors.InvalidQueryException:
Cannot execute this query as it might involve data filtering 
and thus may have unpredictable performance. 
If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

顺便说一句,我知道我可以使用查询方法,甚至findbyid方法,但实际上我只是在试验cql要求并尝试了解它。
--更新域对象

@Table(value = "magazine_name")
@Data
@Builder
public class MagazineName {

    @PrimaryKeyColumn(name = "magazine_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String magazineId;
    @PrimaryKeyColumn(name = "magazine_name", ordinal = 1, type = PrimaryKeyType.CLUSTERED)
    private String name;
}
gudnpqoy

gudnpqoy1#

我定义的表和你的完全一样,这是我的存储库。我可以无误地查询。
1我的存储库

public interface IMagazineDao extends CrudRepository<Magazine, String> {

    @Query("SELECT * from magazine_name where magazine_id = ?0")
    Magazine findMagazineCQlQuery(String id);

}

2应用

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    private IMagazineDao magazineDao;

    @Override
    public void run(String... args) throws Exception {
        this.magazineDao.save(new Magazine("magazine1", "name", (short) 1));
        this.magazineDao.findMagazineCQlQuery("magazine1");
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

三。杂志班

@Table(value = "magazine_name")
public class Magazine {

    @PrimaryKeyColumn(name = "magazine_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String magazineId;

    @PrimaryKeyColumn(name = "magazine_name", ordinal = 1, type = PrimaryKeyType.CLUSTERED)
    private String name;

    @Column
    private Short frequency;

    public Magazine() {

    }
    public Magazine(String magazineId, String name, Short frequency) {
        this.magazineId = magazineId;
        this.name = name;
        this.frequency = frequency;
    }

    public String getMagazineId() {
        return magazineId;
    }

    public void setMagazineId(String magazineId) {
        this.magazineId = magazineId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Short getFrequency() {
        return frequency;
    }

    public void setFrequency(Short frequency) {
        this.frequency = frequency;
    }
}

相关问题