Skip to content

Commit

Permalink
Throw exceptions for rare situations
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-er committed Dec 12, 2021
1 parent 77cfd5c commit 34d5e59
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions src/Relational/Reduce/SelfJoinsPruningExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ protected virtual void RemoveJoin(SelectExpression parentSelect, PredicateJoinEx

if (join is InnerJoinExpression && join.Table is SelectExpression reducedSelect)
{
throw new NotImplementedException(
$"This is a rare situation in {nameof(SelfJoinsPruningExpressionVisitor)}.{nameof(RemoveJoin)} -> innerJoinSelect. " +
$"Please report to the plugin author and provide some samples to make unit tests.");

/*
var predicate1 = _columnRewriting.Visit(parentSelect.Predicate);
var predicate2 = _columnRewriting.Visit(reducedSelect.Predicate);
var predicate = MergePredicate(ExpressionType.AndAlso, predicate1, predicate2);
parentSelect.SetPredicate(predicate);
*/
}

parentSelect.RemoveTableAt(pendingRemovalIndex);
Expand Down Expand Up @@ -175,27 +181,19 @@ protected override Expression VisitSelect(SelectExpression selectExpression)
}
else if (newTables[i] is JoinExpressionBase joinNew && selectTables[i] is JoinExpressionBase joinOld)
{
throw new NotImplementedException(
$"This is a rare situation in {nameof(SelfJoinsPruningExpressionVisitor)}.{nameof(VisitSelect)} -> joinNew & joinOld. " +
$"Please report to the plugin author and provide some samples to make unit tests.");

/*
if (joinNew.Table != joinOld.Table)
{
#if EFCORE31 || EFCORE50
using (_columnRewriting.Setup(joinOld.Table, joinNew.Table))
{
UpdateParent();
}
#elif EFCORE60
if (joinNew.Alias != joinOld.Alias)
{
using (_columnRewriting.Setup(joinOld.Table, joinNew.Table))
{
UpdateParent();
}
}
else
{
selectTables[i] = joinNew;
}
#endif
}
*/
}
else
{
Expand All @@ -204,7 +202,9 @@ protected override Expression VisitSelect(SelectExpression selectExpression)

((List<TableExpressionBase>)selectExpression.Tables)[i] = resulting;

#pragma warning disable CS8321
void UpdateParent()
#pragma warning restore CS8321
{
selectExpression.SetPredicate(_columnRewriting.Visit(selectExpression.Predicate));
selectExpression.SetHaving(_columnRewriting.Visit(selectExpression.Having));
Expand Down Expand Up @@ -238,6 +238,11 @@ void UpdateParent()
var newTable = (TableExpressionBase)Visit(join.Table);
if (newTable != join.Table)
{
throw new NotImplementedException(
$"This is a rare situation in {nameof(SelfJoinsPruningExpressionVisitor)}.{nameof(VisitSelect)} -> visitNewJoin. " +
$"Please report to the plugin author and provide some samples to make unit tests.");

/*
if (newTable is not SelectExpression newSelect)
{
throw new NotImplementedException();
Expand All @@ -261,6 +266,7 @@ void UpdateParent()
selectTables[selectTables.IndexOf(join)] = newJoin;
join = newJoin;
*/
}

if (!_comparer.Compare(pendingTable, join))
Expand Down Expand Up @@ -384,13 +390,20 @@ bool SameSelectFields(SelectExpression select1, SelectExpression select2, TableE
protected override Expression VisitInnerJoin(InnerJoinExpression innerJoinExpression)
{
var result = (InnerJoinExpression)base.VisitInnerJoin(innerJoinExpression);
if (result.Table == innerJoinExpression.Table) return result;
if (result.Table != innerJoinExpression.Table)
{
throw new NotImplementedException(
$"This is a rare situation in {nameof(SelfJoinsPruningExpressionVisitor)}.{nameof(VisitInnerJoin)}. " +
$"Please report to the plugin author and provide some samples to make unit tests.");

if (result.Table.Alias == null) result.Table.SetAlias(innerJoinExpression.Table.Alias);
/*
if (result.Table.Alias == null) result.Table.SetAlias(innerJoinExpression.Table.Alias);
using (_columnRewriting.Setup(innerJoinExpression.Table, result.Table))
{
result = result.Update(result.Table, _columnRewriting.Visit(result.JoinPredicate));
using (_columnRewriting.Setup(innerJoinExpression.Table, result.Table))
{
result = result.Update(result.Table, _columnRewriting.Visit(result.JoinPredicate));
}
*/
}

return result;
Expand All @@ -399,13 +412,20 @@ protected override Expression VisitInnerJoin(InnerJoinExpression innerJoinExpres
protected override Expression VisitLeftJoin(LeftJoinExpression leftJoinExpression)
{
var result = (LeftJoinExpression)base.VisitLeftJoin(leftJoinExpression);
if (result.Table == leftJoinExpression.Table) return result;
if (result.Table != leftJoinExpression.Table)
{
throw new NotImplementedException(
$"This is a rare situation in {nameof(SelfJoinsPruningExpressionVisitor)}.{nameof(VisitLeftJoin)}. " +
$"Please report to the plugin author and provide some samples to make unit tests.");

if (result.Table.Alias == null) result.Table.SetAlias(leftJoinExpression.Table.Alias);
/*
if (result.Table.Alias == null) result.Table.SetAlias(leftJoinExpression.Table.Alias);
using (_columnRewriting.Setup(leftJoinExpression.Table, result.Table))
{
result = result.Update(result.Table, _columnRewriting.Visit(result.JoinPredicate));
using (_columnRewriting.Setup(leftJoinExpression.Table, result.Table))
{
result = result.Update(result.Table, _columnRewriting.Visit(result.JoinPredicate));
}
*/
}

return result;
Expand Down

0 comments on commit 34d5e59

Please sign in to comment.