mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 20:15:53 +08:00
fix: count fixed columns of type bool/number (#2698)
* fix: count fixed columns of type bool/number * fix: add test for count with fixed column and filter
This commit is contained in:
parent
c7f09354f7
commit
ec8e505647
@ -281,10 +281,9 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, tableName str
|
|||||||
key := enrichKeyWithMetadata(mq.AggregateAttribute, keys)
|
key := enrichKeyWithMetadata(mq.AggregateAttribute, keys)
|
||||||
if key.IsColumn {
|
if key.IsColumn {
|
||||||
subQuery, err := existsSubQueryForFixedColumn(key, v3.FilterOperatorExists)
|
subQuery, err := existsSubQueryForFixedColumn(key, v3.FilterOperatorExists)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
filterSubQuery = ""
|
filterSubQuery = fmt.Sprintf("%s AND %s", filterSubQuery, subQuery)
|
||||||
}
|
}
|
||||||
filterSubQuery = fmt.Sprintf(" AND %s", subQuery)
|
|
||||||
} else {
|
} else {
|
||||||
columnType, columnDataType := getClickhouseTracesColumnDataTypeAndType(key)
|
columnType, columnDataType := getClickhouseTracesColumnDataTypeAndType(key)
|
||||||
filterSubQuery = fmt.Sprintf("%s AND has(%s%s, '%s')", filterSubQuery, columnDataType, columnType, mq.AggregateAttribute.Key)
|
filterSubQuery = fmt.Sprintf("%s AND has(%s%s, '%s')", filterSubQuery, columnDataType, columnType, mq.AggregateAttribute.Key)
|
||||||
|
@ -359,7 +359,7 @@ var testBuildTracesQueryData = []struct {
|
|||||||
ExpectedQuery string
|
ExpectedQuery string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Test aggregate count on column",
|
Name: "Test aggregate count on fixed column of float64 type",
|
||||||
Start: 1680066360726210000,
|
Start: 1680066360726210000,
|
||||||
End: 1680066458000000000,
|
End: 1680066458000000000,
|
||||||
Step: 60,
|
Step: 60,
|
||||||
@ -367,6 +367,41 @@ var testBuildTracesQueryData = []struct {
|
|||||||
QueryName: "A",
|
QueryName: "A",
|
||||||
AggregateOperator: v3.AggregateOperatorCount,
|
AggregateOperator: v3.AggregateOperatorCount,
|
||||||
Expression: "A",
|
Expression: "A",
|
||||||
|
AggregateAttribute: v3.AttributeKey{Key: "durationNano", DataType: v3.AttributeKeyDataTypeFloat64, Type: v3.AttributeKeyTypeTag, IsColumn: true},
|
||||||
|
},
|
||||||
|
TableName: "signoz_traces.distributed_signoz_index_v2",
|
||||||
|
ExpectedQuery: "SELECT toStartOfInterval(timestamp, INTERVAL 60 SECOND) AS ts, toFloat64(count()) as value" +
|
||||||
|
" from signoz_traces.distributed_signoz_index_v2 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000')" +
|
||||||
|
" group by ts order by ts",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Test aggregate count on fixed column of float64 type with filter",
|
||||||
|
Start: 1680066360726210000,
|
||||||
|
End: 1680066458000000000,
|
||||||
|
Step: 60,
|
||||||
|
BuilderQuery: &v3.BuilderQuery{
|
||||||
|
QueryName: "A",
|
||||||
|
AggregateOperator: v3.AggregateOperatorCount,
|
||||||
|
Expression: "A",
|
||||||
|
AggregateAttribute: v3.AttributeKey{Key: "durationNano", DataType: v3.AttributeKeyDataTypeFloat64, Type: v3.AttributeKeyTypeTag, IsColumn: true},
|
||||||
|
Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "customer_id", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag}, Value: "10001", Operator: "="}}},
|
||||||
|
},
|
||||||
|
TableName: "signoz_traces.distributed_signoz_index_v2",
|
||||||
|
ExpectedQuery: "SELECT toStartOfInterval(timestamp, INTERVAL 60 SECOND) AS ts," +
|
||||||
|
" toFloat64(count()) as value from signoz_traces.distributed_signoz_index_v2" +
|
||||||
|
" where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000')" +
|
||||||
|
" AND stringTagMap['customer_id'] = '10001' group by ts order by ts",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Test aggregate count on fixed column of bool type",
|
||||||
|
Start: 1680066360726210000,
|
||||||
|
End: 1680066458000000000,
|
||||||
|
Step: 60,
|
||||||
|
BuilderQuery: &v3.BuilderQuery{
|
||||||
|
QueryName: "A",
|
||||||
|
AggregateOperator: v3.AggregateOperatorCount,
|
||||||
|
Expression: "A",
|
||||||
|
AggregateAttribute: v3.AttributeKey{Key: "hasError", DataType: v3.AttributeKeyDataTypeBool, Type: v3.AttributeKeyTypeTag, IsColumn: true},
|
||||||
},
|
},
|
||||||
TableName: "signoz_traces.distributed_signoz_index_v2",
|
TableName: "signoz_traces.distributed_signoz_index_v2",
|
||||||
ExpectedQuery: "SELECT toStartOfInterval(timestamp, INTERVAL 60 SECOND) AS ts, toFloat64(count()) as value" +
|
ExpectedQuery: "SELECT toStartOfInterval(timestamp, INTERVAL 60 SECOND) AS ts, toFloat64(count()) as value" +
|
||||||
@ -390,7 +425,7 @@ var testBuildTracesQueryData = []struct {
|
|||||||
" AND has(stringTagMap, 'user_name') group by ts order by ts",
|
" AND has(stringTagMap, 'user_name') group by ts order by ts",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Test aggregate count on a fixed column",
|
Name: "Test aggregate count on a fixed column of string type",
|
||||||
Start: 1680066360726210000,
|
Start: 1680066360726210000,
|
||||||
End: 1680066458000000000,
|
End: 1680066458000000000,
|
||||||
Step: 60,
|
Step: 60,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user