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)
| 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. |
| 1507 | func 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 { |
no test coverage detected
searching dependent graphs…