2017-08-11 48 views
0

使用點燃C++ API,我試圖找到一種方法來執行一個SqlFieldsQuery來選擇一個特定的字段,但想要爲一組鍵。要做到這一點Ignite SqlFieldsQuery特定鍵

的方法之一,就是做這樣的SqlFieldsQuery,

SqlFieldsQuery("select field from Table where _key in (" + keys_string + ")") 

其中keys_string是關鍵作爲一個逗號分隔字符串列表。

不幸的是,與僅爲密鑰集合keys相比,這需要很長時間。

是否有另一種更快的方式從點火高速緩存獲取一組密鑰的特定字段?

編輯:

看完了答案,我試圖改變查詢:

auto query = SqlFieldsQuery("select field from Table t join table(_key bigint = ?) i on t._key = i._key") 

然後我從我的組鍵添加的參數是這樣的:

for(const auto& key: keys) query.AddArgument(key); 

但運行查詢時,出現錯誤:

Failed to bind parameter [idx=2, obj=159957, stmt=prep0: select field from Table t join table(_key bigint = ?) i on t._key = i._key {1: 159956}]

顯然,這不起作用,因爲只有一個'?'。

於是,我又試圖通過按鍵的vector<int64_t>,但我得到了這基本上說,std::vector<int64_t>沒有專門的點火BinaryType錯誤。所以我按照here的定義做了這個。當呼叫例如

writer.WriteInt64Array("data", data.data(), data.size()) 

我給這個字段指定了一個任意的名字「data」。然後,這將導致錯誤:

Failed to run map query remotely.

不幸的是,C++ API既不是有據可查的,也不是完整的,所以我不知道如果我失去了一些東西,或者該API不允許傳遞一個數組作爲參數SqlFieldsQuery

+0

你不能傳遞一個數組作爲C++中的參數呢。爲什麼你想使用查詢,如果你可以使用'GetAll()'? – isapego

+0

由於帶寬限制,我被告知查詢特定字段可能比獲取整個對象更快。 – Grieverheart

回答

1

運算符「IN」的查詢不總是使用索引。作爲一種變通方法,您可以通過以下方式重寫查詢:

select field from Table t join table(id bigint = ?) i on t.id = i.id 

,然後調用它像:

new SqlFieldsQuery(
     "select field from Table t join table(id bigint = ?) i on t.id = i.id") 
     .setArgs(new Object[]{ new Integer[] {2, 3, 4} }))