internal override SqlExpression VisitMultiset(SqlSubSelect sms)
        {
            // allow one big-join per query?
            if ((this.options & SqlMultiplexerOptionType.EnableBigJoin) != 0 &&
                !this.hasBigJoin && this.canJoin && this.isTopLevel && this.outerSelect != null &&
                !MultisetChecker.HasMultiset(sms.Select.Selection) &&
                BigJoinChecker.CanBigJoin(sms.Select))
            {
                sms.Select = this.VisitSelect(sms.Select);

                SqlAlias alias = new SqlAlias(sms.Select);
                SqlJoin  join  = new SqlJoin(SqlJoinType.OuterApply, this.outerSelect.From, alias, null, sms.SourceExpression);
                this.outerSelect.From         = @join;
                this.outerSelect.OrderingType = SqlOrderingType.Always;

                // make joined expression
                SqlExpression expr = (SqlExpression)SqlDuplicator.Copy(sms.Select.Selection);

                // make count expression
                SqlSelect copySelect  = (SqlSelect)SqlDuplicator.Copy(sms.Select);
                SqlAlias  copyAlias   = new SqlAlias(copySelect);
                SqlSelect countSelect = new SqlSelect(sql.Unary(SqlNodeType.Count, null, sms.SourceExpression), copyAlias, sms.SourceExpression);
                countSelect.OrderingType = SqlOrderingType.Never;
                SqlExpression count = sql.SubSelect(SqlNodeType.ScalarSubSelect, countSelect);

                // make joined collection
                SqlJoinedCollection jc = new SqlJoinedCollection(sms.ClrType, sms.SqlType, expr, count, sms.SourceExpression);
                this.hasBigJoin = true;
                return(jc);
            }
            return(QueryExtractor.Extract(sms, this.parentParameters));
        }
Ejemplo n.º 2
0
        public void HappyPath()
        {
            var context = NewContextWithDefaults(
                new TypeHierarchy
            {
                Element = DefaultClassContext
            },
                new MethodHierarchy
            {
                Element = DefaultMethodContext
            },
                VarDecl("A", "a"),
                InvokeStmt("a", Method("R", "A", "M")),
                Completion("a")
                );

            var actual   = _sut.Extract(context);
            var expected = new Query
            {
                type       = Type("A").ToCoReName(),
                classCtx   = DefaultClassContext.ToCoReName(),
                methodCtx  = DefaultMethodContext.ToCoReName(),
                definition = DefinitionSites.CreateUnknownDefinitionSite(),
                sites      =
                {
                    CallSites.CreateReceiverCallSite(Method("R", "A", "M"))
                }
            };

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        protected override bool AddLookupItems(CSharpCodeCompletionContext context, GroupedItemsCollector collector)
        {
            Action <Context> onSuccess = kaveContext =>
            {
                // TODO NameUpdate: untested addition (try/catch)
                try
                {
                    _currentQuery = _queryGen.Extract(kaveContext);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "error while extracting query");
                    _currentQuery = null;
                }

                if (_currentQuery != null && IsAvailable())
                {
                    var rec = LoadIfAvailable();
                    if (rec != null)
                    {
                        try
                        {
                            var proposals = rec.Query(_currentQuery);

                            WrapExistingItems(collector, proposals);
                            WrapNewItems(collector, proposals);
                        }
                        catch (AssertException e)
                        {
                            _logger.Error(e);
                        }
                    }
                    else
                    {
                        _logger.Info("no recommender model found for {0}", _currentQuery.type);
                    }
                }
            };

            ContextAnalysis.Analyse(
                context.NodeInFile,
                null,
                _logger,
                onSuccess,
                delegate { },
                delegate { });

            return(base.AddLookupItems(context, collector));
        }
 private Query GetQuery(Context ctx)
 {
     try
     {
         return(_queryExtractor.Extract(ctx) ?? new Query());
     }
     catch (AssertException ae)
     {
         // happens for anonymized names, for now, I just ignore these contexts
         _errorMessages.Add(ae.Message);
         return(new Query());
     }
     catch (Exception e)
     {
         _logger.Error(e);
         return(new Query());
     }
 }
 internal override SqlExpression VisitElement(SqlSubSelect elem)
 {
     return(QueryExtractor.Extract(elem, this.parentParameters));
 }