fix(go): write tdengine timestamps as epoch millis

This commit is contained in:
lingniu
2026-07-03 09:17:53 +08:00
parent a16043c032
commit 75fbd92de9
2 changed files with 10 additions and 1 deletions

View File

@@ -420,7 +420,7 @@ func literal(value any) string {
} }
switch typed := value.(type) { switch typed := value.(type) {
case time.Time: case time.Time:
return "'" + typed.UTC().Format("2006-01-02 15:04:05.000") + "'" return strconv.FormatInt(typed.UnixMilli(), 10)
case string: case string:
return "'" + quote(typed) + "'" return "'" + quote(typed) + "'"
case envelope.ParseStatus: case envelope.ParseStatus:

View File

@@ -5,6 +5,7 @@ import (
"database/sql" "database/sql"
"strings" "strings"
"testing" "testing"
"time"
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope" "lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
) )
@@ -151,6 +152,14 @@ func TestWriterLeavesParsedJSONEmptyWhenNoParsedPayload(t *testing.T) {
} }
} }
func TestTimeLiteralsUseEpochMilliseconds(t *testing.T) {
value := time.Date(2026, 7, 3, 1, 12, 59, 77_000_000, time.UTC)
if got, want := literal(value), "1783041179077"; got != want {
t.Fatalf("time literal = %s, want %s", got, want)
}
}
func TestWriterSkipsSparseDerivedRows(t *testing.T) { func TestWriterSkipsSparseDerivedRows(t *testing.T) {
exec := &recordingExec{} exec := &recordingExec{}
writer := NewWriter(exec) writer := NewWriter(exec)