feat: minor fixes to logs QB (#3022)

* feat: minor fixes to logs QB

* fix: panel type check added

* fix: panel type check added

* fix: order by logic updated
This commit is contained in:
Nityananda Gohain 2023-07-04 19:05:20 +05:30 committed by GitHub
parent 10a3a6d3e5
commit 193b04ff0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 13 deletions

View File

@ -131,7 +131,7 @@ func enrichFieldWithMetadata(field v3.AttributeKey, fields map[string]v3.Attribu
// check if the field is present in the fields map
if existingField, ok := fields[field.Key]; ok {
if existingField.IsColumn {
return field
return existingField
}
field.Type = existingField.Type
field.DataType = existingField.DataType

View File

@ -321,19 +321,13 @@ func orderByAttributeKeyTags(panelType v3.PanelType, aggregatorOperator v3.Aggre
}
orderByArray := orderBy(panelType, items, groupTags)
found := false
for i := 0; i < len(orderByArray); i++ {
if strings.Compare(orderByArray[i], constants.TIMESTAMP) == 0 {
orderByArray[i] = "ts"
break
}
}
if !found {
if aggregatorOperator == v3.AggregateOperatorNoOp {
if panelType == v3.PanelTypeList {
if len(orderByArray) == 0 {
orderByArray = append(orderByArray, constants.TIMESTAMP)
} else {
orderByArray = append(orderByArray, "ts")
}
} else {
// since in other aggregation operator we will have to add ts as it will not be present in group by
orderByArray = append(orderByArray, "ts")
}
str := strings.Join(orderByArray, ",")

View File

@ -589,7 +589,7 @@ var testBuildLogsQueryData = []struct {
},
{
Name: "Test Noop",
PanelType: v3.PanelTypeGraph,
PanelType: v3.PanelTypeList,
Start: 1680066360726210000,
End: 1680066458000000000,
Step: 60,
@ -605,6 +605,25 @@ var testBuildLogsQueryData = []struct {
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string " +
"from signoz_logs.distributed_logs where (timestamp >= 1680066360726210000 AND timestamp <= 1680066458000000000) order by timestamp",
},
{
Name: "Test Noop order by custom",
PanelType: v3.PanelTypeList,
Start: 1680066360726210000,
End: 1680066458000000000,
Step: 60,
BuilderQuery: &v3.BuilderQuery{
SelectColumns: []v3.AttributeKey{},
QueryName: "A",
AggregateOperator: v3.AggregateOperatorNoOp,
Expression: "A",
Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{}},
OrderBy: []v3.OrderBy{{ColumnName: "method", Order: "ASC", IsColumn: true}},
},
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, body,CAST((attributes_string_key, attributes_string_value), 'Map(String, String)') as attributes_string," +
"CAST((attributes_int64_key, attributes_int64_value), 'Map(String, Int64)') as attributes_int64,CAST((attributes_float64_key, attributes_float64_value), 'Map(String, Float64)') as attributes_float64," +
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string " +
"from signoz_logs.distributed_logs where (timestamp >= 1680066360726210000 AND timestamp <= 1680066458000000000) order by method ASC",
},
{
Name: "Test aggregate with having clause",
PanelType: v3.PanelTypeGraph,