@@ -2,6 +2,7 @@ package clickhouse_transpiler
22
33import (
44 "fmt"
5+ "strings"
56 "testing"
67 "time"
78
@@ -44,6 +45,47 @@ func TestPlanner(t *testing.T) {
4445 fmt .Println (res )
4546}
4647
48+ // TestTracesDataDurationMsSQL verifies that the generated SQL uses intDiv (integer
49+ // division) for _duration_ms rather than toFloat64, which would produce fractional
50+ // values that Grafana's Tempo datasource cannot unmarshal into uint32 (issue #782).
51+ func TestTracesDataDurationMsSQL (t * testing.T ) {
52+ script , err := traceql_parser .Parse (`{.service.name="test"}` )
53+ if err != nil {
54+ t .Fatal (err )
55+ }
56+ plan , err := Plan (script )
57+ if err != nil {
58+ t .Fatal (err )
59+ }
60+ req , err := plan .Process (& shared.PlannerContext {
61+ IsCluster : false ,
62+ From : time .Now ().Add (time .Hour * - 1 ),
63+ To : time .Now (),
64+ Limit : 10 ,
65+ TracesAttrsTable : "tempo_traces_attrs_gin" ,
66+ TracesAttrsDistTable : "tempo_traces_attrs_gin_dist" ,
67+ TracesTable : "tempo_traces" ,
68+ TracesDistTable : "tempo_traces_dist" ,
69+ VersionInfo : map [string ]int64 {},
70+ })
71+ if err != nil {
72+ t .Fatal (err )
73+ }
74+ query , err := req .String (& sql.Ctx {
75+ Params : map [string ]sql.SQLObject {},
76+ Result : map [string ]sql.SQLObject {},
77+ })
78+ if err != nil {
79+ t .Fatal (err )
80+ }
81+ if strings .Contains (query , "toFloat64" ) {
82+ t .Errorf ("generated SQL must not contain toFloat64 for _duration_ms; got:\n %s" , query )
83+ }
84+ if ! strings .Contains (query , "intDiv" ) {
85+ t .Errorf ("generated SQL must use intDiv for _duration_ms; got:\n %s" , query )
86+ }
87+ }
88+
4789func TestComplexPlanner (t * testing.T ) {
4890 script , err := traceql_parser .Parse (`{.randomContainer=~"admiring" && .randomFloat > 10} | count() > 2 || {.randomContainer=~"boring" && .randomFloat < 10}` )
4991 if err != nil {
0 commit comments