@@ -23,7 +23,6 @@ import (
2323 "github.com/dolthub/go-mysql-server/sql/expression"
2424 vitess "github.com/dolthub/vitess/go/vt/sqlparser"
2525
26- "github.com/dolthub/doltgresql/core"
2726 "github.com/dolthub/doltgresql/server/functions/framework"
2827 pgtypes "github.com/dolthub/doltgresql/server/types"
2928)
@@ -97,53 +96,11 @@ func (c *ExplicitCast) Eval(ctx *sql.Context, row sql.Row) (any, error) {
9796 baseCastToType := checkForDomainType (c .castToType )
9897 castFunction := framework .GetExplicitCast (fromType , baseCastToType )
9998 if castFunction == nil {
100- if fromType .IsRecordType () && c .castToType .IsCompositeType () { // TODO: should this only be in explicit, or assignment and implicit too?
101- // Casting to a record type will always work for any composite type.
102- // TODO: is the above statement true for all cases?
103- // When casting to a composite type, then we must match the arity and have valid casts for every position.
104- if c .castToType .IsRecordType () {
105- castFunction = framework .IdentityCast
106- } else {
107- castFunction = func (ctx * sql.Context , val any , targetType * pgtypes.DoltgresType ) (any , error ) {
108- vals , ok := val .([]pgtypes.RecordValue )
109- if ! ok {
110- // TODO: better error message
111- return nil , errors .New ("casting input error from record type" )
112- }
113- if len (targetType .CompositeAttrs ) != len (vals ) {
114- return nil , errors .Newf ("cannot cast type %s to %s" , "" , targetType .Name ())
115- }
116- typeCollection , err := core .GetTypesCollectionFromContext (ctx )
117- if err != nil {
118- return nil , err
119- }
120- outputVals := make ([]pgtypes.RecordValue , len (vals ))
121- for i := range vals {
122- valType , ok := vals [i ].Type .(* pgtypes.DoltgresType )
123- if ! ok {
124- // TODO: if this is a GMS type, then we should cast to a Doltgres type here
125- return nil , errors .New ("cannot cast record containing GMS type" )
126- }
127- outputVals [i ].Type , err = typeCollection .GetType (ctx , targetType .CompositeAttrs [i ].TypeID )
128- if err != nil {
129- return nil , err
130- }
131- innerExplicit := ExplicitCast {
132- sqlChild : NewUnsafeLiteral (vals [i ].Value , valType ),
133- castToType : outputVals [i ].Type .(* pgtypes.DoltgresType ),
134- }
135- outputVals [i ].Value , err = innerExplicit .Eval (ctx , nil )
136- if err != nil {
137- return nil , err
138- }
139- }
140- return outputVals , nil
141- }
142- }
143- } else {
144- return nil , errors .Errorf ("EXPLICIT CAST: cast from `%s` to `%s` does not exist: %s" ,
145- fromType .String (), c .castToType .String (), c .sqlChild .String ())
146- }
99+ return nil , errors .Errorf (
100+ "EXPLICIT CAST: cast from `%s` to `%s` does not exist: %s" ,
101+ fromType .String (), c .castToType .String (), c .sqlChild .String (),
102+ )
103+
147104 }
148105 castResult , err := castFunction (ctx , val , c .castToType )
149106 if err != nil {
0 commit comments