Skip to content

Commit

Permalink
account for infinity modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Dec 19, 2024
1 parent bc5fff5 commit 4b9afab
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions flow/connectors/postgres/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net"
"net/netip"
"strings"
Expand Down Expand Up @@ -344,7 +345,9 @@ func parseFieldFromQValueKind(qvalueKind qvalue.QValueKind, value interface{}) (

return qvalue.QValueString{Val: string(intervalJSON)}, nil
case qvalue.QValueKindTSTZRange:
slog.Info("tstzrangeValue", slog.Any("value", value))
tstzrangeObject := value.(pgtype.Range[interface{}])
slog.Info("tstzrangeObject", slog.Any("object", tstzrangeObject))
lowerBoundType := tstzrangeObject.LowerType
upperBoundType := tstzrangeObject.UpperType
lowerTime, err := convertTimeRangeBound(tstzrangeObject.Lower)
Expand Down Expand Up @@ -584,18 +587,22 @@ func customTypeToQKind(typeName string) qvalue.QValueKind {
// in tstzrange.
// convertTimeRangeBound removes the +0000 UTC part
func convertTimeRangeBound(timeBound interface{}) (string, error) {
layout := "2006-01-02 15:04:05 -0700 MST"
postgresFormat := "2006-01-02 15:04:05"
var convertedTime string
if timeBound != nil {
lowerParsed, err := time.Parse(layout, fmt.Sprint(timeBound))
if err != nil {
return "", fmt.Errorf("unexpected lower bound value in tstzrange. Error: %v", err)
switch timeBound := timeBound.(type) {
case pgtype.InfinityModifier:
return timeBound.String(), nil
default:
layout := "2006-01-02 15:04:05 -0700 MST"
postgresFormat := "2006-01-02 15:04:05"
if timeBound != nil {
lowerParsed, err := time.Parse(layout, fmt.Sprint(timeBound))
if err != nil {
return "", fmt.Errorf("unexpected lower bound value in tstzrange. Error: %v", err)
}
convertedTime = lowerParsed.Format(postgresFormat)
} else {
convertedTime = ""
}
convertedTime = lowerParsed.Format(postgresFormat)
} else {
convertedTime = ""
}

return convertedTime, nil
}

0 comments on commit 4b9afab

Please sign in to comment.