44
44
_DEFAULT_ROW_LIMIT = 10_000
45
45
_BUFFER_WINDOW = 2 * 3600 # 2 hours
46
46
47
+
48
+ def _convert_key_to_support_doubles_and_floats_for_backward_compat (
49
+ key : TraceAttribute .Key .ValueType ,
50
+ ) -> TraceAttribute .Key .ValueType :
51
+ return TraceAttribute .Key .ValueType (- 1 * key )
52
+
53
+
47
54
_ATTRIBUTES : dict [
48
55
TraceAttribute .Key .ValueType ,
49
56
tuple [str , AttributeKey .Type .ValueType ],
69
76
AttributeKey .Type .TYPE_STRING ,
70
77
),
71
78
}
79
+ # for every AttributeKey of TYPE_FLOAT a user may add during the backward compat period, this adds the TYPE_DOUBLE equivalent
80
+ _attributes_backward_compat = dict ()
81
+ for k in _ATTRIBUTES :
82
+ v = _ATTRIBUTES [k ]
83
+ if v [1 ] == AttributeKey .Type .TYPE_FLOAT :
84
+ _attributes_backward_compat [
85
+ _convert_key_to_support_doubles_and_floats_for_backward_compat (k )
86
+ ] = (v [0 ], AttributeKey .Type .TYPE_DOUBLE )
87
+ _ATTRIBUTES .update (_attributes_backward_compat )
88
+
72
89
_TYPES_TO_CLICKHOUSE : dict [
73
90
AttributeKey .Type .ValueType ,
74
91
tuple [str , Callable [[Any ], AttributeValue ]],
85
102
"Float64" ,
86
103
lambda x : AttributeValue (val_float = float (x )),
87
104
),
105
+ AttributeKey .Type .TYPE_DOUBLE : (
106
+ "Float64" ,
107
+ lambda x : AttributeValue (val_double = float (x )),
108
+ ),
88
109
}
89
110
90
111
@@ -102,11 +123,19 @@ def _attribute_to_expression(
102
123
alias = _ATTRIBUTES [trace_attribute .key ][0 ],
103
124
)
104
125
if trace_attribute .key == TraceAttribute .Key .KEY_START_TIMESTAMP :
105
- attribute = _ATTRIBUTES [trace_attribute .key ]
126
+ attribute = (
127
+ _ATTRIBUTES [
128
+ _convert_key_to_support_doubles_and_floats_for_backward_compat (
129
+ trace_attribute .key
130
+ )
131
+ ]
132
+ if trace_attribute .type == AttributeKey .Type .TYPE_DOUBLE
133
+ else _ATTRIBUTES [trace_attribute .key ]
134
+ )
106
135
return f .cast (
107
136
f .min (column ("start_timestamp" )),
108
137
_TYPES_TO_CLICKHOUSE [attribute [1 ]][0 ],
109
- alias = _ATTRIBUTES [ trace_attribute . key ] [0 ],
138
+ alias = attribute [0 ],
110
139
)
111
140
if trace_attribute .key == TraceAttribute .Key .KEY_ROOT_SPAN_NAME :
112
141
# TODO: Change to return the root span name instead of the trace's first span's name.
@@ -116,7 +145,15 @@ def _attribute_to_expression(
116
145
alias = _ATTRIBUTES [trace_attribute .key ][0 ],
117
146
)
118
147
if trace_attribute .key in _ATTRIBUTES :
119
- attribute = _ATTRIBUTES [trace_attribute .key ]
148
+ attribute = (
149
+ _ATTRIBUTES [
150
+ _convert_key_to_support_doubles_and_floats_for_backward_compat (
151
+ trace_attribute .key
152
+ )
153
+ ]
154
+ if trace_attribute .type == AttributeKey .Type .TYPE_DOUBLE
155
+ else _ATTRIBUTES [trace_attribute .key ]
156
+ )
120
157
return f .cast (
121
158
column (attribute [0 ]),
122
159
_TYPES_TO_CLICKHOUSE [attribute [1 ]][0 ],
@@ -165,8 +202,15 @@ def _convert_results(
165
202
TraceAttribute ,
166
203
] = defaultdict (TraceAttribute )
167
204
for attribute in request .attributes :
168
- value = row [_ATTRIBUTES [attribute .key ][0 ]]
169
- type = _ATTRIBUTES [attribute .key ][1 ]
205
+ backward_compat_attribute_key = (
206
+ _convert_key_to_support_doubles_and_floats_for_backward_compat (
207
+ attribute .key
208
+ )
209
+ if attribute .type == AttributeKey .Type .TYPE_DOUBLE
210
+ else attribute .key
211
+ )
212
+ value = row [_ATTRIBUTES [backward_compat_attribute_key ][0 ]]
213
+ type = _ATTRIBUTES [backward_compat_attribute_key ][1 ]
170
214
values [attribute .key ] = TraceAttribute (
171
215
key = attribute .key ,
172
216
value = _TYPES_TO_CLICKHOUSE [type ][1 ](value ),
0 commit comments