MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / prettyPrintFirstValue

Function prettyPrintFirstValue

pkg/util/encoding/encoding.go:1507–1653  ·  view source on GitHub ↗

prettyPrintFirstValue returns a string representation of the first decodable value in the provided byte slice, along with the remaining byte slice after decoding. Ascending will be the default direction (when dir is the 0 value) for all values except for NotNull. NotNull: if Ascending or Descendin

(dir Direction, b []byte)

Source from the content-addressed store, hash-verified

1505// are always encoded Ascending), this will always print out the correct key
1506// even if we don't have directions for the child index's columns.
1507func prettyPrintFirstValue(dir Direction, b []byte) ([]byte, string, error) {
1508 var err error
1509 switch PeekType(b) {
1510 case Null:
1511 b, _ = DecodeIfNull(b)
1512 return b, "NULL", nil
1513 case True:
1514 return b[1:], "True", nil
1515 case False:
1516 return b[1:], "False", nil
1517 case Array:
1518 return b[1:], "Arr", nil
1519 case NotNull:
1520 // The tag can be either encodedNotNull or encodedNotNullDesc. The
1521 // latter can be an interleaved sentinel.
1522 isNotNullDesc := (b[0] == encodedNotNullDesc)
1523 b, _ = DecodeIfNotNull(b)
1524 if dir != Ascending && dir != Descending && isNotNullDesc {
1525 // Unspecified direction (0 value) will default to '#' for the
1526 // interleaved sentinel.
1527 return b, "#", nil
1528 }
1529 return b, "!NULL", nil
1530 case Int:
1531 var i int64
1532 if dir == Descending {
1533 b, i, err = DecodeVarintDescending(b)
1534 } else {
1535 b, i, err = DecodeVarintAscending(b)
1536 }
1537 if err != nil {
1538 return b, "", err
1539 }
1540 return b, strconv.FormatInt(i, 10), nil
1541 case Float:
1542 var f float64
1543 if dir == Descending {
1544 b, f, err = DecodeFloatDescending(b)
1545 } else {
1546 b, f, err = DecodeFloatAscending(b)
1547 }
1548 if err != nil {
1549 return b, "", err
1550 }
1551 return b, strconv.FormatFloat(f, 'g', -1, 64), nil
1552 case Decimal:
1553 var d apd.Decimal
1554 if dir == Descending {
1555 b, d, err = DecodeDecimalDescending(b, nil)
1556 } else {
1557 b, d, err = DecodeDecimalAscending(b, nil)
1558 }
1559 if err != nil {
1560 return b, "", err
1561 }
1562 return b, d.String(), nil
1563 case BitArray:
1564 if dir == Descending {

Callers 1

prettyPrintValueImplFunction · 0.85

Calls 15

StringMethod · 0.95
StringMethod · 0.95
StringNanosMethod · 0.95
PeekTypeFunction · 0.85
DecodeIfNullFunction · 0.85
DecodeIfNotNullFunction · 0.85
DecodeVarintDescendingFunction · 0.85
DecodeVarintAscendingFunction · 0.85
DecodeFloatDescendingFunction · 0.85
DecodeFloatAscendingFunction · 0.85
DecodeDecimalDescendingFunction · 0.85
DecodeDecimalAscendingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…