Skip to content

Commit dac577d

Browse files
committed
IGNITE-29199 Fix local IndexQuery returning binary objects for a cache not in keep-binary mode
1 parent 15380a5 commit dac577d

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ public GridCloseableIterator indexQueryLocal(final CacheQuery qry) throws Ignite
11601160
private int cnt;
11611161

11621162
@Override protected Object onNext() throws IgniteCheckedException {
1163-
IgniteBiTuple<K, V> entry = iter.nextX();
1163+
IgniteBiTuple<K, V> entry = (IgniteBiTuple<K, V>)cctx.unwrapBinaryIfNeeded(iter.nextX(), qry.keepBinary(), false, null);
11641164
cnt++;
11651165

11661166
return new CacheEntryImpl<>(entry.getKey(), entry.getValue());

‎modules/indexing/src/test/java/org/apache/ignite/cache/query/IndexQueryLocalTest.java‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
package org.apache.ignite.cache.query;
1919

20+
import java.util.List;
2021
import java.util.Objects;
22+
import javax.cache.Cache;
2123
import org.apache.ignite.Ignite;
2224
import org.apache.ignite.IgniteCache;
2325
import org.apache.ignite.IgniteDataStreamer;
2426
import org.apache.ignite.IgniteException;
27+
import org.apache.ignite.binary.BinaryObject;
2528
import org.apache.ignite.cache.CacheMode;
2629
import org.apache.ignite.cache.query.annotations.QuerySqlField;
2730
import org.apache.ignite.configuration.CacheConfiguration;
@@ -99,6 +102,44 @@ public void testServerNodePartitionedCache() {
99102
assertEquals(CNT / 2, resultSize);
100103
}
101104

105+
/** Should return deserialized values for a cache that is not in keep-binary mode. */
106+
@Test
107+
public void testLocalQueryReturnsDeserializedValues() {
108+
IgniteCache<Long, Person> cache = crd.createCache(ccfg(CacheMode.REPLICATED));
109+
110+
insertData(crd, cache);
111+
112+
IndexQuery<Long, Person> qry = new IndexQuery<Long, Person>(Person.class, IDX)
113+
.setCriteria(lt("id", CNT / 2));
114+
115+
List<Cache.Entry<Long, Person>> res = cache.query(qry.setLocal(true)).getAll();
116+
117+
for (Cache.Entry<Long, Person> e : res)
118+
assertEquals(new Person(e.getKey().intValue()), e.getValue());
119+
120+
assertEquals(CNT / 2, res.size());
121+
}
122+
123+
/** Should keep binary values for a cache in keep-binary mode. */
124+
@Test
125+
public void testLocalQueryKeepBinaryReturnsBinaryValues() {
126+
IgniteCache<Long, Person> cache = crd.createCache(ccfg(CacheMode.REPLICATED));
127+
128+
insertData(crd, cache);
129+
130+
IgniteCache<Long, BinaryObject> binCache = cache.withKeepBinary();
131+
132+
IndexQuery<Long, BinaryObject> qry = new IndexQuery<Long, BinaryObject>(Person.class, IDX)
133+
.setCriteria(lt("id", CNT / 2));
134+
135+
List<Cache.Entry<Long, BinaryObject>> res = binCache.query(qry.setLocal(true)).getAll();
136+
137+
for (Cache.Entry<Long, BinaryObject> e : res)
138+
assertEquals(new Person(e.getKey().intValue()), e.getValue().deserialize());
139+
140+
assertEquals(CNT / 2, res.size());
141+
}
142+
102143
/** Should fail as no data on nodes. */
103144
@Test
104145
public void testClientNodeReplicatedCache() throws Exception {

0 commit comments

Comments
 (0)