protected override void VisitSingleRowSubselect(BoundSingleRowSubselect node) { var output = node.Relation.GetOutputValues().Single(); ValueSlots.Add(output); base.VisitSingleRowSubselect(node); }
protected override BoundExpression RewriteSingleRowSubselect(BoundSingleRowSubselect node) { var input = RewriteRelation(node.Relation); var valueSlot = RewriteValueSlot(node.Value); return(node.Update(valueSlot, input)); }
protected override BoundExpression RewriteSingleRowSubselect(BoundSingleRowSubselect node) { var relation = RewriteRelation(node.Relation); var factory = node.Value.Factory; // TODO: If the query is guranteed to return a single, e.g. if it is a aggregated but not grouped, // we should not emit the additional aggregation and assertion. // 1. We need to know whether it returns more then one row. var valueSlot = node.Value; var anyOutput = factory.CreateTemporary(valueSlot.Type); var countOutput = factory.CreateTemporary(typeof(int)); var anyAggregateSymbol = BuiltInAggregates.Any; var anyAggregatable = anyAggregateSymbol.Definition.CreateAggregatable(valueSlot.Type); var countAggregatedSymbol = BuiltInAggregates.Count; var countAggregatable = countAggregatedSymbol.Definition.CreateAggregatable(typeof(int)); var aggregates = new[] { new BoundAggregatedValue(anyOutput, anyAggregateSymbol, anyAggregatable, Expression.Value(valueSlot)), new BoundAggregatedValue(countOutput, countAggregatedSymbol, countAggregatable, Expression.Literal(0)) }; var aggregation = new BoundGroupByAndAggregationRelation(relation, Enumerable.Empty <BoundComparedValue>(), aggregates); // 2. Now we can assert that the number of rows returned is at most one. var condition = Expression.LessThan(Expression.Value(countOutput), Expression.Literal(1)); var message = Resources.SubqueryReturnedMoreThanRow; var assertRelation = new BoundAssertRelation(aggregation, condition, message); var subquery = new Subquery(SubqueryKind.Subselect, anyOutput, assertRelation, CurrentPassthru); var subqueries = _subqueryStack.Peek(); subqueries.Add(subquery); return(Expression.Value(anyOutput)); }
protected override BoundExpression RewriteSingleRowSubselect(BoundSingleRowSubselect node) { _recorder.Record(node.Value); return(base.RewriteSingleRowSubselect(node)); }
protected override void VisitSingleRowSubselect(BoundSingleRowSubselect node) { SubqueryFound = true; }