why hazelcast can not query incorrect result with imap and hazelcastjsonvalue

北战南征 提交于 2021-01-29 07:34:00

问题


I use IMap store data in hazelcast, key is a string, value is a hazelcastjsonvalue. code example: `

    Gson gson = new Gson();
    String json = "{\"orderId\":\"-20200822-221116-188-quote-100002\",\"securityId\":\"130015\",\"tradingAccount\":\"xtrinterbanktra01\",\"subSystemId\":\"QDM-ESP\",\"userId\":\"xtrinterbankat01\",\"securityExchange\":\"B\",\"systemNodeId\":710,\"quoteId\":\"1598145974197\",\"execId\":\"22550774606679263\",\"investAccount\":\"xtrinterbankinvest01\",\"productAccount\":\"xtrinterbankprod01\",\"assetAccount\":\"xtrinterbankasst01\",\"securityAccount\":\"111010032010000205011\",\"securityType\":\"4\",\"settlType\":\"1\",\"orderModel\":\"legs\",\"orderStatus\":\"8\",\"createdTime\":1598145974,\"createdDate\":\"20200824\",\"tradeDate\":\"20200824\",\"positionFlag\":1,\"price\":111.0,\"orderQty\":1.0E7,\"accumulatedExecQty\":1.0E7,\"lastQty\":1.0E7,\"finalFlag\":true,\"symbol\":\"13国债15\",\"side\":\"1\",\"orderVersion\":2,\"classType\":\"OrderBO\",\"messageId\":87350933198472267,\"uniqueKey\":\"-20200822-221116-188-quote-100002\",\"topicName\":\"order\",\"subject\":\"business/order/130015/B/xtrinterbanktra01/xtrinterbankat01\",\"publisherId\":\"oms-710-9577@168-61-73-136\",\"tenantId\":\"ficc\",\"extFields\":{\"quotaionType\":\"5\",\"clOrdId\":\"-20200822-221116-188-quote-100001\",\"marketIndicator\":\"4\",\"deliveryType\":\"0\",\"transcatTime\":\"1883635200\",\"quoteStaus\":\"16\",\"clearingMethod\":\"13\",\"execType\":\"F\",\"validUnitTime\":\"1883635200\"}}";

    String tableName = "__UT_TestMap";

    IMap map = instance.getMap(tableName);
    map.addIndex(new IndexConfig(IndexType.HASH,"orderId"));

    map.put("-20200822-221116-188-quote-100002",json);

    System.out.println(map.entrySet(Predicates.sql("side='1'")));

` condition is correct,but result is null,why? when I not add index , the result of query is correct.


回答1:


In your map.put, try changing the value clause from json to new HazelcastJsonValue(json))

The variable you've named json is actually a String, so it's a map of form Map<String, String>.

Hazelcast won't search inside a String for a field, because it won't know that it contains any form of structured data. You'll get an IllegalOperationException for the code posted.

If you use new HazelcastJsonValue(json)) for the entry's value, that makes it structured, and you can search (and index) on fields.



来源:https://stackoverflow.com/questions/63574076/why-hazelcast-can-not-query-incorrect-result-with-imap-and-hazelcastjsonvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!