Skip to content

Commit c5d3dfd

Browse files
committed
ad guardrails when infer parameter names from column references when ref.name is empty.
1 parent b634f95 commit c5d3dfd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

internal/compiler/resolve.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,22 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
157157
if funcCallSide != nil {
158158
fun, ferr := c.ResolveFuncCall(funcCallSide)
159159
if ferr == nil && fun.ReturnType != nil && !strings.HasPrefix(fun.ReturnType.Name, "any") && fun.ReturnType.Name != "record" {
160-
defaultP := named.NewInferredParam(ref.name, true)
160+
paramName := ref.name
161+
if paramName == "" {
162+
fcList := astutils.Search(funcCallSide, func(node ast.Node) bool {
163+
_, ok := node.(*ast.ColumnRef)
164+
return ok
165+
})
166+
if len(fcList.Items) > 0 {
167+
if cr, ok := fcList.Items[0].(*ast.ColumnRef); ok {
168+
items := stringSlice(cr.Fields)
169+
if len(items) > 0 {
170+
paramName = items[len(items)-1]
171+
}
172+
}
173+
}
174+
}
175+
defaultP := named.NewInferredParam(paramName, true)
161176
p, isNamed := params.FetchMerge(ref.ref.Number, defaultP)
162177
a = append(a, Parameter{
163178
Number: ref.ref.Number,

0 commit comments

Comments
 (0)