Skip to content

Commit

Permalink
Merge pull request #277 from taosdata/fix/xftan/TD-29976-main
Browse files Browse the repository at this point in the history
fix: fix parsing timestamp
  • Loading branch information
huskar-t authored May 9, 2024
2 parents 7237cd1 + 6a8103d commit 0272483
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions controller/rest/restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func (ctl *Restful) sql(c *gin.Context) {
timeBuffer = timeBuffer[:0]
switch precision {
case common.PrecisionMilliSecond: // milli-second
timeBuffer = time.Unix(0, ts*1e6).In(location).AppendFormat(timeBuffer, layout.LayoutMillSecond)
timeBuffer = time.Unix(ts/1e3, (ts%1e3)*1e6).In(location).AppendFormat(timeBuffer, layout.LayoutMillSecond)
case common.PrecisionMicroSecond: // micro-second
timeBuffer = time.Unix(0, ts*1e3).In(location).AppendFormat(timeBuffer, layout.LayoutMicroSecond)
timeBuffer = time.Unix(ts/1e6, (ts%1e6)*1e3).In(location).AppendFormat(timeBuffer, layout.LayoutMicroSecond)
case common.PrecisionNanoSecond: // nano-second
timeBuffer = time.Unix(0, ts).In(location).AppendFormat(timeBuffer, layout.LayoutNanoSecond)
default:
Expand Down
18 changes: 14 additions & 4 deletions controller/ws/tmq/tmq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func TestMeta(t *testing.T) {
var resp wstool.TDEngineRestfulResp
err = jsoniter.Unmarshal(w.Body.Bytes(), &resp)
assert.NoError(t, err)
assert.Equal(t, [][]driver.Value{
expect := [][]driver.Value{
{"ts", "TIMESTAMP", float64(8), ""},
{"c1", "BOOL", float64(1), ""},
{"c2", "TINYINT", float64(1), ""},
Expand Down Expand Up @@ -696,7 +696,12 @@ func TestMeta(t *testing.T) {
{"tc11", "DOUBLE", float64(8), "TAG"},
{"tc12", "VARCHAR", float64(20), "TAG"},
{"tc13", "NCHAR", float64(20), "TAG"},
}, resp.Data)
}
for index, values := range expect {
for i := 0; i < 4; i++ {
assert.Equal(t, values[i], resp.Data[index][i])
}
}
status = AfterTMQCommit
b, _ := json.Marshal(&TMQCommitReq{
ReqID: 3,
Expand Down Expand Up @@ -850,7 +855,7 @@ func TestMeta(t *testing.T) {
var resp wstool.TDEngineRestfulResp
err = jsoniter.Unmarshal(w.Body.Bytes(), &resp)
assert.NoError(t, err)
assert.Equal(t, [][]driver.Value{
expect := [][]driver.Value{
{"ts", "TIMESTAMP", float64(8), ""},
{"c1", "BOOL", float64(1), ""},
{"c2", "TINYINT", float64(1), ""},
Expand Down Expand Up @@ -879,7 +884,12 @@ func TestMeta(t *testing.T) {
{"tc11", "DOUBLE", float64(8), "TAG"},
{"tc12", "VARCHAR", float64(20), "TAG"},
{"tc13", "NCHAR", float64(20), "TAG"},
}, resp.Data)
}
for index, values := range expect {
for i := 0; i < 4; i++ {
assert.Equal(t, values[i], resp.Data[index][i])
}
}
time.Sleep(time.Second * 3)
w = httptest.NewRecorder()
body = strings.NewReader("drop topic if exists test_tmq_meta_ws_topic")
Expand Down
4 changes: 2 additions & 2 deletions plugin/prometheus/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func generateWriteSql(timeseries []prompbWrite.TimeSeries, sql *bytes.Buffer, tt
for _, sample := range timeseries[i].Samples {
sql.WriteString("('")
timeBuffer.Reset()
timeBuffer.B = time.Unix(0, sample.Timestamp*1e6).UTC().AppendFormat(timeBuffer.B, time.RFC3339Nano)
timeBuffer.B = time.Unix(sample.Timestamp/1e3, (sample.Timestamp%1e3)*1e6).UTC().AppendFormat(timeBuffer.B, time.RFC3339Nano)
sql.WriteString(bytesutil.ToUnsafeString(timeBuffer.B))
sql.WriteString("',")
if math.IsNaN(sample.Value) {
Expand Down Expand Up @@ -262,7 +262,7 @@ func generateReadSql(query *prompb.Query) (string, error) {
}

func ms2Time(ts int64) string {
return time.Unix(0, ts*1e6).UTC().Format(time.RFC3339Nano)
return time.Unix(ts/1e3, (ts%1e3)*1e6).UTC().Format(time.RFC3339Nano)
}

func escapeString(s string) string {
Expand Down

0 comments on commit 0272483

Please sign in to comment.