Skip to content

Commit 015bbfa

Browse files
committed
internal/rule: don't throw error on squashing projects
Signed-off-by: Manuel Carmona <[email protected]>
1 parent 8d7298a commit 015bbfa

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

internal/rule/squashjoins.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func SquashJoins(
7575
return n, nil
7676
}
7777

78-
squashedProject, err := squashProjects(project, child)
79-
if err != nil {
80-
return nil, err
78+
squashedProject, ok := squashProjects(project, child)
79+
if !ok {
80+
return n, nil
8181
}
8282

8383
projectSquashes--
@@ -100,22 +100,19 @@ func countProjectSquashes(n sql.Node) int {
100100
return squashableProjects - 1
101101
}
102102

103-
// ErrWrongProjection is raised if a plan.Project node contains a wrong expression.
104-
var ErrWrongProjection = errors.NewKind("wrong expression found in project node %s")
105-
106-
func squashProjects(parent, child *plan.Project) (sql.Node, error) {
103+
func squashProjects(parent, child *plan.Project) (sql.Node, bool) {
107104
projections := []sql.Expression{}
108105
for _, expr := range parent.Expressions() {
109106
parentField, ok := expr.(*expression.GetField)
110107
if !ok {
111-
return nil, ErrWrongProjection.New(parent.String())
108+
return nil, false
112109
}
113110

114111
index := parentField.Index()
115112
for _, e := range child.Expressions() {
116113
childField, ok := e.(*expression.GetField)
117114
if !ok {
118-
return nil, ErrWrongProjection.New(child.String())
115+
return nil, false
119116
}
120117

121118
if referenceSameColumn(parentField, childField) {
@@ -134,7 +131,7 @@ func squashProjects(parent, child *plan.Project) (sql.Node, error) {
134131
projections = append(projections, projection)
135132
}
136133

137-
return plan.NewProject(projections, child.Child), nil
134+
return plan.NewProject(projections, child.Child), true
138135
}
139136

140137
func referenceSameColumn(parent, child *expression.GetField) bool {

0 commit comments

Comments
 (0)