convertRowsToRecords iterates overs |rows| and converts each field in each row into a RecordValue. |schema| is specified for type information.
(schema sql.Schema, rows []sql.Row)
| 378 | // convertRowsToRecords iterates overs |rows| and converts each field in each row |
| 379 | // into a RecordValue. |schema| is specified for type information. |
| 380 | func convertRowsToRecords(schema sql.Schema, rows []sql.Row) ([][]pgtypes.RecordValue, error) { |
| 381 | records := make([][]pgtypes.RecordValue, 0, len(rows)) |
| 382 | for _, row := range rows { |
| 383 | record := make([]pgtypes.RecordValue, len(row)) |
| 384 | for i, field := range row { |
| 385 | t := schema[i].Type |
| 386 | doltgresType, ok := t.(*pgtypes.DoltgresType) |
| 387 | if !ok { |
| 388 | // non-Doltgres types are still used in analysis, but we only support disk serialization |
| 389 | // for Doltgres types, so we must convert the GMS type to the nearest Doltgres type here. |
| 390 | // TODO: this conversion isn't fully accurate. expression.GMSCast has additional logic in |
| 391 | // its Eval() method to handle types more exactly and also handles converting the |
| 392 | // value to ensure it is well formed for the returned DoltgresType. We can't |
| 393 | // currently use GMSCast directly here though, because of a dependency cycle, so |
| 394 | // that conversion logic needs to be extracted into a package both places can import. |
| 395 | var err error |
| 396 | doltgresType, err = pgtypes.FromGmsTypeToDoltgresType(t) |
| 397 | if err != nil { |
| 398 | return nil, err |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | record[i] = pgtypes.RecordValue{ |
| 403 | Value: field, |
| 404 | Type: doltgresType, |
| 405 | } |
| 406 | } |
| 407 | records = append(records, record) |
| 408 | } |
| 409 | |
| 410 | return records, nil |
| 411 | } |
| 412 | |
| 413 | // applyNoticeOptions adds the specified |options| to the |noticeResponse|. |
| 414 | func applyNoticeOptions(ctx *sql.Context, noticeResponse *pgproto3.NoticeResponse, options map[string]string) error { |