IGNITE-7229 .NET: Rename ICache.QueryFields to Query, add FieldNames
authorPavel Tupitsyn <ptupitsyn@apache.org>
Tue, 19 Dec 2017 07:20:08 +0000 (10:20 +0300)
committerPavel Tupitsyn <ptupitsyn@apache.org>
Tue, 19 Dec 2017 07:20:08 +0000 (10:20 +0300)
This closes #3247

28 files changed:
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
modules/platforms/dotnet/Apache.Ignite.AspNet.Tests/ExpiryCacheHolderTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryFooterTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/Serializable/SqlDmlTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheTestAsyncWrapper.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheDmlQueriesTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/Linq/CacheLinqTest.Introspection.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Client/Cache/SqlQueryTest.cs
modules/platforms/dotnet/Apache.Ignite.Core/Cache/ICache.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryReaderExtensions.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheImpl.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/ICacheInternal.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/FieldsQueryCursor.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/PlatformQueryQursorBase.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/CacheClient.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/Cache/Query/ClientFieldsQueryCursor.cs
modules/platforms/dotnet/Apache.Ignite.Core/NuGet/LINQPad/BinaryModeExample.linq
modules/platforms/dotnet/Apache.Ignite.Core/NuGet/LINQPad/QueryExample.linq
modules/platforms/dotnet/Apache.Ignite.Linq/CacheLinqExtensions.cs
modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs
modules/platforms/dotnet/Apache.Ignite.ndproj
modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/BinaryModeExample.cs
modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryDmlExample.cs
modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs
modules/platforms/dotnet/examples/dotnetcore/SqlExample.cs

index 20e98fc..aef8e59 100644 (file)
@@ -176,6 +176,15 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
     protected abstract void write(BinaryRawWriterEx writer, T val);
 
     /**
+     * Gets the cursor.
+     *
+     * @return Cursor.
+     */
+    public QueryCursorEx<T> cursor() {
+        return cursor;
+    }
+
+    /**
      * Query cursor consumer.
      */
     private static class Consumer<T> implements QueryCursorEx.Consumer<T> {
index 25f86f2..15561b0 100644 (file)
 
 package org.apache.ignite.internal.processors.platform.cache.query;
 
-import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.query.FieldsQueryCursor;
 import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 
+import java.util.List;
+
 /**
  * Interop cursor for fields query.
  */
 public class PlatformFieldsQueryCursor extends PlatformAbstractQueryCursor<List<?>> {
+    /** Gets field names. */
+    private static final int OP_GET_FIELD_NAMES = 7;
+
     /**
      * Constructor.
      *
@@ -52,4 +58,20 @@ public class PlatformFieldsQueryCursor extends PlatformAbstractQueryCursor<List<
         
         writer.writeInt(rowSizePos, rowEndPos - rowSizePos);
     }
+
+    /** {@inheritDoc} */
+    @Override public void processOutStream(int type, final BinaryRawWriterEx writer) throws IgniteCheckedException {
+        if (type == OP_GET_FIELD_NAMES) {
+            FieldsQueryCursor fq = (FieldsQueryCursor) cursor();
+
+            int cnt = fq.getColumnsCount();
+            writer.writeInt(cnt);
+
+            for (int i = 0; i < cnt; i++) {
+                writer.writeString(fq.getFieldName(i));
+            }
+        } else {
+            super.processOutStream(type, writer);
+        }
+    }
 }
index 2fe3309..93e3a53 100644 (file)
@@ -419,6 +419,11 @@ namespace Apache.Ignite.AspNet.Tests
                 throw new NotImplementedException();
             }
 
+            public IFieldsQueryCursor Query(SqlFieldsQuery qry)
+            {
+                throw new NotImplementedException();
+            }
+
             public IQueryCursor<IList> QueryFields(SqlFieldsQuery qry)
             {
                 throw new NotImplementedException();
index 9fa4538..34df6d7 100644 (file)
@@ -146,7 +146,7 @@ namespace Apache.Ignite.Core.Tests.Binary
             Assert.AreEqual(dt.Arr, cache[1].Arr);
 
             // SQL: read field on Java side to ensure correct offset handling.
-            var res = cache.QueryFields(new SqlFieldsQuery("select int from OffsetTest")).GetAll()[0][0];
+            var res = cache.Query(new SqlFieldsQuery("select int from OffsetTest")).GetAll()[0][0];
             Assert.AreEqual(dt.Int, (int) res);
         }
 
index 4b77dbe..0ffd068 100644 (file)
@@ -107,7 +107,7 @@ namespace Apache.Ignite.Core.Tests.Binary.Serializable
 
             // Test DML.
             var guid = Guid.NewGuid();
