mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 10:55:57 +08:00
Issue 6367 (#6376)
* fix: issue with orderby by materialized column * fix: tests * fix: order by issue in old explorer as well
This commit is contained in:
parent
e748fb0655
commit
22c10f9479
@ -419,9 +419,6 @@ func orderBy(panelType v3.PanelType, items []v3.OrderBy, tagLookup map[string]st
|
|||||||
} else if panelType == v3.PanelTypeList {
|
} else if panelType == v3.PanelTypeList {
|
||||||
attr := v3.AttributeKey{Key: item.ColumnName, DataType: item.DataType, Type: item.Type, IsColumn: item.IsColumn}
|
attr := v3.AttributeKey{Key: item.ColumnName, DataType: item.DataType, Type: item.Type, IsColumn: item.IsColumn}
|
||||||
name := getClickhouseColumnName(attr)
|
name := getClickhouseColumnName(attr)
|
||||||
if item.IsColumn {
|
|
||||||
name = "`" + name + "`"
|
|
||||||
}
|
|
||||||
orderBy = append(orderBy, fmt.Sprintf("%s %s", name, item.Order))
|
orderBy = append(orderBy, fmt.Sprintf("%s %s", name, item.Order))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -788,14 +788,14 @@ var testBuildLogsQueryData = []struct {
|
|||||||
AggregateOperator: v3.AggregateOperatorNoOp,
|
AggregateOperator: v3.AggregateOperatorNoOp,
|
||||||
Expression: "A",
|
Expression: "A",
|
||||||
Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{}},
|
Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{}},
|
||||||
OrderBy: []v3.OrderBy{{ColumnName: "method", DataType: v3.AttributeKeyDataTypeString, Order: "ASC", IsColumn: true}},
|
OrderBy: []v3.OrderBy{{ColumnName: "method", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, Order: "ASC", IsColumn: true}},
|
||||||
},
|
},
|
||||||
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body,CAST((attributes_string_key, attributes_string_value), 'Map(String, String)') as attributes_string," +
|
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, 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((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((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool," +
|
"CAST((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool," +
|
||||||
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string," +
|
"CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string," +
|
||||||
"CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope " +
|
"CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope " +
|
||||||
"from signoz_logs.distributed_logs where (timestamp >= 1680066360726210000 AND timestamp <= 1680066458000000000) order by `method` ASC",
|
"from signoz_logs.distributed_logs where (timestamp >= 1680066360726210000 AND timestamp <= 1680066458000000000) order by `attribute_string_method` ASC",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Test Noop with filter",
|
Name: "Test Noop with filter",
|
||||||
@ -1524,7 +1524,7 @@ var testPrepLogsQueryLimitOffsetData = []struct {
|
|||||||
PageSize: 5,
|
PageSize: 5,
|
||||||
},
|
},
|
||||||
TableName: "logs",
|
TableName: "logs",
|
||||||
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, 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((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool,CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string,CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope from signoz_logs.distributed_logs where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) order by `timestamp` desc LIMIT 1",
|
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, 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((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool,CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string,CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope from signoz_logs.distributed_logs where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) order by timestamp desc LIMIT 1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Test limit greater than pageSize - order by ts",
|
Name: "Test limit greater than pageSize - order by ts",
|
||||||
@ -1545,7 +1545,7 @@ var testPrepLogsQueryLimitOffsetData = []struct {
|
|||||||
PageSize: 10,
|
PageSize: 10,
|
||||||
},
|
},
|
||||||
TableName: "logs",
|
TableName: "logs",
|
||||||
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, 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((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool,CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string,CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope from signoz_logs.distributed_logs where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND id < '2TNh4vp2TpiWyLt3SzuadLJF2s4' order by `timestamp` desc LIMIT 10",
|
ExpectedQuery: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, 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((attributes_bool_key, attributes_bool_value), 'Map(String, Bool)') as attributes_bool,CAST((resources_string_key, resources_string_value), 'Map(String, String)') as resources_string,CAST((scope_string_key, scope_string_value), 'Map(String, String)') as scope from signoz_logs.distributed_logs where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND id < '2TNh4vp2TpiWyLt3SzuadLJF2s4' order by timestamp desc LIMIT 10",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Test limit less than pageSize - order by custom",
|
Name: "Test limit less than pageSize - order by custom",
|
||||||
|
@ -255,9 +255,6 @@ func orderBy(panelType v3.PanelType, items []v3.OrderBy, tagLookup map[string]st
|
|||||||
} else if panelType == v3.PanelTypeList {
|
} else if panelType == v3.PanelTypeList {
|
||||||
attr := v3.AttributeKey{Key: item.ColumnName, DataType: item.DataType, Type: item.Type, IsColumn: item.IsColumn}
|
attr := v3.AttributeKey{Key: item.ColumnName, DataType: item.DataType, Type: item.Type, IsColumn: item.IsColumn}
|
||||||
name := getClickhouseKey(attr)
|
name := getClickhouseKey(attr)
|
||||||
if item.IsColumn {
|
|
||||||
name = "`" + name + "`"
|
|
||||||
}
|
|
||||||
orderBy = append(orderBy, fmt.Sprintf("%s %s", name, item.Order))
|
orderBy = append(orderBy, fmt.Sprintf("%s %s", name, item.Order))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -520,14 +520,16 @@ func Test_orderByAttributeKeyTags(t *testing.T) {
|
|||||||
{
|
{
|
||||||
ColumnName: "bytes",
|
ColumnName: "bytes",
|
||||||
Order: "asc",
|
Order: "asc",
|
||||||
|
IsColumn: true,
|
||||||
|
Type: v3.AttributeKeyTypeTag,
|
||||||
|
DataType: v3.AttributeKeyDataTypeString,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tags: []v3.AttributeKey{
|
tags: []v3.AttributeKey{
|
||||||
{Key: "name"},
|
{Key: "name"},
|
||||||
{Key: "bytes"},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: "`name` asc,value asc,`bytes` asc",
|
want: "`name` asc,value asc,`attribute_string_bytes` asc",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "test 4",
|
name: "test 4",
|
||||||
@ -1016,7 +1018,7 @@ func TestPrepareLogsQuery(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string from " +
|
want: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string from " +
|
||||||
"signoz_logs.distributed_logs_v2 where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) " +
|
"signoz_logs.distributed_logs_v2 where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) " +
|
||||||
"order by `timestamp` desc LIMIT 1",
|
"order by timestamp desc LIMIT 1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test limit greater than pageSize - order by ts",
|
name: "Test limit greater than pageSize - order by ts",
|
||||||
@ -1041,7 +1043,7 @@ func TestPrepareLogsQuery(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string from " +
|
want: "SELECT timestamp, id, trace_id, span_id, trace_flags, severity_text, severity_number, scope_name, scope_version, body, attributes_string, attributes_number, attributes_bool, resources_string, scope_string from " +
|
||||||
"signoz_logs.distributed_logs_v2 where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) " +
|
"signoz_logs.distributed_logs_v2 where (timestamp >= 1680066360726000000 AND timestamp <= 1680066458000000000) AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) " +
|
||||||
"AND id < '2TNh4vp2TpiWyLt3SzuadLJF2s4' order by `timestamp` desc LIMIT 10",
|
"AND id < '2TNh4vp2TpiWyLt3SzuadLJF2s4' order by timestamp desc LIMIT 10",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test limit less than pageSize - order by custom",
|
name: "Test limit less than pageSize - order by custom",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user