MCPcopy Create free account
hub / github.com/PostHog/duckgres / compareValues

Function compareValues

tests/integration/compare.go:520–567  ·  view source on GitHub ↗

compareValues compares two values for sorting

(a, b interface{})

Source from the content-addressed store, hash-verified

518
519// compareValues compares two values for sorting
520func compareValues(a, b interface{}) int {
521 if a == nil && b == nil {
522 return 0
523 }
524 if a == nil {
525 return -1
526 }
527 if b == nil {
528 return 1
529 }
530
531 // Try numeric comparison first
532 if aNum, aOk := toFloat64(a); aOk {
533 if bNum, bOk := toFloat64(b); bOk {
534 if aNum < bNum {
535 return -1
536 }
537 if aNum > bNum {
538 return 1
539 }
540 return 0
541 }
542 }
543
544 // Try time comparison
545 if aTime, aOk := a.(time.Time); aOk {
546 if bTime, bOk := b.(time.Time); bOk {
547 if aTime.Before(bTime) {
548 return -1
549 }
550 if aTime.After(bTime) {
551 return 1
552 }
553 return 0
554 }
555 }
556
557 // Fall back to string comparison
558 aStr := fmt.Sprintf("%v", a)
559 bStr := fmt.Sprintf("%v", b)
560 if aStr < bStr {
561 return -1
562 }
563 if aStr > bStr {
564 return 1
565 }
566 return 0
567}
568
569// sortedCopy returns a sorted copy of a string slice
570func sortedCopy(s []string) []string {

Callers 1

sortRowsFunction · 0.85

Calls 1

toFloat64Function · 0.85

Tested by

no test coverage detected