Commit 69a5530a by Kyle Brandt Committed by GitHub

Backend Plugins: use sdk v0.26.0 (#22725)

allows Field names to be duplicated, goes with #22705
parent 08d8190c
......@@ -32,7 +32,7 @@ require (
github.com/gorilla/websocket v1.4.1
github.com/gosimple/slug v1.4.2
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-sdk-go v0.24.0
github.com/grafana/grafana-plugin-sdk-go v0.26.0
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.0.1
github.com/hashicorp/go-version v1.1.0
......
......@@ -139,6 +139,8 @@ github.com/grafana/grafana-plugin-sdk-go v0.22.1-0.20200310164332-6b4c0d952d70 h
github.com/grafana/grafana-plugin-sdk-go v0.22.1-0.20200310164332-6b4c0d952d70/go.mod h1:G6Ov9M+FDOZXNw8eKXINO6XzqdUvTs7huwyQp5jLTBQ=
github.com/grafana/grafana-plugin-sdk-go v0.24.0 h1:sgd9rAQMmB0rAIMd4JVMFM0Gc+CTHoDwN5oxkPjVrGw=
github.com/grafana/grafana-plugin-sdk-go v0.24.0/go.mod h1:G6Ov9M+FDOZXNw8eKXINO6XzqdUvTs7huwyQp5jLTBQ=
github.com/grafana/grafana-plugin-sdk-go v0.26.0 h1:zDOZMGgGOrFF5m7+iqcQSQA/AJiG9xplNibL8SbLmn4=
github.com/grafana/grafana-plugin-sdk-go v0.26.0/go.mod h1:G6Ov9M+FDOZXNw8eKXINO6XzqdUvTs7huwyQp5jLTBQ=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
......
......@@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"time"
"github.com/apache/arrow/go/arrow"
......@@ -70,7 +72,28 @@ func MarshalArrow(f *Frame) ([]byte, error) {
return fb.Buff.Bytes(), nil
}
// buildArrowFields builds Arrow field definitions from a Frame.
// fieldNamePrefixSep is the delimiter used with fieldNamePrefix.
const fieldNamePrefixSep = "🦥: "
// fieldNamePrefix is the fmt string for Field Names. We prefix the name with fieldIdx number, sloth, :, space
// to ensure names are unique. The prefix is removed upon reading.
const fieldNamePrefix = "%s" + fieldNamePrefixSep + "%s"
// prefixFieldName adds our special fieldNamePrefix to the fieldNames so they are unique when writing to arrow.
func prefixFieldName(fieldIdx int, name string) string {
return fmt.Sprintf(fieldNamePrefix, strconv.Itoa(fieldIdx), name)
}
// prefixFieldNameStrip adds our special fieldNamePrefix from Field Names when reading from arrow.
func prefixFieldNameStrip(name string) string {
sp := strings.SplitN(name, fieldNamePrefixSep, 2)
if len(sp) == 2 {
return sp[1]
}
return name
}
// buildArrowFields builds Arrow field definitions from a DataFrame.
func buildArrowFields(f *Frame) ([]arrow.Field, error) {
arrowFields := make([]arrow.Field, len(f.Fields))
......@@ -80,7 +103,7 @@ func buildArrowFields(f *Frame) ([]arrow.Field, error) {
return nil, err
}
fieldMeta := map[string]string{"name": field.Name}
fieldMeta := map[string]string{"name": prefixFieldName(i, field.Name)}
if field.Labels != nil {
if fieldMeta["labels"], err = toJSONString(field.Labels); err != nil {
......@@ -97,7 +120,7 @@ func buildArrowFields(f *Frame) ([]arrow.Field, error) {
}
arrowFields[i] = arrow.Field{
Name: field.Name,
Name: prefixFieldName(i, field.Name),
Type: t,
Metadata: arrow.MetadataFrom(fieldMeta),
Nullable: nullable,
......@@ -301,7 +324,7 @@ func initializeFrameFields(schema *arrow.Schema, frame *Frame) ([]bool, error) {
nullable := make([]bool, len(schema.Fields()))
for idx, field := range schema.Fields() {
sdkField := &Field{
Name: field.Name,
Name: prefixFieldNameStrip(field.Name),
}
if labelsAsString, ok := getMDKey("labels", field.Metadata); ok {
if err := json.Unmarshal([]byte(labelsAsString), &sdkField.Labels); err != nil {
......
......@@ -147,7 +147,7 @@ github.com/gosimple/slug
# github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4
github.com/grafana/grafana-plugin-model/go/datasource
github.com/grafana/grafana-plugin-model/go/renderer
# github.com/grafana/grafana-plugin-sdk-go v0.24.0
# github.com/grafana/grafana-plugin-sdk-go v0.26.0
github.com/grafana/grafana-plugin-sdk-go/backend/plugin
github.com/grafana/grafana-plugin-sdk-go/data
github.com/grafana/grafana-plugin-sdk-go/genproto/pluginv2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment