You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2016/08/26 09:16:36 UTC

[32/50] ignite git commit: Merge remote-tracking branch 'remotes/community/ignite-1.6.6' into ignite-1.7.2

Merge remote-tracking branch 'remotes/community/ignite-1.6.6' into ignite-1.7.2

# Conflicts:
#	modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e4344fa8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e4344fa8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e4344fa8

Branch: refs/heads/ignite-3443
Commit: e4344fa811c78d78d3a829ba2cf2c916a05e0ef7
Parents: 8d5b6ba d603371
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Tue Aug 23 14:15:32 2016 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Tue Aug 23 14:15:32 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  |   9 +-
 .../continuous/CacheContinuousQueryManager.java |   2 +-
 .../internal/processors/igfs/IgfsImpl.java      |   6 +-
 .../MarshallerContextLockingSelfTest.java       | 139 ++++++++++
 ...eDynamicCacheStartNoExchangeTimeoutTest.java |   2 +
 .../processors/igfs/IgfsAbstractSelfTest.java   |   4 +-
 .../ignite/testsuites/IgniteBasicTestSuite.java |   3 +
 .../Cache/Query/CacheLinqTest.cs                | 196 +++++++++++++-
 .../Apache.Ignite.Linq.csproj                   |   2 +-
 .../dotnet/Apache.Ignite.Linq/CompiledQuery.cs  |   1 +
 .../dotnet/Apache.Ignite.Linq/CompiledQuery2.cs | 257 +++++++++++++++++++
 .../Impl/CacheFieldsQueryExecutor.cs            | 132 ++++++++--
 .../Impl/CacheQueryExpressionVisitor.cs         |  15 ++
 .../Impl/CacheQueryModelVisitor.cs              |  15 +-
 .../Impl/CacheQueryableBase.cs                  |  22 ++
 .../Apache.Ignite.Linq/Impl/ExpressionWalker.cs |   9 +
 .../Apache.Ignite.Linq/Impl/ICacheQueryProxy.cs |  40 ---
 .../Impl/ICacheQueryableInternal.cs             |  14 +-
 .../ignite/schema/generator/CodeGenerator.java  |  16 +-
 19 files changed, 795 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs
----------------------------------------------------------------------
diff --cc modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs
index 7464a03,b4c3292..3d48f41
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryExecutor.cs
@@@ -60,11 -51,7 +60,11 @@@ namespace Apache.Ignite.Linq.Imp
          /// </summary>
          /// <param name="cache">The executor function.</param>
          /// <param name="local">Local flag.</param>
 -        public CacheFieldsQueryExecutor(ICacheInternal cache, bool local)
 +        /// <param name="pageSize">Size of the page.</param>
 +        /// <param name="enableDistributedJoins">Distributed joins flag.</param>
 +        /// <param name="enforceJoinOrder">Enforce join order flag.</param>
