@@ -273,7 +273,11 @@ func call(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack) (
273273 if err != nil {
274274 return nil , err
275275 }
276- stack .BufferReturnQueryResults (convertRowsToRecords (schema , rows ))
276+ records , err := convertRowsToRecords (schema , rows )
277+ if err != nil {
278+ return nil , err
279+ }
280+ stack .BufferReturnQueryResults (records )
277281
278282 case OpCode_ScopeBegin :
279283 stack .PushScope ()
@@ -292,15 +296,26 @@ func call(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack) (
292296
293297// convertRowsToRecords iterates overs |rows| and converts each field in each row
294298// into a RecordValue. |schema| is specified for type information.
295- func convertRowsToRecords (schema sql.Schema , rows []sql.Row ) [][]pgtypes.RecordValue {
299+ func convertRowsToRecords (schema sql.Schema , rows []sql.Row ) ( [][]pgtypes.RecordValue , error ) {
296300 records := make ([][]pgtypes.RecordValue , 0 , len (rows ))
297301 for _ , row := range rows {
298302 record := make ([]pgtypes.RecordValue , len (row ))
299303 for i , field := range row {
300304 t := schema [i ].Type
301305 doltgresType , ok := t .(* pgtypes.DoltgresType )
302306 if ! ok {
303- panic ("expected Doltgres type" )
307+ // non-Doltgres types are still used in analysis, but we only support disk serialization
308+ // for Doltgres types, so we must convert the GMS type to the nearest Doltgres type here.
309+ // TODO: this conversion isn't fully accurate. expression.GMSCast has additional logic in
310+ // its Eval() method to handle types more exactly and also handles converting the
311+ // value to ensure it is well formed for the returned DoltgresType. We can't
312+ // currently use GMSCast directly here though, because of a dependency cycle, so
313+ // that conversion logic needs to be extracted into a package both places can import.
314+ var err error
315+ doltgresType , err = pgtypes .FromGmsTypeToDoltgresType (t )
316+ if err != nil {
317+ return nil , err
318+ }
304319 }
305320
306321 record [i ] = pgtypes.RecordValue {
@@ -311,7 +326,7 @@ func convertRowsToRecords(schema sql.Schema, rows []sql.Row) [][]pgtypes.RecordV
311326 records = append (records , record )
312327 }
313328
314- return records
329+ return records , nil
315330}
316331
317332// applyNoticeOptions adds the specified |options| to the |noticeResponse|.
0 commit comments