github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/mysql_compatibility.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package plan 16 17 import "github.com/matrixorigin/matrixone/pkg/pb/plan" 18 19 func (builder *QueryBuilder) wrapBareColRefsInAnyValue(expr *plan.Expr, ctx *BindContext) *plan.Expr { 20 switch exprImpl := expr.Expr.(type) { 21 case *plan.Expr_Col: 22 if exprImpl.Col.RelPos == ctx.groupTag || exprImpl.Col.RelPos == ctx.aggregateTag { 23 return expr 24 } 25 newExpr, _ := BindFuncExprImplByPlanExpr(builder.compCtx.GetContext(), "any_value", []*plan.Expr{expr}) 26 colPos := len(ctx.aggregates) 27 ctx.aggregates = append(ctx.aggregates, newExpr) 28 return &plan.Expr{ 29 Typ: ctx.aggregates[colPos].Typ, 30 Expr: &plan.Expr_Col{ 31 Col: &plan.ColRef{ 32 RelPos: ctx.aggregateTag, 33 ColPos: int32(colPos), 34 }, 35 }, 36 } 37 38 case *plan.Expr_F: 39 for i, arg := range exprImpl.F.Args { 40 exprImpl.F.Args[i] = builder.wrapBareColRefsInAnyValue(arg, ctx) 41 } 42 return expr 43 44 default: 45 return expr 46 } 47 }