From cdb09371bd3f08af67aad3f6f40aad740b5efbb9 Mon Sep 17 00:00:00 2001 From: Radim Hrazdil Date: Fri, 17 Oct 2025 16:06:05 +0200 Subject: [PATCH 1/3] query_result: test returned date with non-zero microseconds Signed-off-by: Radim Hrazdil --- platform/model/query_result_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/model/query_result_test.go b/platform/model/query_result_test.go index a6cd2cd0a..cd007ff7c 100644 --- a/platform/model/query_result_test.go +++ b/platform/model/query_result_test.go @@ -4,10 +4,11 @@ package model import ( "context" - "github.com/QuesmaOrg/quesma/platform/util" "strconv" "testing" "time" + + "github.com/QuesmaOrg/quesma/platform/util" ) func TestQueryResultCol_String(t *testing.T) { @@ -33,6 +34,7 @@ func TestQueryResultCol_String(t *testing.T) { value any expected string }{ + {time.Date(2023, 10, 5, 14, 30, 45, 123456000, time.UTC), `"name": "2023-10-05 14:30:45.123456 +0000 UTC"`}, {"test", `"name": "test"`}, {`test "GET"`, `"name": "test \"GET\""`}, {1, `"name": 1`}, From 2725d0df75fa9e2615eeca075734662815a3f1ce Mon Sep 17 00:00:00 2001 From: Radim Hrazdil Date: Thu, 16 Oct 2025 11:22:11 +0200 Subject: [PATCH 2/3] query_result: use strict date format, always include microseconds Signed-off-by: Radim Hrazdil --- platform/model/query_result.go | 13 ++++++++----- platform/model/query_result_test.go | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/platform/model/query_result.go b/platform/model/query_result.go index a519a5b14..f55194a72 100644 --- a/platform/model/query_result.go +++ b/platform/model/query_result.go @@ -5,15 +5,16 @@ package model import ( "context" "fmt" + "reflect" + "slices" + "strings" + "time" + "github.com/QuesmaOrg/quesma/platform/common_table" "github.com/QuesmaOrg/quesma/platform/logger" "github.com/QuesmaOrg/quesma/platform/schema" "github.com/QuesmaOrg/quesma/platform/util" "github.com/goccy/go-json" - "reflect" - "slices" - "strings" - "time" ) type ( @@ -46,7 +47,9 @@ func (c *QueryResultCol) String(ctx context.Context) string { } return fmt.Sprintf(`"%s": %s`, c.ColName, string(processed)) case time.Time: - return fmt.Sprintf(`"%s": "%v"`, c.ColName, valueExtracted) + // Format timestamp with consistent microsecond precision + formattedTime := valueExtracted.(time.Time).Format("2006-01-02 15:04:05.000000 -0700 MST") + return fmt.Sprintf(`"%s": "%s"`, c.ColName, formattedTime) case int, int64, float64, uint64, bool: return fmt.Sprintf(`"%s": %v`, c.ColName, valueExtracted) default: diff --git a/platform/model/query_result_test.go b/platform/model/query_result_test.go index cd007ff7c..55dd47b22 100644 --- a/platform/model/query_result_test.go +++ b/platform/model/query_result_test.go @@ -34,6 +34,7 @@ func TestQueryResultCol_String(t *testing.T) { value any expected string }{ + {time.Date(2023, 10, 5, 14, 30, 45, 000000000, time.UTC), `"name": "2023-10-05 14:30:45.000000 +0000 UTC"`}, {time.Date(2023, 10, 5, 14, 30, 45, 123456000, time.UTC), `"name": "2023-10-05 14:30:45.123456 +0000 UTC"`}, {"test", `"name": "test"`}, {`test "GET"`, `"name": "test \"GET\""`}, @@ -42,10 +43,10 @@ func TestQueryResultCol_String(t *testing.T) { {int64(1), `"name": 1`}, {uint64(1), `"name": 1`}, {true, `"name": true`}, - {time.Time{}, `"name": "0001-01-01 00:00:00 +0000 UTC"`}, + {time.Time{}, `"name": "0001-01-01 00:00:00.000000 +0000 UTC"`}, {strPtr, `"name": ""`}, {strPtrNil, ``}, - {timePtr, `"name": "0001-01-01 00:00:00 +0000 UTC"`}, + {timePtr, `"name": "0001-01-01 00:00:00.000000 +0000 UTC"`}, {timePtrNil, ``}, {int64Ptr, `"name": 1`}, {int64PtrNil, ``}, From fae30bd86605bd5a7ba5d316da252ae8ad2c4e34 Mon Sep 17 00:00:00 2001 From: Radim Hrazdil Date: Fri, 17 Oct 2025 16:23:26 +0200 Subject: [PATCH 3/3] query_result: assign result of type assertion to variable Addressing the static check linter. Signey-off-by: Radim Hrazdil --- platform/model/query_result.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/model/query_result.go b/platform/model/query_result.go index f55194a72..7da38c991 100644 --- a/platform/model/query_result.go +++ b/platform/model/query_result.go @@ -39,25 +39,25 @@ func (c *QueryResultCol) String(ctx context.Context) string { if valueExtracted == nil { return "" } - switch valueExtracted.(type) { + switch v := valueExtracted.(type) { case string: - processed, err := json.Marshal(valueExtracted) + processed, err := json.Marshal(v) if err != nil { - logger.ErrorWithCtx(ctx).Err(err).Msgf("failed to marshal value %v", valueExtracted) + logger.ErrorWithCtx(ctx).Err(err).Msgf("failed to marshal value %v", v) } return fmt.Sprintf(`"%s": %s`, c.ColName, string(processed)) case time.Time: // Format timestamp with consistent microsecond precision - formattedTime := valueExtracted.(time.Time).Format("2006-01-02 15:04:05.000000 -0700 MST") + formattedTime := v.Format("2006-01-02 15:04:05.000000 -0700 MST") return fmt.Sprintf(`"%s": "%s"`, c.ColName, formattedTime) case int, int64, float64, uint64, bool: - return fmt.Sprintf(`"%s": %v`, c.ColName, valueExtracted) + return fmt.Sprintf(`"%s": %v`, c.ColName, v) default: // Probably good to only use marshaller when necessary, so for arrays/maps, // and try to handle simple cases without it - marshalled, err := json.Marshal(valueExtracted) + marshalled, err := json.Marshal(v) if err != nil { - logger.ErrorWithCtx(ctx).Err(err).Msgf("failed to marshal value %v", valueExtracted) + logger.ErrorWithCtx(ctx).Err(err).Msgf("failed to marshal value %v", v) } return fmt.Sprintf(`"%s": %v`, c.ColName, string(marshalled)) }