Repository: ignite Updated Branches: refs/heads/ignite-4424-1.6.12 [created] 7035e5ee5
GG-11746: Backport of IGNITE-4379: Fixed broken local SqlFieldsQuery. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/18598574 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/18598574 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/18598574 Branch: refs/heads/ignite-4424-1.6.12 Commit: 18598574bb2992aa193eed1d72ca333a1e21ad72 Parents: 6e36a79 Author: Andrey V. Mashenkov <[email protected]> Authored: Thu Dec 8 12:36:07 2016 +0300 Committer: Andrey V. Mashenkov <[email protected]> Committed: Thu Dec 8 12:36:07 2016 +0300 ---------------------------------------------------------------------- .../processors/query/h2/IgniteH2Indexing.java | 36 ++++++++++---------- ...niteCachePartitionedFieldsQuerySelfTest.java | 25 ++++++++++++++ 2 files changed, 43 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/18598574/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 5c2fab5..3ea238b 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -737,33 +737,33 @@ public class IgniteH2Indexing implements GridQueryIndexing { @Nullable final Collection<Object> params, final IndexingQueryFilter filters, final int timeout, final GridQueryCancel cancel) throws IgniteCheckedException { - setFilters(filters); + final Connection conn = connectionForThread(schema(spaceName)); - try { - final Connection conn = connectionForThread(schema(spaceName)); + final PreparedStatement stmt = preparedStatementWithParams(conn, qry, params, true); - final PreparedStatement stmt = preparedStatementWithParams(conn, qry, params, true); + List<GridQueryFieldMetadata> meta; - List<GridQueryFieldMetadata> meta; + try { + meta = meta(stmt.getMetaData()); + } + catch (SQLException e) { + throw new IgniteCheckedException("Cannot prepare query metadata", e); + } - try { - meta = meta(stmt.getMetaData()); - } - catch (SQLException e) { - throw new IgniteCheckedException("Cannot prepare query metadata", e); - } + return new GridQueryFieldsResultAdapter(meta, null) { + @Override public GridCloseableIterator<List<?>> iterator() throws IgniteCheckedException { + setFilters(filters); - return new GridQueryFieldsResultAdapter(meta, null) { - @Override public GridCloseableIterator<List<?>> iterator() throws IgniteCheckedException{ + try { ResultSet rs = executeSqlQueryWithTimer(spaceName, stmt, conn, qry, params, timeout, cancel); return new FieldsIterator(rs); } - }; - } - finally { - setFilters(null); - } + finally { + setFilters(null); + } + } + }; } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/18598574/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedFieldsQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedFieldsQuerySelfTest.java index 653947e..af5845d 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedFieldsQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCachePartitionedFieldsQuerySelfTest.java @@ -17,7 +17,13 @@ package org.apache.ignite.internal.processors.cache.distributed.near; +import java.util.List; +import javax.cache.Cache; +import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CachePeekMode; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractFieldsQuerySelfTest; @@ -54,4 +60,23 @@ public class IgniteCachePartitionedFieldsQuerySelfTest extends IgniteCacheAbstra return cc; } + + /** @throws Exception If failed. */ + public void testLocalQuery() throws Exception { + IgniteCache<Object, Object> cache = grid(0).cache( null); + + awaitPartitionMapExchange(true, true, null); + + int expected = 0; + + for(Cache.Entry e: cache.localEntries(CachePeekMode.PRIMARY)){ + if(e.getValue() instanceof Integer) + expected++; + } + + QueryCursor<List<?>> qry = cache + .query(new SqlFieldsQuery("select _key, _val from Integer").setLocal(true)); + + assertEquals(expected, qry.getAll().size()); + } } \ No newline at end of file
