更新时间:2023-11-14 12:41:10
在编写测试时,我实际上发现了您的问题:-)
While writing a test I actually found your problem :-)
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.query.EntryObject;
import com.hazelcast.query.PredicateBuilder;
import java.io.Serializable;
import java.sql.Date;
public class Test
{
public static void main(String[] args)
{
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<MyObject, MyEnum> map = hz.getMap("test");
EntryObject entryObject = new PredicateBuilder().getEntryObject();
PredicateBuilder builder = entryObject.key().get("date").isNull();
map.addIndex("__key#date", true);
map.put(new MyObject(), MyEnum.TEST_ENUM);
}
public static class MyObject implements Serializable
{
private Date date;
public Date getDate()
{
return date;
}
public void setDate(Date date)
{
this.date = date;
}
}
public static enum MyEnum {
TEST_ENUM;
}
}
诀窍是基于map键而不是默认值创建索引.您已经在查询entryObject.key()
中进行了此操作,但是在索引定义__key.date
中未进行此操作.
The trick is to create the index based on the map-key and not the value which is taken by default. You already did it in your query entryObject.key()
but missed it on the index definition __key.date
.