-            var insertRes = cache.QueryFields(new SqlFieldsQuery(
+            var insertRes = cache.Query(new SqlFieldsQuery(
                 "insert into SimpleSerializable(_key, Byte, Bool, Short, Int, Long, Float, Double, " +
                 "Decimal, Guid, String) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 
                 3, 45, true, 43, 33, 99, 4.5f, 6.7, 9.04m, guid, "bar33")).GetAll();
@@ -141,7 +141,7 @@ namespace Apache.Ignite.Core.Tests.Binary.Serializable
             Assert.AreEqual(uint.MaxValue, cache[1].Uint);
 
             // Test SQL.
-            var sqlRes = cache.QueryFields(new SqlFieldsQuery(
+            var sqlRes = cache.Query(new SqlFieldsQuery(
                 "select uint from DotNetSpecificSerializable where uint <> 0")).GetAll();
 
             Assert.AreEqual(1, sqlRes.Count);
@@ -152,7 +152,7 @@ namespace Apache.Ignite.Core.Tests.Binary.Serializable
             Assert.AreEqual(uint.MaxValue, linqRes);
 
             // Test DML.
-            var dmlRes = cache.QueryFields(new SqlFieldsQuery(
+            var dmlRes = cache.Query(new SqlFieldsQuery(
                 "insert into DotNetSpecificSerializable(_key, uint) values (?, ?), (?, ?)",
                 2, uint.MaxValue, 3, 88)).GetAll();
             Assert.AreEqual(1, dmlRes.Count);
index 5ba2fc9..0b1af41 100644 (file)
@@ -445,6 +445,13 @@ namespace Apache.Ignite.Core.Tests.Cache
         }
 
         /** <inheritDoc /> */
+        public IFieldsQueryCursor Query(SqlFieldsQuery qry)
+        {
+            return _cache.Query(qry);
+        }
+
+        /** <inheritDoc /> */
+        [Obsolete]
         public IQueryCursor<IList> QueryFields(SqlFieldsQuery qry)
         {
             return _cache.QueryFields(qry);
index 741dff0..f289e56 100644 (file)
@@ -76,7 +76,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cache = Ignition.GetIgnite().CreateCache<int, Foo>(cfg);
 
             // Test insert.
-            var res = cache.QueryFields(new SqlFieldsQuery("insert into foo(_key, id, name) " +
+            var res = cache.Query(new SqlFieldsQuery("insert into foo(_key, id, name) " +
                                                            "values (?, ?, ?), (?, ?, ?)",
                 1, 2, "John", 3, 4, "Mary")).GetAll();
 
@@ -118,7 +118,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
             var cache = Ignition.GetIgnite().CreateCache<int, Foo>(cfg);
 
-            var ex = Assert.Throws<IgniteException>(() => cache.QueryFields(new SqlFieldsQuery(
+            var ex = Assert.Throws<IgniteException>(() => cache.Query(new SqlFieldsQuery(
                 "insert into foo(_key, name) values (?, ?)", 1, "bar")).GetAll());
 
             Assert.AreEqual("Null value is not allowed for column 'ID'", ex.Message);
@@ -133,7 +133,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cfg = new CacheConfiguration("not_null_attr", new QueryEntity(typeof(int), typeof(Foo)));
             var cache = Ignition.GetIgnite().CreateCache<int, Foo>(cfg);
 
-            var ex = Assert.Throws<IgniteException>(() => cache.QueryFields(new SqlFieldsQuery(
+            var ex = Assert.Throws<IgniteException>(() => cache.Query(new SqlFieldsQuery(
                 "insert into foo(_key, id) values (?, ?)", 1, 2)).GetAll());
 
             Assert.AreEqual("Null value is not allowed for column 'NAME'", ex.Message);
@@ -169,7 +169,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
             foreach (var val in vals)
             {
-                var res = cache.QueryFields(new SqlFieldsQuery(
+                var res = cache.Query(new SqlFieldsQuery(
                     "insert into string(_key, _val) values (?, ?)", val, val.ToString())).GetAll();
 
                 Assert.AreEqual(1, res.Count);
@@ -190,7 +190,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cache = Ignition.GetIgnite().CreateCache<Key, Foo>(cfg);
 
             // Test insert.
-            var res = cache.QueryFields(new SqlFieldsQuery("insert into foo(hi, lo, id, name) " +
+            var res = cache.Query(new SqlFieldsQuery("insert into foo(hi, lo, id, name) " +
                                                "values (-1, 65500, 3, 'John'), (255, 128, 6, 'Mary')")).GetAll();
 
             Assert.AreEqual(1, res.Count);
@@ -240,7 +240,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cache = Ignition.GetIgnite().CreateCache<Key2, Foo>(cfg);
 
             // Test insert.
-            var res = cache.QueryFields(new SqlFieldsQuery("insert into foo(hi, lo, str, id, name) " +
+            var res = cache.Query(new SqlFieldsQuery("insert into foo(hi, lo, str, id, name) " +
                                                "values (1, 2, 'Фу', 3, 'John'), (4, 5, 'Бар', 6, 'Mary')")).GetAll();
 
             Assert.AreEqual(1, res.Count);
@@ -293,7 +293,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cache = Ignition.GetIgnite().CreateCache<Key, Foo>(cfg);
 
             var ex = Assert.Throws<IgniteException>(
-                () => cache.QueryFields(new SqlFieldsQuery("insert into foo(lo, hi, id, name) " +
+                () => cache.Query(new SqlFieldsQuery("insert into foo(lo, hi, id, name) " +
                                                            "values (1, 2, 3, 'John'), (4, 5, 6, 'Mary')")));
 
             Assert.AreEqual("Ownership flag not set for binary property. Have you set 'keyFields' " +
@@ -322,7 +322,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var cache = Ignition.GetIgnite().CreateCache<object, object>(cfg)
                 .WithKeepBinary<IBinaryObject, IBinaryObject>();
 
-            var res = cache.QueryFields(new SqlFieldsQuery("insert into car(VIN, Id, Make, Year) " +
+            var res = cache.Query(new SqlFieldsQuery("insert into car(VIN, Id, Make, Year) " +
                                                            "values ('DLRDMC', 88, 'DeLorean', 1982)")).GetAll();
 
             Assert.AreEqual(1, res.Count);
@@ -362,7 +362,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             };
 
             // Test insert.
-            var res = cache.QueryFields(new SqlFieldsQuery(
+            var res = cache.Query(new SqlFieldsQuery(
                     "insert into string(byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, " +
                     "guid, string, key, _val) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                     key.Byte, key.SByte, key.Short, key.UShort, key.Int, key.UInt, key.Long, key.ULong, key.Float,
index 2e24ff6..9768fca 100644 (file)
@@ -91,7 +91,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                     Assert.AreEqual(2, cursor.GetAll().Single().Key);
                 }
 
-                using (var cursor = cache.QueryFields(new SqlFieldsQuery(
+                using (var cursor = cache.Query(new SqlFieldsQuery(
                     "select _key from CustomTableName where age > ? and birthday < ?", 10, DateTime.UtcNow)))
                 {
                     Assert.AreEqual(2, cursor.GetAll().Single()[0]);
index 8134b3d..278d1fd 100644 (file)
@@ -20,7 +20,6 @@
 namespace Apache.Ignite.Core.Tests.Cache.Query
 {
     using System;
-    using System.Collections;
     using System.Collections.Generic;
     using System.Diagnostics.CodeAnalysis;
     using System.Linq;
@@ -156,7 +155,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         public void TestValidationSqlFields()
         {
             // 1. No sql.
-            Assert.Throws<ArgumentException>(() => { Cache().QueryFields(new SqlFieldsQuery(null)); });
+            Assert.Throws<ArgumentException>(() => { Cache().Query(new SqlFieldsQuery(null)); });
         }
 
         /// <summary>
@@ -285,11 +284,9 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Cache().Put(3, new QueryPerson("Sidorov", 50));
 
             // 1. Empty result set.
-            using (
-                IQueryCursor<IList> cursor = Cache().QueryFields(
-                    new SqlFieldsQuery("SELECT age FROM QueryPerson WHERE age < ?", 50)))
+            using (var cursor = Cache().Query(new SqlFieldsQuery("SELECT age FROM QueryPerson WHERE age < ?", 50)))
             {
-                foreach (IList entry in cursor.GetAll())
+                foreach (var entry in cursor.GetAll())
                     Assert.IsTrue((int) entry[0] < 50);
             }
         }
@@ -390,7 +387,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                 Lazy = lazy
             };
 
-            using (IQueryCursor<IList> cursor = cache.QueryFields(qry))
+            using (var cursor = cache.Query(qry))
             {
                 HashSet<int> exp0 = new HashSet<int>(exp);
 
@@ -403,9 +400,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                 }
 
                 Assert.AreEqual(0, exp0.Count);
+                Assert.AreEqual(new[] {"NAME", "AGE"}, cursor.FieldNames);
             }
 
-            using (IQueryCursor<IList> cursor = cache.QueryFields(qry))
+            // Test old API as well.
+#pragma warning disable 618
+            using (var cursor = cache.QueryFields(qry))
             {
                 HashSet<int> exp0 = new HashSet<int>(exp);
 
@@ -418,6 +418,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
                 Assert.AreEqual(0, exp0.Count);
             }
+#pragma warning restore 618
         }
 
         /// <summary>
@@ -622,7 +623,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             strings[1] = "foo";
 
             // Default schema.
-            var res = doubles.QueryFields(new SqlFieldsQuery(
+            var res = doubles.Query(new SqlFieldsQuery(
                     "select S._val from double as D join \"strings\".string as S on S._key = D._key"))
                 .Select(x => (string) x[0])
                 .Single();
@@ -630,7 +631,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.AreEqual("foo", res);
 
             // Custom schema.
-            res = doubles.QueryFields(new SqlFieldsQuery(
+            res = doubles.Query(new SqlFieldsQuery(
                     "select S._val from \"doubles\".double as D join string as S on S._key = D._key")
                 {
                     Schema = strings.Name
@@ -667,13 +668,13 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             var sql = "select T0.Age from QueryPerson as T0 " +
                       "inner join QueryPerson as T1 on ((? - T1.Age - 1) = T0._key)";
 
-            var res = cache.QueryFields(new SqlFieldsQuery(sql, count)).GetAll().Distinct().Count();
+            var res = cache.Query(new SqlFieldsQuery(sql, count)).GetAll().Distinct().Count();
 
             Assert.Greater(res, 0);
             Assert.Less(res, count);
 
             // Test distributed join: returns complete results
-            res = cache.QueryFields(new SqlFieldsQuery(sql, count) {EnableDistributedJoins = true})
+            res = cache.Query(new SqlFieldsQuery(sql, count) {EnableDistributedJoins = true})
                 .GetAll().Distinct().Count();
 
             Assert.AreEqual(count, res);
@@ -709,7 +710,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
             cache[1] = new QueryPerson("Joe", 48);
 
-            var row = cache.QueryFields(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0];
+            var row = cache.Query(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0];
             Assert.AreEqual(2, row.Count);
             Assert.AreEqual(48, row[0]);
             Assert.AreEqual("Joe", row[1]);
@@ -736,7 +737,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
 
             cache[1] = new QueryPerson("John", 33);
 
-            row = cache.QueryFields(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0];
+            row = cache.Query(new SqlFieldsQuery("select * from QueryPerson")).GetAll()[0];
             
             Assert.AreEqual(3, row.Count);
             Assert.AreEqual(33, row[0]);
@@ -746,7 +747,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Assert.AreEqual("John", person.Name);
 
             // Check explicit select.
-            row = cache.QueryFields(new SqlFieldsQuery("select FullKey from QueryPerson")).GetAll()[0];
+            row = cache.Query(new SqlFieldsQuery("select FullKey from QueryPerson")).GetAll()[0];
             Assert.AreEqual(1, row[0]);
         }
 
@@ -786,11 +787,47 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             };
 
             // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
-            var ex = Assert.Throws<CacheException>(() => cache.QueryFields(fieldsQry).ToArray());
+            var ex = Assert.Throws<CacheException>(() => cache.Query(fieldsQry).ToArray());
             Assert.IsTrue(ex.ToString().Contains("QueryCancelledException: The query was cancelled while executing."));
         }
 
         /// <summary>
+        /// Tests the FieldNames property.
+        /// </summary>
+        [Test]
+        public void TestFieldNames()
+        {
+            var cache = Cache();
+            PopulateCache(cache, false, 5, x => true);
+
+            // Get before iteration.
+            var qry = new SqlFieldsQuery("SELECT * FROM QueryPerson");
+            var cur = cache.Query(qry);
+            var names = cur.FieldNames;
+
+            Assert.AreEqual(new[] {"AGE", "NAME" }, names);
+            
+            cur.Dispose();
+            Assert.AreSame(names, cur.FieldNames);
+
+            Assert.Throws<NotSupportedException>(() => cur.FieldNames.Add("x"));
+
+            // Custom order, key-val, get after iteration.
+            qry.Sql = "SELECT NAME, _key, AGE, _val FROM QueryPerson";
+            cur = cache.Query(qry);
+            cur.GetAll();
+
+            Assert.AreEqual(new[] { "NAME", "_KEY", "AGE", "_VAL" }, cur.FieldNames);
+
+            // Get after disposal.
+            qry.Sql = "SELECT 1, AGE FROM QueryPerson";
+            cur = cache.Query(qry);
+            cur.Dispose();
+            
+            Assert.AreEqual(new[] { "1", "AGE" }, cur.FieldNames);
+        }
+
+        /// <summary>
         /// Validates the query results.
         /// </summary>
         /// <param name="cache">Cache.</param>
index 6e7483e..aa26548 100644 (file)
@@ -72,7 +72,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query.Linq
 
             Assert.AreEqual(new[] { 10 }, fq.Arguments);
             Assert.IsTrue(fq.Local);
-            Assert.AreEqual(PersonCount - 11, cache.QueryFields(fq).GetAll().Count);
+            Assert.AreEqual(PersonCount - 11, cache.Query(fq).GetAll().Count);
             Assert.AreEqual(999, fq.PageSize);
             Assert.IsFalse(fq.EnableDistributedJoins);
             Assert.IsTrue(fq.EnforceJoinOrder);
index 6f6df11..b9de090 100644 (file)
@@ -114,7 +114,9 @@ namespace Apache.Ignite.Core.Tests.Client.Cache
 
             // DateTime.
             qry = new SqlFieldsQuery("select Id, DateTime from Person where DateTime > ?", DateTime.UtcNow.AddDays(9));
-            Assert.AreEqual(cache[Count].DateTime, cache.Query(qry).Single().Last());
+            cursor = cache.Query(qry);
+            Assert.AreEqual(new[] {"ID", "DATETIME" }, cursor.FieldNames);
+            Assert.AreEqual(cache[Count].DateTime, cursor.Single().Last());
 
             // Invalid args.
             qry.Sql = null;
index f83f279..8a9fe59 100644 (file)
@@ -705,6 +705,14 @@ namespace Apache.Ignite.Core.Cache
         /// </summary>
         /// <param name="qry">SQL fields query.</param>
         /// <returns>Cursor.</returns>
+        IFieldsQueryCursor Query(SqlFieldsQuery qry);
+
+        /// <summary>
+        /// Queries separate entry fields.
+        /// </summary>
+        /// <param name="qry">SQL fields query.</param>
+        /// <returns>Cursor.</returns>
+        [Obsolete("Use Query(SqlFieldsQuery qry) instead.")]
         IQueryCursor<IList> QueryFields(SqlFieldsQuery qry);
 
         /// <summary>
index db2f84f..b13318c 100644 (file)
@@ -130,7 +130,7 @@ namespace Apache.Ignite.Core.Impl.Binary
         /// <summary>
         /// Reads the string collection.
         /// </summary>
-        public static ICollection<string> ReadStringCollection(this IBinaryRawReader reader)
+        public static List<string> ReadStringCollection(this IBinaryRawReader reader)
         {
             Debug.Assert(reader != null);
 
index ca9fb63..6661161 100644 (file)
@@ -1054,17 +1054,26 @@ namespace Apache.Ignite.Core.Impl.Cache
         #region Queries
 
         /** <inheritDoc /> */
+        public IFieldsQueryCursor Query(SqlFieldsQuery qry)
+        {
+            var cursor = QueryFieldsInternal(qry);
+
+            return new FieldsQueryCursor(cursor, _flagKeepBinary, 
+                (reader, count) => ReadFieldsArrayList(reader, count));
+        }
+
+        /** <inheritDoc /> */
         public IQueryCursor<IList> QueryFields(SqlFieldsQuery qry)
         {
-            return QueryFields(qry, ReadFieldsArrayList);
+            return Query(qry, (reader, count) => (IList) ReadFieldsArrayList(reader, count));
         }
 
         /// <summary>
         /// Reads the fields array list.
         /// </summary>
-        private static IList ReadFieldsArrayList(IBinaryRawReader reader, int count)
+        private static List<object> ReadFieldsArrayList(IBinaryRawReader reader, int count)
         {
-            IList res = new ArrayList(count);
+            var res = new List<object>(count);
 
             for (var i = 0; i < count; i++)
                 res.Add(reader.ReadObject<object>());
@@ -1073,15 +1082,21 @@ namespace Apache.Ignite.Core.Impl.Cache
         }
 
         /** <inheritDoc /> */
-        public IQueryCursor<T> QueryFields<T>(SqlFieldsQuery qry, Func<IBinaryRawReader, int, T> readerFunc)
+        public IQueryCursor<T> Query<T>(SqlFieldsQuery qry, Func<IBinaryRawReader, int, T> readerFunc)
+        {
+            var cursor = QueryFieldsInternal(qry);
+
+            return new FieldsQueryCursor<T>(cursor, _flagKeepBinary, readerFunc);
+        }
+
+        private IPlatformTargetInternal QueryFieldsInternal(SqlFieldsQuery qry)
         {
             IgniteArgumentCheck.NotNull(qry, "qry");
-            IgniteArgumentCheck.NotNull(readerFunc, "readerFunc");
 
             if (string.IsNullOrEmpty(qry.Sql))
                 throw new ArgumentException("Sql cannot be null or empty");
 
-            var cursor = DoOutOpObject((int) CacheOp.QrySqlFields, writer =>
+            return DoOutOpObject((int) CacheOp.QrySqlFields, writer =>
             {
                 writer.WriteBoolean(qry.Local);
                 writer.WriteString(qry.Sql);
@@ -1097,8 +1112,6 @@ namespace Apache.Ignite.Core.Impl.Cache
                 writer.WriteBoolean(qry.Colocated);
                 writer.WriteString(qry.Schema); // Schema
             });
-        
-            return new FieldsQueryCursor<T>(cursor, _flagKeepBinary, readerFunc);
         }
 
         /** <inheritDoc /> */
index 1ec5341..fb968cf 100644 (file)
@@ -36,7 +36,7 @@ namespace Apache.Ignite.Core.Impl.Cache
         /// <returns>
         /// Cursor.
         /// </returns>
-        IQueryCursor<T> QueryFields<T>(SqlFieldsQuery qry, Func<IBinaryRawReader, int, T> readerFunc);
+        IQueryCursor<T> Query<T>(SqlFieldsQuery qry, Func<IBinaryRawReader, int, T> readerFunc);
 
         /// <summary>
         /// Invokes a cache extension.
index c60e010..c9e64a8 100644 (file)
 namespace Apache.Ignite.Core.Impl.Cache.Query
 {
     using System;
+    using System.Collections.Generic;
+    using System.Collections.ObjectModel;
     using Apache.Ignite.Core.Binary;
+    using Apache.Ignite.Core.Cache.Query;
+    using Apache.Ignite.Core.Impl.Binary;
 
     /// <summary>
     /// Cursor for entry-based queries.
@@ -47,4 +51,39 @@ namespace Apache.Ignite.Core.Impl.Cache.Query
             // No-op.
         }
     }
+
+    /// <summary>
+    /// Cursor for entry-based queries.
+    /// </summary>
+    internal class FieldsQueryCursor : FieldsQueryCursor<IList<object>>, IFieldsQueryCursor
+    {
+        /** */
+        private const int OpGetFieldNames = 7;
+
+        /** */
+        private IList<string> _fieldNames;
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="target">Target.</param>
+        /// <param name="keepBinary">Keep poratble flag.</param>
+        /// <param name="readerFunc">The reader function.</param>
+        public FieldsQueryCursor(IPlatformTargetInternal target, bool keepBinary, 
+            Func<IBinaryRawReader, int, IList<object>> readerFunc) : base(target, keepBinary, readerFunc)
+        {
+            // No-op.
+        }
+
+        /** <inheritdoc /> */
+        public IList<string> FieldNames
+        {
+            get
+            {
+                return _fieldNames ??
+                       (_fieldNames = new ReadOnlyCollection<string>(
+                           Target.OutStream(OpGetFieldNames, reader => reader.ReadStringCollection())));
+            }
+        }
+    }
 }
index fc78392..3f1e4fc 100644 (file)
@@ -54,6 +54,14 @@ namespace Apache.Ignite.Core.Impl.Cache.Query
             _target = target;
         }
 
+        /// <summary>
+        /// Gets the target.
+        /// </summary>
+        public IPlatformTargetInternal Target
+        {
+            get { return _target; }
+        }
+
         /** <inheritdoc /> */
         protected override IList<T> GetAllInternal()
         {
index 93829c2..2344417 100644 (file)
@@ -196,7 +196,7 @@ namespace Apache.Ignite.Core.Impl.Client.Cache
         }
 
         /** <inheritDoc /> */
-        public IQueryCursor<T> QueryFields<T>(SqlFieldsQuery sqlFieldsQuery, Func<IBinaryRawReader, int, T> readerFunc)
+        public IQueryCursor<T> Query<T>(SqlFieldsQuery sqlFieldsQuery, Func<IBinaryRawReader, int, T> readerFunc)
         {
             return DoOutInOp(ClientOp.QuerySqlFields, 
                 w => WriteSqlFieldsQuery(w, sqlFieldsQuery, false),
index 2e57863..c8f7e1f 100644 (file)
@@ -22,6 +22,7 @@ namespace Apache.Ignite.Core.Impl.Client.Cache.Query
     using System.Diagnostics;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache.Query;
+    using Apache.Ignite.Core.Impl.Binary;
     using Apache.Ignite.Core.Impl.Binary.IO;
 
     /// <summary>
@@ -64,16 +65,9 @@ namespace Apache.Ignite.Core.Impl.Client.Cache.Query
         /// <summary>
         /// Reads the columns.
         /// </summary>
-        internal static string[] ReadColumns(IBinaryRawReader reader)
+        internal static List<string> ReadColumns(IBinaryRawReader reader)
         {
-            var res = new string[reader.ReadInt()];
-
-            for (var i = 0; i < res.Length; i++)
-            {
-                res[i] = reader.ReadString();
-            }
-
-            return res;
+            return reader.ReadStringCollection();
         }
     }
 }
index 2220650..4b2291e 100644 (file)
@@ -90,6 +90,6 @@ using (var ignite = Ignition.Start())
                .Dump("Persons with age less than 40:");
                
        // Run SQL fields query.
-       cache.QueryFields(new SqlFieldsQuery("select name from Person order by name"))
+       cache.Query(new SqlFieldsQuery("select name from Person order by name"))
                .Dump("All person names:");
 }
\ No newline at end of file
index 19d55a3..b3d63ba 100644 (file)
@@ -66,7 +66,7 @@ void Main()
                        .Dump("Persons working for " + orgName);
 
                // Fields query
-               orgs.QueryFields(new SqlFieldsQuery("select name, size from Organization")).Dump("Fields query");
+               orgs.Query(new SqlFieldsQuery("select name, size from Organization")).Dump("Fields query");
 
                // Full text query
                persons.Query(new TextQuery(typeof(Person), "Chris*")).Dump("Persons starting with 'Chris'");
index 940b23b..935666f 100644 (file)
@@ -23,6 +23,7 @@ namespace Apache.Ignite.Linq
     using System.Linq.Expressions;
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Cache.Query;
     using Apache.Ignite.Core.Impl.Cache;
     using Apache.Ignite.Core.Impl.Common;
     using Apache.Ignite.Linq.Impl;
@@ -37,8 +38,7 @@ namespace Apache.Ignite.Linq
         /// Gets an <see cref="IQueryable{T}"/> instance over this cache.
         /// <para />
         /// Resulting query will be translated to cache SQL query and executed over the cache instance 
-        /// via either <see cref="ICache{TK,TV}.Query"/> or <see cref="ICache{TK,TV}.QueryFields"/>,
-        /// depending on requested result. 
+        /// via <see cref="ICache{TK,TV}.Query(SqlFieldsQuery)"/>. 
         /// <para />
         /// Result of this method (and subsequent query) can be cast to <see cref="ICacheQueryable"/>
         /// for introspection, or converted with <see cref="ToCacheQueryable{T}"/> extension method.
@@ -59,7 +59,7 @@ namespace Apache.Ignite.Linq
         /// Gets an <see cref="IQueryable{T}"/> instance over this cache.
         /// <para />
         /// Resulting query will be translated to cache SQL query and executed over the cache instance 
-        /// via either <see cref="ICache{TK,TV}.Query"/> or <see cref="ICache{TK,TV}.QueryFields"/>,
+        /// via <see cref="ICache{TK,TV}.Query(SqlFieldsQuery)"/>. 
         /// depending on requested result. 
         /// <para />
         /// Result of this method (and subsequent query) can be cast to <see cref="ICacheQueryable"/> for introspection.
@@ -82,7 +82,7 @@ namespace Apache.Ignite.Linq
         /// Gets an <see cref="IQueryable{T}" /> instance over this cache.
         /// <para />
         /// Resulting query will be translated to cache SQL query and executed over the cache instance
-        /// via either <see cref="ICache{TK,TV}.Query" /> or <see cref="ICache{TK,TV}.QueryFields" />,
+        /// via <see cref="ICache{TK,TV}.Query(SqlFieldsQuery)"/>. 
         /// depending on requested result.
         /// <para />
         /// Result of this method (and subsequent query) can be cast to <see cref="ICacheQueryable" /> for introspection.
@@ -112,7 +112,7 @@ namespace Apache.Ignite.Linq
         /// Gets an <see cref="IQueryable{T}" /> instance over this cache.
         /// <para />
         /// Resulting query will be translated to cache SQL query and executed over the cache instance
-        /// via either <see cref="ICache{TK,TV}.Query" /> or <see cref="ICache{TK,TV}.QueryFields" />,
+        /// via <see cref="ICache{TK,TV}.Query(SqlFieldsQuery)"/>. 
         /// depending on requested result.
         /// <para />
         /// Result of this method (and subsequent query) can be cast to <see cref="ICacheQueryable" /> for introspection.
index fb34270..9d0edd7 100644 (file)
@@ -89,7 +89,7 @@ namespace Apache.Ignite.Linq.Impl
 
             var selector = GetResultSelector<T>(queryModel.SelectClause.Selector);
 
-            return _cache.QueryFields(qry, selector);
+            return _cache.Query(qry, selector);
         }
 
         /// <summary>
@@ -102,7 +102,7 @@ namespace Apache.Ignite.Linq.Impl
             var qryText = GetQueryData(queryModel).QueryText;
             var selector = GetResultSelector<T>(queryModel.SelectClause.Selector);
 
-            return args => _cache.QueryFields(GetFieldsQuery(qryText, args), selector);
+            return args => _cache.Query(GetFieldsQuery(qryText, args), selector);
         }
 
         /// <summary>
@@ -144,7 +144,7 @@ namespace Apache.Ignite.Linq.Impl
             // Simple case: lambda with no parameters. Only embedded parameters are used.
             if (!queryLambda.Parameters.Any())
             {
-                return argsUnused => _cache.QueryFields(GetFieldsQuery(qryText, qryParams), selector);
+                return argsUnused => _cache.Query(GetFieldsQuery(qryText, qryParams), selector);
             }
 
             // These are in order of usage in query
@@ -157,7 +157,7 @@ namespace Apache.Ignite.Linq.Impl
             if (qryOrderArgs.Length == qryParams.Length
                 && qryOrderArgs.SequenceEqual(userOrderArgs))
             {
-                return args => _cache.QueryFields(GetFieldsQuery(qryText, args), selector);
+                return args => _cache.Query(GetFieldsQuery(qryText, args), selector);
             }
 
             // General case: embedded args and lambda args are mixed; same args can be used multiple times.
@@ -172,7 +172,7 @@ namespace Apache.Ignite.Linq.Impl
                 return -1;
             }).ToArray();
 
-            return args => _cache.QueryFields(
+            return args => _cache.Query(
                 GetFieldsQuery(qryText, MapQueryArgs(args, qryParams, mapping)), selector);
         }
 
index 5ed9e3c..ae99617 100644 (file)
@@ -2029,7 +2029,7 @@ select new {
 // is equal to 3 minutes per derived class used by the base class +
 // 3 minutes per member of a derived class used by the base class.
 //</HowToFix>]]></Query>
-      <Query Active="True" DisplayList="True" DisplayStat="False" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Class shouldn't be too deep in inheritance tree</Name>
+      <Query Active="False" DisplayList="True" DisplayStat="False" DisplaySelectionView="False" IsCriticalRule="False"><![CDATA[// <Name>Class shouldn't be too deep in inheritance tree</Name>
         
 warnif count > 0 from t in JustMyCode.Types 
 where t.IsClass
index 1cc406b..89021e6 100644 (file)
@@ -18,7 +18,6 @@
 namespace Apache.Ignite.Examples.Datagrid
 {
     using System;
-    using System.Collections;
     using Apache.Ignite.Core;
     using Apache.Ignite.Core.Binary;
     using Apache.Ignite.Core.Cache;
@@ -196,12 +195,12 @@ namespace Apache.Ignite.Examples.Datagrid
         /// <param name="cache">Cache.</param>
         private static void SqlFieldsQueryExample(ICache<int, IBinaryObject> cache)
         {
-            var qry = cache.QueryFields(new SqlFieldsQuery("select name from Person order by name"));
+            var qry = cache.Query(new SqlFieldsQuery("select name from Person order by name"));
 
             Console.WriteLine();
             Console.WriteLine(">>> All person names:");
 
-            foreach (IList row in qry)
+            foreach (var row in qry)
                 Console.WriteLine(">>>     " + row[0]);
         }
 
index 10bf1dd..00486bd 100644 (file)
@@ -98,7 +98,7 @@ namespace Apache.Ignite.Examples.Datagrid
                 EnableDistributedJoins = true
             };
 
-            using (var cursor = employeeCache.QueryFields(qry))
+            using (var cursor = employeeCache.Query(qry))
             {
                 foreach (var row in cursor)
                 {
@@ -116,25 +116,25 @@ namespace Apache.Ignite.Examples.Datagrid
         {
             // Insert organizations.
             var qry = new SqlFieldsQuery("insert into Organization (_key, name) values (?, ?)", 1, "ASF");
-            organizationCache.QueryFields(qry);
+            organizationCache.Query(qry);
 
             qry.Arguments = new object[] {2, "Eclipse"};
-            organizationCache.QueryFields(qry);
+            organizationCache.Query(qry);
 
             // Insert employees.
             qry = new SqlFieldsQuery("insert into Employee (_key, name, organizationId, salary) values (?, ?, ?, ?)");
 
             qry.Arguments = new object[] {1, "John Doe", 1, 4000};
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
 
             qry.Arguments = new object[] {2, "Jane Roe", 1, 5000};
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
 
             qry.Arguments = new object[] {3, "Mary Major", 2, 2000};
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
 
             qry.Arguments = new object[] {4, "Richard Miles", 2, 3000};
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
         }
 
         /// <summary>
@@ -145,7 +145,7 @@ namespace Apache.Ignite.Examples.Datagrid
         {
             var qry = new SqlFieldsQuery("update Employee set salary = salary * 1.1 where organizationId = ?", 1);
 
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
         }
 
         /// <summary>
@@ -159,7 +159,7 @@ namespace Apache.Ignite.Examples.Datagrid
                 "select emp._key from Employee emp, \"{0}\".Organization org " +
                 "where org.Name != ? and org._key = emp.organizationId)", OrganizationCacheName), "ASF");
 
-            employeeCache.QueryFields(qry);
+            employeeCache.Query(qry);
         }
     }
 }
index 98f9f50..23736ea 100644 (file)
@@ -18,7 +18,6 @@
 namespace Apache.Ignite.Examples.Datagrid
 {
     using System;
-    using System.Collections;
     using Apache.Ignite.Core;
     using Apache.Ignite.Core.Cache;
     using Apache.Ignite.Core.Cache.Affinity;
@@ -182,12 +181,12 @@ namespace Apache.Ignite.Examples.Datagrid
         /// <param name="cache">Cache.</param>
         private static void SqlFieldsQueryExample(ICache<int, Employee> cache)
         {
-            var qry = cache.QueryFields(new SqlFieldsQuery("select name, salary from Employee"));
+            var qry = cache.Query(new SqlFieldsQuery("select name, salary from Employee"));
 
             Console.WriteLine();
             Console.WriteLine(">>> Employee names and their salaries:");
 
-            foreach (IList row in qry)
+            foreach (var row in qry)
                 Console.WriteLine(">>>     [Name=" + row[0] + ", salary=" + row[1] + ']');
         }
 
index 1fb2e90..1fe6a74 100644 (file)
@@ -139,7 +139,7 @@ namespace Apache.Ignite.Examples
         /// <param name="cache">Cache.</param>
         private static void SqlFieldsQueryExample(ICache<int, Employee> cache)
         {
-            var qry = cache.QueryFields(new SqlFieldsQuery("select name, salary from Employee"));
+            var qry = cache.Query(new SqlFieldsQuery("select name, salary from Employee"));
 
             Console.WriteLine();
             Console.WriteLine(">>> Employee names and their salaries:");