fix: do not return zero value for non-aggregated table result (#5217)

This commit is contained in:
Srikanth Chekuri 2024-06-14 16:23:56 +05:30 committed by GitHub
parent aa9689e025
commit ded58f5392
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4437,7 +4437,7 @@ func (r *ClickHouseReader) GetLogAttributeValues(ctx context.Context, req *v3.Fi
} }
func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([]string, map[string]string, []map[string]string, v3.Point) { func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([]string, map[string]string, []map[string]string, *v3.Point) {
// Each row will have a value and a timestamp, and an optional list of label values // Each row will have a value and a timestamp, and an optional list of label values
// example: {Timestamp: ..., Value: ...} // example: {Timestamp: ..., Value: ...}
// The timestamp may also not present in some cases where the time series is reduced to single value // The timestamp may also not present in some cases where the time series is reduced to single value
@ -4453,6 +4453,8 @@ func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([
// example: {"serviceName": "frontend", "operation": "/fetch"} // example: {"serviceName": "frontend", "operation": "/fetch"}
groupAttributes := make(map[string]string) groupAttributes := make(map[string]string)
isValidPoint := false
for idx, v := range vars { for idx, v := range vars {
colName := columnNames[idx] colName := columnNames[idx]
switch v := v.(type) { switch v := v.(type) {
@ -4481,6 +4483,7 @@ func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([
case *time.Time: case *time.Time:
point.Timestamp = v.UnixMilli() point.Timestamp = v.UnixMilli()
case *float64, *float32: case *float64, *float32:
isValidPoint = true
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 { if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 {
point.Value = float64(reflect.ValueOf(v).Elem().Float()) point.Value = float64(reflect.ValueOf(v).Elem().Float())
} else { } else {
@ -4491,6 +4494,7 @@ func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Float()) groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Float())
} }
case *uint, *uint8, *uint64, *uint16, *uint32: case *uint, *uint8, *uint64, *uint16, *uint32:
isValidPoint = true
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 { if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 {
point.Value = float64(reflect.ValueOf(v).Elem().Uint()) point.Value = float64(reflect.ValueOf(v).Elem().Uint())
} else { } else {
@ -4501,6 +4505,7 @@ func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([
groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint()) groupAttributes[colName] = fmt.Sprintf("%v", reflect.ValueOf(v).Elem().Uint())
} }
case *int, *int8, *int16, *int32, *int64: case *int, *int8, *int16, *int32, *int64:
isValidPoint = true
if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 { if _, ok := constants.ReservedColumnTargetAliases[colName]; ok || countOfNumberCols == 1 {
point.Value = float64(reflect.ValueOf(v).Elem().Int()) point.Value = float64(reflect.ValueOf(v).Elem().Int())
} else { } else {
@ -4521,7 +4526,10 @@ func readRow(vars []interface{}, columnNames []string, countOfNumberCols int) ([
zap.L().Error("unsupported var type found in query builder query result", zap.Any("v", v), zap.String("colName", colName)) zap.L().Error("unsupported var type found in query builder query result", zap.Any("v", v), zap.String("colName", colName))
} }
} }
return groupBy, groupAttributes, groupAttributesArray, point if isValidPoint {
return groupBy, groupAttributes, groupAttributesArray, &point
}
return groupBy, groupAttributes, groupAttributesArray, nil
} }
func readRowsForTimeSeriesResult(rows driver.Rows, vars []interface{}, columnNames []string, countOfNumberCols int) ([]*v3.Series, error) { func readRowsForTimeSeriesResult(rows driver.Rows, vars []interface{}, columnNames []string, countOfNumberCols int) ([]*v3.Series, error) {
@ -4562,7 +4570,7 @@ func readRowsForTimeSeriesResult(rows driver.Rows, vars []interface{}, columnNam
groupBy, groupAttributes, groupAttributesArray, metricPoint := readRow(vars, columnNames, countOfNumberCols) groupBy, groupAttributes, groupAttributesArray, metricPoint := readRow(vars, columnNames, countOfNumberCols)
// skip the point if the value is NaN or Inf // skip the point if the value is NaN or Inf
// are they ever useful enough to be returned? // are they ever useful enough to be returned?
if math.IsNaN(metricPoint.Value) || math.IsInf(metricPoint.Value, 0) { if metricPoint != nil && (math.IsNaN(metricPoint.Value) || math.IsInf(metricPoint.Value, 0)) {
continue continue
} }
sort.Strings(groupBy) sort.Strings(groupBy)
@ -4572,7 +4580,9 @@ func readRowsForTimeSeriesResult(rows driver.Rows, vars []interface{}, columnNam
} }
seriesToAttrs[key] = groupAttributes seriesToAttrs[key] = groupAttributes
labelsArray[key] = groupAttributesArray labelsArray[key] = groupAttributesArray
seriesToPoints[key] = append(seriesToPoints[key], metricPoint) if metricPoint != nil {
seriesToPoints[key] = append(seriesToPoints[key], *metricPoint)
}
} }
var seriesList []*v3.Series var seriesList []*v3.Series