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:
Vishal Sharma 2023-05-16 19:32:50 +05:30 committed by GitHub
parent c7f09354f7
commit ec8e505647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 8 deletions

View File

@ -281,10 +281,9 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, tableName str
key := enrichKeyWithMetadata(mq.AggregateAttribute, keys)
if key.IsColumn {
subQuery, err := existsSubQueryForFixedColumn(key, v3.FilterOperatorExists)
if err != nil {
filterSubQuery = ""
if err == nil {
filterSubQuery = fmt.Sprintf("%s AND %s", filterSubQuery, subQuery)
}
filterSubQuery = fmt.Sprintf(" AND %s", subQuery)
} else {
columnType, columnDataType := getClickhouseTracesColumnDataTypeAndType(key)
filterSubQuery = fmt.Sprintf("%s AND has(%s%s, '%s')", filterSubQuery, columnDataType, columnType, mq.AggregateAttribute.Key)

View File

@ -359,7 +359,7 @@ var testBuildTracesQueryData = []struct {
ExpectedQuery string
}{
{
Name: "Test aggregate count on column",
Name: "Test aggregate count on fixed column of float64 type",
Start: 1680066360726210000,
End: 1680066458000000000,
Step: 60,
@ -367,6 +367,41 @@ var testBuildTracesQueryData = []struct {
QueryName: "A",
AggregateOperator: v3.AggregateOperatorCount,
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",
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",
},
{
Name: "Test aggregate count on a fixed column",
Name: "Test aggregate count on a fixed column of string type",
Start: 1680066360726210000,
End: 1680066458000000000,
Step: 60,