卡桑德拉 select 按 timeuuid
Cassandra select by timeuuid
Spring-boot-data-cassandra
CQL:
CREATE TABLE device_data (
device_id uuid,
time timeuuid,
unit text,
value double,
PRIMARY KEY (device_id, time)
)
存储库:
public interface DeviceDataRepository extends CassandraRepository<DeviceData> {
@Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, Date from);
}
用法:
Calendar calendar = new GregorianCalendar(1990, 1, 1);
List<DeviceData> pump1Data = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(pumpid), calendar.getTime());
这给了我以下错误:
Invalid INTEGER constant (633826800000) for "time" of type timeuuid; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Invalid INTEGER constant (633826800000) for "time" of type timeuuid
我做错了什么?
解决了问题:
@Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, UUID from);
设备数据:
...
private UUID time;
...
控制器:
List<DeviceData> pumpData = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(id), calendar.getTime());
Spring-boot-data-cassandra
CQL:
CREATE TABLE device_data (
device_id uuid,
time timeuuid,
unit text,
value double,
PRIMARY KEY (device_id, time)
)
存储库:
public interface DeviceDataRepository extends CassandraRepository<DeviceData> {
@Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, Date from);
}
用法:
Calendar calendar = new GregorianCalendar(1990, 1, 1);
List<DeviceData> pump1Data = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(pumpid), calendar.getTime());
这给了我以下错误:
Invalid INTEGER constant (633826800000) for "time" of type timeuuid; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Invalid INTEGER constant (633826800000) for "time" of type timeuuid
我做错了什么?
解决了问题:
@Query("SELECT * FROM device_data WHERE device_id = ?0 AND time > ?1")
List<DeviceData> findByDeviceIdAndTime(UUID deviceId, UUID from);
设备数据:
...
private UUID time;
...
控制器:
List<DeviceData> pumpData = deviceDataService.findByDeviceIdAndFrom(UUID.fromString(id), calendar.getTime());