From af607e9df522fc812f1f09050cd978af438a9dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Fri, 6 Dec 2024 14:37:33 +0000 Subject: [PATCH] feedback --- flow/connectors/postgres/qvalue_convert.go | 8 ++++++++ flow/model/qvalue/equals.go | 18 ++++++++++++++++++ flow/model/qvalue/kind.go | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/flow/connectors/postgres/qvalue_convert.go b/flow/connectors/postgres/qvalue_convert.go index 184006f5ff..df88a89653 100644 --- a/flow/connectors/postgres/qvalue_convert.go +++ b/flow/connectors/postgres/qvalue_convert.go @@ -248,6 +248,8 @@ func parseUUID(value interface{}) (qvalue.QValue, error) { return nil, fmt.Errorf("invalid UUID string: %w", err) } return qvalue.QValueUUID{Val: id}, nil + case [16]byte: + return qvalue.QValueUUID{Val: uuid.UUID(v)}, nil case uuid.UUID: return qvalue.QValueUUID{Val: v}, nil default: @@ -267,6 +269,12 @@ func parseUUIDArray(value interface{}) (qvalue.QValue, error) { uuids = append(uuids, id) } return qvalue.QValueArrayUUID{Val: uuids}, nil + case [][16]byte: + uuids := make([]uuid.UUID, 0, len(v)) + for _, v := range v { + uuids = append(uuids, uuid.UUID(v)) + } + return qvalue.QValueArrayUUID{Val: uuids}, nil case []uuid.UUID: return qvalue.QValueArrayUUID{Val: v}, nil default: diff --git a/flow/model/qvalue/equals.go b/flow/model/qvalue/equals.go index a609c6df6a..13af407b4b 100644 --- a/flow/model/qvalue/equals.go +++ b/flow/model/qvalue/equals.go @@ -90,6 +90,8 @@ func Equals(qv QValue, other QValue) bool { return compareTimeArrays(qvValue, otherValue) case QValueArrayBoolean: return compareBoolArrays(q.Val, otherValue) + case QValueArrayUUID: + return compareUuidArrays(q.Val, otherValue) case QValueArrayString: return compareArrayString(q.Val, otherValue) default: @@ -321,6 +323,22 @@ func compareBoolArrays(value1, value2 interface{}) bool { return true } +func compareUuidArrays(value1, value2 interface{}) bool { + array1, ok1 := value1.([]uuid.UUID) + array2, ok2 := value2.([]uuid.UUID) + + if !ok1 || !ok2 || len(array1) != len(array2) { + return false + } + + for i := range array1 { + if array1[i] != array2[i] { + return false + } + } + return true +} + func compareArrayString(value1, value2 interface{}) bool { array1, ok1 := value1.([]string) array2, ok2 := value2.([]string) diff --git a/flow/model/qvalue/kind.go b/flow/model/qvalue/kind.go index 29fb469c24..10b7db4629 100644 --- a/flow/model/qvalue/kind.go +++ b/flow/model/qvalue/kind.go @@ -141,7 +141,7 @@ var QValueKindToClickHouseTypeMap = map[QValueKind]string{ QValueKindArrayTimestampTZ: "Array(DateTime64(6))", QValueKindArrayJSON: "String", QValueKindArrayJSONB: "String", - QValueKindArrayUUID: "Array(String)", + QValueKindArrayUUID: "Array(UUID)", } func getClickHouseTypeForNumericColumn(ctx context.Context, env map[string]string, column *protos.FieldDescription) (string, error) {