Function implements the interface sql.FunctionProvider.
(ctx *sql.Context, schema, name string)
| 31 | |
| 32 | // Function implements the interface sql.FunctionProvider. |
| 33 | func (fp *FunctionProvider) Function(ctx *sql.Context, schema, name string) (sql.Function, bool) { |
| 34 | // TODO: this should be configurable from within Dolt, rather than set on an external variable |
| 35 | if !core.IsContextValid(ctx) { |
| 36 | return nil, false |
| 37 | } |
| 38 | funcCollection, err := core.GetFunctionsCollectionFromContext(ctx, "") |
| 39 | if err != nil { |
| 40 | return nil, false |
| 41 | } |
| 42 | typesCollection, err := core.GetTypesCollectionFromContext(ctx, "") |
| 43 | if err != nil { |
| 44 | return nil, false |
| 45 | } |
| 46 | // TODO: this should search all schemas in the search path, but the search path doesn't handle pg_catalog yet |
| 47 | funcName := id.NewFunction("pg_catalog", name) |
| 48 | overloads, err := funcCollection.GetFunctionOverloads(ctx, funcName) |
| 49 | if err != nil { |
| 50 | return nil, false |
| 51 | } |
| 52 | if len(overloads) == 0 { |
| 53 | if schema == "" { |
| 54 | currentSchema, err := core.GetCurrentSchema(ctx) |
| 55 | if err != nil { |
| 56 | return nil, false |
| 57 | } |
| 58 | schema = currentSchema |
| 59 | } |
| 60 | funcName = id.NewFunction(schema, name) |
| 61 | overloads, err = funcCollection.GetFunctionOverloads(ctx, funcName) |
| 62 | if err != nil { |
| 63 | return nil, false |
| 64 | } |
| 65 | if len(overloads) == 0 { |
| 66 | return nil, false |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | overloadTree := NewOverloads() |
| 71 | for _, overload := range overloads { |
| 72 | returnType, err := typesCollection.GetType(ctx, overload.ReturnType) |
| 73 | if err != nil || returnType == nil { |
| 74 | return nil, false |
| 75 | } |
| 76 | |
| 77 | paramTypes := make([]*pgtypes.DoltgresType, len(overload.ParameterTypes)) |
| 78 | for i, paramType := range overload.ParameterTypes { |
| 79 | paramTypes[i], err = typesCollection.GetType(ctx, paramType) |
| 80 | if err != nil || paramTypes[i] == nil { |
| 81 | return nil, false |
| 82 | } |
| 83 | } |
| 84 | if len(overload.ExtensionName) > 0 { |
| 85 | if err = overloadTree.Add(CFunction{ |
| 86 | ID: overload.ID, |
| 87 | ReturnType: returnType, |
| 88 | ParameterTypes: paramTypes, |
| 89 | Variadic: overload.Variadic, |
| 90 | IsNonDeterministic: overload.IsNonDeterministic, |
nothing calls this directly
no test coverage detected