MCPcopy Create free account
hub / github.com/dolthub/doltgresql / getTargetType

Method getTargetType

server/expression/array.go:172–202  ·  view source on GitHub ↗

getTargetType returns the evaluated type for this expression. Returns the "anyarray" type if the type combination is invalid.

(ctx *sql.Context, children ...sql.Expression)

Source from the content-addressed store, hash-verified

170// getTargetType returns the evaluated type for this expression.
171// Returns the "anyarray" type if the type combination is invalid.
172func (array *Array) getTargetType(ctx *sql.Context, children ...sql.Expression) (*pgtypes.DoltgresType, error) {
173 var childrenTypes []*pgtypes.DoltgresType
174 for _, child := range children {
175 if child != nil {
176 childType, ok := child.Type(ctx).(*pgtypes.DoltgresType)
177 if !ok {
178 // We use "anyarray" as the indeterminate/invalid type
179 return pgtypes.AnyArray, nil
180 }
181 childrenTypes = append(childrenTypes, childType)
182 }
183 }
184 targetType, _, err := framework.FindCommonType(ctx, childrenTypes)
185 if err != nil {
186 return nil, errors.Errorf("ARRAY %s", err.Error())
187 }
188 // If the common type is unresolved (e.g. a user-defined composite type seen before the analyzer runs),
189 // look it up from the type collection so that ToArrayType can find the array type ID.
190 if !targetType.IsResolvedType() {
191 schemaName := targetType.ID.SchemaName()
192 if schemaName == "" {
193 schemaName, _ = core.GetCurrentSchema(ctx)
194 }
195 if typeColl, tcErr := core.GetTypesCollectionFromContext(ctx, ""); tcErr == nil && typeColl != nil {
196 if resolved, rErr := typeColl.GetType(ctx, id.NewType(schemaName, targetType.ID.TypeName())); rErr == nil && resolved != nil {
197 targetType = resolved
198 }
199 }
200 }
201 return targetType.ToArrayType(), nil
202}

Callers 1

WithChildrenMethod · 0.95

Calls 12

FindCommonTypeFunction · 0.92
GetCurrentSchemaFunction · 0.92
NewTypeFunction · 0.92
IsResolvedTypeMethod · 0.80
TypeNameMethod · 0.80
ToArrayTypeMethod · 0.80
TypeMethod · 0.65
ErrorfMethod · 0.65
GetTypeMethod · 0.65
ErrorMethod · 0.45
SchemaNameMethod · 0.45

Tested by

no test coverage detected