Skip to content

Commit

Permalink
partition: use cmp.Compare (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex authored Feb 7, 2024
1 parent 8ba31be commit 199ce12
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions flow/connectors/utils/partition/partition.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package partition_utils

import (
"cmp"
"fmt"
"log/slog"
"time"
Expand All @@ -16,21 +17,9 @@ import (
func compareValues(prevEnd interface{}, start interface{}) int {
switch v := start.(type) {
case int64:
if prevEnd.(int64) < v {
return -1
} else if prevEnd.(int64) > v {
return 1
} else {
return 0
}
return cmp.Compare(prevEnd.(int64), v)
case int32:
if prevEnd.(int64) < int64(v) {
return -1
} else if prevEnd.(int64) > int64(v) {
return 1
} else {
return 0
}
return cmp.Compare(prevEnd.(int64), int64(v))
case time.Time:
if prevEnd.(time.Time).Before(v) {
return -1
Expand All @@ -41,25 +30,12 @@ func compareValues(prevEnd interface{}, start interface{}) int {
}
case pgtype.TID:
pe := prevEnd.(pgtype.TID)
if pe.BlockNumber < v.BlockNumber {
return -1
} else if pe.BlockNumber > v.BlockNumber {
return 1
} else if pe.OffsetNumber < v.OffsetNumber {
return -1
} else if pe.OffsetNumber > v.OffsetNumber {
return 1
} else {
return 0
if c := cmp.Compare(pe.BlockNumber, v.BlockNumber); c != 0 {
return c
}
return cmp.Compare(pe.OffsetNumber, v.OffsetNumber)
case uint32: // xmin
if prevEnd.(uint32) < v {
return -1
} else if prevEnd.(uint32) > v {
return 1
} else {
return 0
}
return cmp.Compare(prevEnd.(uint32), v)
default:
return 0
}
Expand Down

0 comments on commit 199ce12

Please sign in to comment.