【问题标题】:Cassandra Error : expected 8 or 0 byte long for dateCassandra 错误:预计日期为 8 或 0 字节长
【发布时间】:2019-11-01 07:38:58
【问题描述】:

我正在使用 Spring Data cassandra

我的这段代码正在运行

@Query("SELECT count(*) as cnt FROM notifications where userid = ?0 and typeofnotification=?1  "
            + "and notificationId > minTimeuuid('2019-09-12') and category = ?3 allow filtering")

    public Integer findCountForCategoryForDate(int userId, String typeOfNotification, String category);

但是当我尝试将日期作为参数时,它给出了错误

@Query("SELECT count(*) as cnt FROM notifications where userid = ?0 and typeofnotification=?1  "
            + "and notificationId > minTimeuuid(?2) and category = ?3 allow filtering")

public Integer findCountForCategoryForDate(int userId, String typeOfNotification,String date, String category);

我错过了什么?

notificationId 列是 DB 中的 timeuuid

【问题讨论】:

    标签: cassandra spring-data-cassandra


    【解决方案1】:

    mintimeuuid 函数需要时间戳作为参数,但您传递了一个字符串。您需要使用 java.util.Date 类型传递变量。请参阅documentation for mapping between Java type and CQL types

    【讨论】:

    • 谢谢,但已经用 Date 修复了它。但想知道为什么它甚至不能使用 java,util.LocalDate 而是使用 java.util.Date
    • 它可以工作,如果您可以添加相应的编解码器,如下所述:docs.datastax.com/en/developer/java-driver/3.7/manual/… - 但这是额外的包......在 Java 驱动程序 4.x 中,Instant 用于时间戳
    【解决方案2】:

    您可以使用 SimpleDateFormatter 然后创建日期实例并将该值分配给 TimeStamp 列。见mapping between Java type and CQL types

    享受:)

    【讨论】:

      猜你喜欢
      • 2014-08-29
      • 2017-11-30
      • 2019-09-22
      • 2019-05-06
      • 2014-12-28
      • 1970-01-01
      • 2020-09-30
      • 2021-04-22
      • 1970-01-01
      相关资源
      最近更新 更多