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

Function NormalizeExpectedRow

testing/go/framework.go:567–637  ·  view source on GitHub ↗

NormalizeExpectedRow normalizes each value's type, as the tests only want to compare values. Returns a new row.

(fds []pgconn.FieldDescription, rows []sql.Row)

Source from the content-addressed store, hash-verified

565
566// NormalizeExpectedRow normalizes each value's type, as the tests only want to compare values. Returns a new row.
567func NormalizeExpectedRow(fds []pgconn.FieldDescription, rows []sql.Row) []sql.Row {
568 newRows := make([]sql.Row, len(rows))
569 for ri, row := range rows {
570 if len(row) == 0 {
571 newRows[ri] = nil
572 } else if len(row) != len(fds) {
573 // Return if the expected row count does not match the field description count, we'll error elsewhere
574 return rows
575 } else {
576 newRow := make(sql.Row, len(row))
577 for i := range row {
578 dt, ok := types.IDToBuiltInDoltgresType[id.Type(id.Cache().ToInternal(fds[i].DataTypeOID))]
579 if !ok {
580 // try using text type
581 dt = types.Text
582 }
583 if dt.ID == types.Json.ID && row[i] != nil {
584 newRow[i] = UnmarshalAndMarshalJsonString(row[i].(string))
585 } else if dt.IsArrayType() && dt.ArrayBaseType().ID == types.Json.ID {
586 v, err := dt.IoInput(nil, row[i].(string))
587 if err != nil {
588 panic(err)
589 }
590 arr := v.([]any)
591 newArr := make([]any, len(arr))
592 for j, el := range arr {
593 switch e := el.(type) {
594 case string:
595 newArr[j] = UnmarshalAndMarshalJsonString(e)
596 case sql.JSONWrapper:
597 iface, err := e.ToInterface(context.Background())
598 if err != nil {
599 panic(err)
600 }
601 b, err := json.Marshal(iface)
602 if err != nil {
603 panic(err)
604 }
605 newArr[j] = string(b)
606 default:
607 newArr[j] = el
608 }
609 }
610 ret, err := dt.FormatValue(newArr)
611 if err != nil {
612 panic(err)
613 }
614 newRow[i] = ret
615 } else if dt.ID == types.Date.ID {
616 newRow[i] = row[i]
617 if row[i] != nil {
618 if t, _, err := pgtree.ParseDTimestampTZ(nil, row[i].(string), pgtree.TimeFamilyPrecisionToRoundDuration(6), time.UTC); err == nil {
619 newRow[i] = functions.FormatDateTimeWithBC(t.Time.UTC(), "2006-01-02", dt.ID == types.TimestampTZ.ID)
620 }
621 }
622 } else if dt.ID == types.Timestamp.ID || dt.ID == types.TimestampTZ.ID {
623 newRow[i] = row[i]
624 if row[i] != nil {

Callers 4

runReplicationScriptFunction · 0.85
runScriptFunction · 0.85
RunScriptNFunction · 0.85
TestSSLFunction · 0.85

Calls 11

TypeTypeAlias · 0.92
CacheFunction · 0.92
FormatDateTimeWithBCFunction · 0.92
NormalizeIntsAndFloatsFunction · 0.85
ToInternalMethod · 0.80
IsArrayTypeMethod · 0.80
ArrayBaseTypeMethod · 0.80
IoInputMethod · 0.80
FormatValueMethod · 0.80
MarshalMethod · 0.45

Tested by 3

runReplicationScriptFunction · 0.68
RunScriptNFunction · 0.68
TestSSLFunction · 0.68