TestData: Support labels in CSV content name (#61337)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Ryan McKinley 2023-05-26 09:36:43 -07:00 committed by GitHub
parent 4aa207ed83
commit effe21fb65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 1 deletions

View File

@ -147,6 +147,16 @@ func LoadCsvContent(ioReader io.Reader, name string) (*data.Frame, error) {
}
}
// Check for labels in the name
idx := strings.Index(fieldName, "{")
if idx >= 0 {
labels := parseLabelsString(fieldName[idx:], fieldIndex) // _ := data.LabelsFromString(fieldName[idx:])
if len(labels) > 0 {
field.Labels = labels
fieldName = fieldName[:idx]
}
}
field.Name = fieldName
fields = append(fields, field)
if field.Len() > longest {

View File

@ -22,7 +22,7 @@ func TestCSVFileScenario(t *testing.T) {
}
t.Run("loadCsvFile", func(t *testing.T) {
files := []string{"simple", "mixed"}
files := []string{"simple", "mixed", "labels"}
for _, name := range files {
t.Run("Should load CSV Text: "+name, func(t *testing.T) {
filePath := filepath.Join("testdata", name+".csv")

View File

@ -0,0 +1,3 @@
"a{foo=bar,x=y}",b{foo=baz},"{foo=x, no=name, idx=$seriesIndex}"
1,2,3
4,5,6
1 a{foo=bar,x=y} b{foo=baz} {foo=x, no=name, idx=$seriesIndex}
2 1 2 3
3 4 5 6

View File

@ -0,0 +1,79 @@
// 🌟 This was machine generated. Do not edit. 🌟
//
// Frame[0]
// Name: labels
// Dimensions: 3 Fields by 2 Rows
// +----------------------+-----------------+-------------------------------+
// | Name: a | Name: b | Name: |
// | Labels: foo=bar, x=y | Labels: foo=baz | Labels: foo=x, idx=2, no=name |
// | Type: []*int64 | Type: []*int64 | Type: []*int64 |
// +----------------------+-----------------+-------------------------------+
// | 1 | 2 | 3 |
// | 4 | 5 | 6 |
// +----------------------+-----------------+-------------------------------+
//
//
// 🌟 This was machine generated. Do not edit. 🌟
{
"status": 200,
"frames": [
{
"schema": {
"name": "labels",
"fields": [
{
"name": "a",
"type": "number",
"typeInfo": {
"frame": "int64",
"nullable": true
},
"labels": {
"foo": "bar",
"x": "y"
}
},
{
"name": "b",
"type": "number",
"typeInfo": {
"frame": "int64",
"nullable": true
},
"labels": {
"foo": "baz"
}
},
{
"type": "number",
"typeInfo": {
"frame": "int64",
"nullable": true
},
"labels": {
"foo": "x",
"idx": "2",
"no": "name"
}
}
]
},
"data": {
"values": [
[
1,
4
],
[
2,
5
],
[
3,
6
]
]
}
}
]
}