From 50d0b8fe47f3da4d6a1dd6c7b7d694d24b0504b2 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Tue, 14 Nov 2023 13:36:04 -0500 Subject: [PATCH] move the nil check to earlier --- flow/model/model.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/flow/model/model.go b/flow/model/model.go index ab276f53c9..4ce215bc1c 100644 --- a/flow/model/model.go +++ b/flow/model/model.go @@ -121,22 +121,23 @@ func (r *RecordItems) toMap() (map[string]interface{}, error) { jsonStruct := make(map[string]interface{}) for col, idx := range r.colToValIdx { v := r.values[idx] + if v.Value == nil { + jsonStruct[col] = nil + continue + } + var err error switch v.Kind { case qvalue.QValueKindString, qvalue.QValueKindJSON: - if v.Value == nil { - jsonStruct[col] = nil - } else { - strVal, ok := v.Value.(string) - if !ok { - return nil, fmt.Errorf("expected string value for column %s for %T", col, v.Value) - } + strVal, ok := v.Value.(string) + if !ok { + return nil, fmt.Errorf("expected string value for column %s for %T", col, v.Value) + } - if len(strVal) > 15*1024*1024 { - jsonStruct[col] = "" - } else { - jsonStruct[col] = strVal - } + if len(strVal) > 15*1024*1024 { + jsonStruct[col] = "" + } else { + jsonStruct[col] = strVal } case qvalue.QValueKindTimestamp, qvalue.QValueKindTimestampTZ, qvalue.QValueKindDate, qvalue.QValueKindTime, qvalue.QValueKindTimeTZ: