From 4b9afabdd98235712d3e4833a65a3d9c16a9dba3 Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Thu, 19 Dec 2024 21:23:48 +0530 Subject: [PATCH 1/4] account for infinity modifier --- flow/connectors/postgres/qvalue_convert.go | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/flow/connectors/postgres/qvalue_convert.go b/flow/connectors/postgres/qvalue_convert.go index e3052a08f4..856a02210d 100644 --- a/flow/connectors/postgres/qvalue_convert.go +++ b/flow/connectors/postgres/qvalue_convert.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "net" "net/netip" "strings" @@ -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) @@ -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 } From 3c792c6bcebe25bf6ca14d76f4111a3cc416db1b Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Thu, 19 Dec 2024 21:25:43 +0530 Subject: [PATCH 2/4] remove log --- flow/connectors/postgres/qvalue_convert.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/flow/connectors/postgres/qvalue_convert.go b/flow/connectors/postgres/qvalue_convert.go index 856a02210d..ceaf865a41 100644 --- a/flow/connectors/postgres/qvalue_convert.go +++ b/flow/connectors/postgres/qvalue_convert.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "log/slog" "net" "net/netip" "strings" @@ -345,9 +344,7 @@ 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) From c903d0d4a6bbca9707777c8cd194f33f747364de Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Thu, 19 Dec 2024 21:26:34 +0530 Subject: [PATCH 3/4] minor change --- flow/connectors/postgres/qvalue_convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/connectors/postgres/qvalue_convert.go b/flow/connectors/postgres/qvalue_convert.go index ceaf865a41..a247a04b14 100644 --- a/flow/connectors/postgres/qvalue_convert.go +++ b/flow/connectors/postgres/qvalue_convert.go @@ -594,7 +594,7 @@ func convertTimeRangeBound(timeBound interface{}) (string, error) { 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) + return "", fmt.Errorf("unexpected bound value in tstzrange. Error: %v", err) } convertedTime = lowerParsed.Format(postgresFormat) } else { From 97903d743614235a668c0d0bd5c5f9c84ad415ac Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Thu, 19 Dec 2024 22:33:12 +0530 Subject: [PATCH 4/4] suggestions --- flow/connectors/postgres/qvalue_convert.go | 26 +++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/flow/connectors/postgres/qvalue_convert.go b/flow/connectors/postgres/qvalue_convert.go index a247a04b14..9e8f758489 100644 --- a/flow/connectors/postgres/qvalue_convert.go +++ b/flow/connectors/postgres/qvalue_convert.go @@ -584,22 +584,18 @@ func customTypeToQKind(typeName string) qvalue.QValueKind { // in tstzrange. // convertTimeRangeBound removes the +0000 UTC part func convertTimeRangeBound(timeBound interface{}) (string, error) { - var convertedTime string - switch timeBound := timeBound.(type) { - case pgtype.InfinityModifier: + if timeBound, isInfinite := timeBound.(pgtype.InfinityModifier); isInfinite { 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 bound value in tstzrange. Error: %v", err) - } - convertedTime = lowerParsed.Format(postgresFormat) - } else { - convertedTime = "" + } + + 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 bound value in tstzrange. Error: %v", err) } + return lowerParsed.Format(postgresFormat), nil } - return convertedTime, nil + return "", nil }