-         public CacheFieldsQueryExecutor(ICacheInternal cache, bool local, int pageSize, bool enableDistributedJoins, 
++        public CacheFieldsQueryExecutor(ICacheInternal cache, bool local, int pageSize, bool enableDistributedJoins,
 +            bool enforceJoinOrder)
          {
              Debug.Assert(cache != null);
  
@@@ -177,21 -132,119 +172,124 @@@
  
              // Check if user param order is already correct
              if (indices.SequenceEqual(Enumerable.Range(0, indices.Length)))
-                 return args => _cache.QueryFields(new SqlFieldsQuery(qryText, _local, args)
-                 {
-                     EnableDistributedJoins = _enableDistributedJoins,
-                     PageSize = _pageSize,
-                     EnforceJoinOrder = _enforceJoinOrder
-                 }, selector);
+                 return args => _cache.QueryFields(GetFieldsQuery(qryText, args), selector);
  
              // Return delegate with reorder
-             return args => _cache.QueryFields(new SqlFieldsQuery(qryText, _local,
-                 args.Select((x, i) => args[indices[i]]).ToArray())
+             return args => _cache.QueryFields(GetFieldsQuery(qryText,
+                 args.Select((x, i) => args[indices[i]]).ToArray()), selector);
+         }
+         /// <summary>
+         /// Compiles the query without regard to number or order of arguments.
+         /// </summary>
+         public Func<object[], IQueryCursor<T>> CompileQuery<T>(QueryModel queryModel)
+         {
+             Debug.Assert(queryModel != null);
+ 
+             var qryText = GetQueryData(queryModel).QueryText;
+             var selector = GetResultSelector<T>(queryModel.SelectClause.Selector);
+ 
+             return args => _cache.QueryFields(GetFieldsQuery(qryText, args), selector);
+         }
+ 
+         /// <summary>
+         /// Compiles the query.
+         /// </summary>
+         /// <typeparam name="T">Result type.</typeparam>
+         /// <param name="queryModel">The query model.</param>
+         /// <param name="queryLambdaModel">The query model generated from lambda body.</param>
+         /// <param name="queryLambda">The query lambda.</param>
+         /// <returns>Compiled query func.</returns>
+         public Func<object[], IQueryCursor<T>> CompileQuery<T>(QueryModel queryModel, QueryModel queryLambdaModel,
+             LambdaExpression queryLambda)
+         {
+             Debug.Assert(queryModel != null);
+ 
+             // Get model from lambda to map arguments properly.
+             var qryData = GetQueryData(queryLambdaModel);
+ 
+             var qryText = GetQueryData(queryModel).QueryText;
+             var qryTextLambda = qryData.QueryText;
+ 
+             if (qryText != qryTextLambda)
+             {
+                 Debug.WriteLine(qryText);
+                 Debug.WriteLine(qryTextLambda);
+ 
+                 throw new InvalidOperationException("Error compiling query: entire LINQ expression should be " +
+                                                     "specified within lambda passed to Compile method. " +
+                                                     "Part of the query can't be outside the Compile method call.");
+             }
+ 
+             var selector = GetResultSelector<T>(queryModel.SelectClause.Selector);
+ 
+             var qryParams = qryData.Parameters.ToArray();
+ 
+             // Compiled query is a delegate with query parameters
+             // Delegate parameters order and query parameters order may differ
+ 
+             // Simple case: lambda with no parameters. Only embedded parameters are used.
+             if (!queryLambda.Parameters.Any())
+             {
+                 return argsUnused => _cache.QueryFields(GetFieldsQuery(qryText, qryParams), selector);
+             }
+ 
+             // These are in order of usage in query
+             var qryOrderArgs = qryParams.OfType<ParameterExpression>().Select(x => x.Name).ToArray();
+ 
+             // These are in order they come from user
+             var userOrderArgs = queryLambda.Parameters.Select(x => x.Name).ToList();
+ 
+             // Simple case: all query args directly map to the lambda args in the same order
+             if (qryOrderArgs.Length == qryParams.Length
+                 && qryOrderArgs.SequenceEqual(userOrderArgs))
+             {
+                 return args => _cache.QueryFields(GetFieldsQuery(qryText, args), selector);
+             }
+ 
+             // General case: embedded args and lambda args are mixed; same args can be used multiple times.
+             // Produce a mapping that defines where query arguments come from.
+             var mapping = qryParams.Select(x =>
+             {
+                 var pe = x as ParameterExpression;
+ 
+                 if (pe != null)
+                     return userOrderArgs.IndexOf(pe.Name);
+ 
+                 return -1;
+             }).ToArray();
+ 
+             return args => _cache.QueryFields(
+                 GetFieldsQuery(qryText, MapQueryArgs(args, qryParams, mapping)), selector);
+         }
+ 
+         /// <summary>
+         /// Maps the query arguments.
+         /// </summary>
+         private static object[] MapQueryArgs(object[] userArgs, object[] embeddedArgs, int[] mapping)
+         {
+             var mappedArgs = new object[embeddedArgs.Length];
+ 
+             for (var i = 0; i < mappedArgs.Length; i++)
+             {
+                 var map = mapping[i];
+ 
+                 mappedArgs[i] = map < 0 ? embeddedArgs[i] : userArgs[map];
+             }
+ 
+             return mappedArgs;
+         }
+ 
+         /// <summary>
+         /// Gets the fields query.
+         /// </summary>
+         private SqlFieldsQuery GetFieldsQuery(string text, object[] args)
+         {
 -            return new SqlFieldsQuery(text, _local, args);
++            return new SqlFieldsQuery(text, _local, args)
 +            {
 +                EnableDistributedJoins = _enableDistributedJoins,
 +                PageSize = _pageSize,
 +                EnforceJoinOrder = _enforceJoinOrder
-             }, selector);
++            };
          }
  
          /** <inheritdoc /> */

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryExpressionVisitor.cs
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
----------------------------------------------------------------------
diff --cc modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
index a8c4c67,51297ee..ae94cfb
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
@@@ -423,21 -428,9 +427,10 @@@ namespace Apache.Ignite.Linq.Imp
              }
              else
              {
-                 var innerExpr = joinClause.InnerSequence as ConstantExpression;
- 
-                 if (innerExpr == null)
-                     throw new NotSupportedException("Unexpected JOIN inner sequence (subqueries are not supported): " +
-                                                     joinClause.InnerSequence);
- 
-                 if (!(innerExpr.Value is ICacheQueryable))
-                     throw new NotSupportedException("Unexpected JOIN inner sequence " +
-                                                     "(only results of cache.ToQueryable() are supported): " +
-                                                     innerExpr.Value);
- 
                  var queryable = ExpressionWalker.GetCacheQueryable(joinClause);
                  var tableName = ExpressionWalker.GetTableNameWithSchema(queryable);
 -                _builder.AppendFormat("inner join {0} as {1} on (", tableName, _aliases.GetTableAlias(tableName));
 +                var alias = _aliases.GetTableAlias(joinClause);
 +                _builder.AppendFormat("inner join {0} as {1} on (", tableName, alias);
              }
  
              BuildJoinCondition(joinClause.InnerKeySelector, joinClause.OuterKeySelector);

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryableBase.cs
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/e4344fa8/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/ExpressionWalker.cs
----------------------------------------------------------------------