mirror of
https://github.com/grafana/grafana.git
synced 2026-02-20 00:11:35 -05:00
Some checks failed
Actionlint / Lint GitHub Actions files (push) Waiting to run
Backend Code Checks / Detect whether code changed (push) Waiting to run
Backend Code Checks / Validate Backend Configs (push) Blocked by required conditions
Backend Unit Tests / Detect whether code changed (push) Waiting to run
Backend Unit Tests / Grafana (1/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (2/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (3/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (4/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (5/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (6/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (7/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana (8/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (1/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (2/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (3/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (4/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (5/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (6/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (7/8) (push) Blocked by required conditions
Backend Unit Tests / Grafana Enterprise (8/8) (push) Blocked by required conditions
Backend Unit Tests / All backend unit tests complete (push) Blocked by required conditions
CodeQL checks / Detect whether code changed (push) Waiting to run
CodeQL checks / Analyze (push) Blocked by required conditions
Lint Frontend / Detect whether code changed (push) Waiting to run
Lint Frontend / Lint (push) Blocked by required conditions
Lint Frontend / Typecheck (push) Blocked by required conditions
Lint Frontend / Verify API clients (push) Waiting to run
Lint Frontend / Verify API clients (enterprise) (push) Waiting to run
golangci-lint / Detect whether code changed (push) Waiting to run
golangci-lint / go-fmt (push) Blocked by required conditions
golangci-lint / lint-go (push) Blocked by required conditions
Crowdin Upload Action / upload-sources-to-crowdin (push) Waiting to run
Verify i18n / verify-i18n (push) Waiting to run
Documentation / Build & Verify Docs (push) Waiting to run
End-to-end tests / Detect whether code changed (push) Waiting to run
End-to-end tests / Build & Package Grafana (push) Blocked by required conditions
End-to-end tests / Build E2E test runner (push) Blocked by required conditions
End-to-end tests / push-docker-image (push) Blocked by required conditions
End-to-end tests / dashboards-suite (old arch) (push) Blocked by required conditions
End-to-end tests / panels-suite (old arch) (push) Blocked by required conditions
End-to-end tests / smoke-tests-suite (old arch) (push) Blocked by required conditions
End-to-end tests / various-suite (old arch) (push) Blocked by required conditions
End-to-end tests / Verify Storybook (Playwright) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (1/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (2/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (3/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (4/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (5/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (6/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (7/8) (push) Blocked by required conditions
End-to-end tests / Playwright E2E tests (8/8) (push) Blocked by required conditions
End-to-end tests / run-azure-monitor-e2e (push) Blocked by required conditions
End-to-end tests / All Playwright tests complete (push) Blocked by required conditions
End-to-end tests / A11y test (push) Blocked by required conditions
End-to-end tests / Publish metrics (push) Blocked by required conditions
End-to-end tests / All E2E tests complete (push) Blocked by required conditions
Frontend tests / Detect whether code changed (push) Waiting to run
Frontend tests / Unit tests (1 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (10 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (11 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (12 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (13 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (14 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (15 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (16 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (2 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (3 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (4 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (5 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (6 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (7 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (8 / 16) (push) Blocked by required conditions
Frontend tests / Unit tests (9 / 16) (push) Blocked by required conditions
Frontend tests / Decoupled plugin tests (push) Blocked by required conditions
Frontend tests / Packages unit tests (push) Blocked by required conditions
Frontend tests / All frontend unit tests complete (push) Blocked by required conditions
Frontend tests / Devenv frontend-service build (push) Blocked by required conditions
Integration Tests / Detect whether code changed (push) Waiting to run
Integration Tests / Sqlite (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (1/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (2/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (3/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (4/4) (push) Blocked by required conditions
Integration Tests / Sqlite Without CGo (profiled) (push) Blocked by required conditions
Integration Tests / MySQL (1/16) (push) Blocked by required conditions
Integration Tests / MySQL (10/16) (push) Blocked by required conditions
Integration Tests / MySQL (11/16) (push) Blocked by required conditions
Integration Tests / MySQL (12/16) (push) Blocked by required conditions
Integration Tests / MySQL (13/16) (push) Blocked by required conditions
Integration Tests / MySQL (14/16) (push) Blocked by required conditions
Integration Tests / MySQL (15/16) (push) Blocked by required conditions
Integration Tests / MySQL (16/16) (push) Blocked by required conditions
Integration Tests / MySQL (2/16) (push) Blocked by required conditions
Integration Tests / MySQL (3/16) (push) Blocked by required conditions
Integration Tests / MySQL (4/16) (push) Blocked by required conditions
Integration Tests / MySQL (5/16) (push) Blocked by required conditions
Integration Tests / MySQL (6/16) (push) Blocked by required conditions
Integration Tests / MySQL (7/16) (push) Blocked by required conditions
Integration Tests / MySQL (8/16) (push) Blocked by required conditions
Integration Tests / MySQL (9/16) (push) Blocked by required conditions
Integration Tests / Postgres (1/16) (push) Blocked by required conditions
Integration Tests / Postgres (10/16) (push) Blocked by required conditions
Integration Tests / Postgres (11/16) (push) Blocked by required conditions
Integration Tests / Postgres (12/16) (push) Blocked by required conditions
Integration Tests / Postgres (13/16) (push) Blocked by required conditions
Integration Tests / Postgres (14/16) (push) Blocked by required conditions
Integration Tests / Postgres (15/16) (push) Blocked by required conditions
Integration Tests / Postgres (16/16) (push) Blocked by required conditions
Integration Tests / Postgres (2/16) (push) Blocked by required conditions
Integration Tests / Postgres (3/16) (push) Blocked by required conditions
Integration Tests / Postgres (4/16) (push) Blocked by required conditions
Integration Tests / Postgres (5/16) (push) Blocked by required conditions
Integration Tests / Postgres (6/16) (push) Blocked by required conditions
Integration Tests / Postgres (7/16) (push) Blocked by required conditions
Integration Tests / Postgres (8/16) (push) Blocked by required conditions
Integration Tests / Postgres (9/16) (push) Blocked by required conditions
Integration Tests / All backend integration tests complete (push) Blocked by required conditions
publish-technical-documentation-next / sync (push) Waiting to run
Reject GitHub secrets / reject-gh-secrets (push) Waiting to run
Build Release Packages / setup (push) Waiting to run
Build Release Packages / Dispatch grafana-enterprise build (push) Blocked by required conditions
Build Release Packages / / darwin-amd64 (push) Blocked by required conditions
Build Release Packages / / darwin-arm64 (push) Blocked by required conditions
Build Release Packages / / linux-amd64 (push) Blocked by required conditions
Build Release Packages / / linux-armv6 (push) Blocked by required conditions
Build Release Packages / / linux-armv7 (push) Blocked by required conditions
Build Release Packages / / linux-arm64 (push) Blocked by required conditions
Build Release Packages / / linux-s390x (push) Blocked by required conditions
Build Release Packages / / windows-amd64 (push) Blocked by required conditions
Build Release Packages / / windows-arm64 (push) Blocked by required conditions
Build Release Packages / Upload artifacts (push) Blocked by required conditions
Build Release Packages / publish-dockerhub (push) Blocked by required conditions
Build Release Packages / Dispatch publish NPM canaries (push) Blocked by required conditions
Build Release Packages / notify-pr (push) Blocked by required conditions
Run dashboard schema v2 e2e / dashboard-schema-v2-e2e (push) Waiting to run
Shellcheck / Shellcheck scripts (push) Waiting to run
Run Storybook a11y tests / Detect whether code changed (push) Waiting to run
Run Storybook a11y tests / Run Storybook a11y tests (light theme) (push) Blocked by required conditions
Run Storybook a11y tests / Run Storybook a11y tests (dark theme) (push) Blocked by required conditions
Swagger generated code / Detect whether code changed (push) Waiting to run
Swagger generated code / Verify committed API specs match (push) Blocked by required conditions
Dispatch sync to mirror / dispatch-job (push) Waiting to run
trigger-dashboard-search-e2e / trigger-search-e2e (push) Waiting to run
publish-kinds-next / main (push) Has been cancelled
Trivy Scan / trivy-scan (push) Has been cancelled
* upgraded github.com/grafana/grafana-plugin-sdk-go v0.283.0 => v0.284.0 * make update-workspace * apply fixes * nolint for FieldTypeNullableJSON instead * fmt * fix lint issues
191 lines
4.8 KiB
Go
191 lines
4.8 KiB
Go
//go:build !arm
|
|
|
|
package sql
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"math"
|
|
"strings"
|
|
|
|
mysql "github.com/dolthub/go-mysql-server/sql"
|
|
"github.com/dolthub/go-mysql-server/sql/types"
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
)
|
|
|
|
// FrameTable fulfills the mysql.Table interface for a data.Frame.
|
|
type FrameTable struct {
|
|
Frame *data.Frame
|
|
schema mysql.Schema
|
|
}
|
|
|
|
// Name implements the sql.Nameable interface
|
|
func (ft *FrameTable) Name() string {
|
|
return ft.Frame.RefID
|
|
}
|
|
|
|
// String implements the fmt.Stringer interface
|
|
func (ft *FrameTable) String() string {
|
|
return ft.Name()
|
|
}
|
|
|
|
func SchemaFromFrame(frame *data.Frame) mysql.Schema {
|
|
schema := make(mysql.Schema, len(frame.Fields))
|
|
|
|
for i, field := range frame.Fields {
|
|
schema[i] = &mysql.Column{
|
|
Name: field.Name,
|
|
Type: convertDataType(field.Type()),
|
|
Nullable: field.Type().Nullable(),
|
|
Source: strings.ToLower(frame.RefID),
|
|
}
|
|
}
|
|
|
|
return schema
|
|
}
|
|
|
|
// Schema implements the mysql.Table interface
|
|
func (ft *FrameTable) Schema() mysql.Schema {
|
|
if ft.schema == nil {
|
|
ft.schema = SchemaFromFrame(ft.Frame)
|
|
}
|
|
return ft.schema
|
|
}
|
|
|
|
// Collation implements the mysql.Table interface
|
|
func (ft *FrameTable) Collation() mysql.CollationID {
|
|
return mysql.Collation_Unspecified
|
|
}
|
|
|
|
// Partitions implements the mysql.Table interface
|
|
func (ft *FrameTable) Partitions(ctx *mysql.Context) (mysql.PartitionIter, error) {
|
|
return &noopPartitionIter{}, nil
|
|
}
|
|
|
|
// PartitionRows implements the mysql.Table interface
|
|
func (ft *FrameTable) PartitionRows(ctx *mysql.Context, _ mysql.Partition) (mysql.RowIter, error) {
|
|
return &rowIter{ft: ft, row: 0}, nil
|
|
}
|
|
|
|
type rowIter struct {
|
|
ft *FrameTable
|
|
row int
|
|
}
|
|
|
|
func (ri *rowIter) Next(ctx *mysql.Context) (mysql.Row, error) {
|
|
// We assume each field in the Frame has the same number of rows.
|
|
numRows := 0
|
|
if len(ri.ft.Frame.Fields) > 0 {
|
|
numRows = ri.ft.Frame.Fields[0].Len()
|
|
}
|
|
|
|
// If we've already exhausted all rows, return EOF
|
|
if ri.row >= numRows {
|
|
return nil, io.EOF
|
|
}
|
|
|
|
// Construct a Row (which is []interface{} under the hood) by pulling
|
|
// the value from each column at the current row index.
|
|
row := make(mysql.Row, len(ri.ft.Frame.Fields))
|
|
for colIndex, field := range ri.ft.Frame.Fields {
|
|
if field.NilAt(ri.row) {
|
|
continue
|
|
}
|
|
val, _ := field.ConcreteAt(ri.row)
|
|
switch v := val.(type) {
|
|
case float32:
|
|
if math.IsNaN(float64(v)) || math.IsInf(float64(v), 0) {
|
|
continue
|
|
}
|
|
case float64:
|
|
if math.IsNaN(v) || math.IsInf(v, 0) {
|
|
continue
|
|
}
|
|
}
|
|
|
|
// If the field is JSON, convert json.RawMessage to types.JSONDocument
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
doc, inRange, err := types.JSON.Convert(ctx, raw)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to convert json.RawMessage to JSONDocument: %w", err)
|
|
}
|
|
if !inRange {
|
|
return nil, fmt.Errorf("invalid JSON value detected at row %d, column %s: value required type coercion", ri.row, ri.ft.Frame.Fields[colIndex].Name)
|
|
}
|
|
val = doc
|
|
}
|
|
|
|
row[colIndex] = val
|
|
}
|
|
|
|
ri.row++
|
|
return row, nil
|
|
}
|
|
|
|
// Close implements the mysql.RowIter interface.
|
|
// In this no-op example, there isn't anything to do here.
|
|
func (ri *rowIter) Close(*mysql.Context) error {
|
|
return nil
|
|
}
|
|
|
|
type noopPartitionIter struct {
|
|
done bool
|
|
}
|
|
|
|
func (i *noopPartitionIter) Next(*mysql.Context) (mysql.Partition, error) {
|
|
if !i.done {
|
|
i.done = true
|
|
return noopParition, nil
|
|
}
|
|
return nil, io.EOF
|
|
}
|
|
|
|
func (i *noopPartitionIter) Close(*mysql.Context) error {
|
|
return nil
|
|
}
|
|
|
|
var noopParition = partition(nil)
|
|
|
|
type partition []byte
|
|
|
|
func (p partition) Key() []byte {
|
|
return p
|
|
}
|
|
|
|
// Helper function to convert data.FieldType to types.Type
|
|
func convertDataType(fieldType data.FieldType) mysql.Type {
|
|
switch fieldType {
|
|
case data.FieldTypeInt8, data.FieldTypeNullableInt8:
|
|
return types.Int8
|
|
case data.FieldTypeUint8, data.FieldTypeNullableUint8:
|
|
return types.Uint8
|
|
case data.FieldTypeInt16, data.FieldTypeNullableInt16:
|
|
return types.Int16
|
|
case data.FieldTypeUint16, data.FieldTypeNullableUint16:
|
|
return types.Uint16
|
|
case data.FieldTypeInt32, data.FieldTypeNullableInt32:
|
|
return types.Int32
|
|
case data.FieldTypeUint32, data.FieldTypeNullableUint32:
|
|
return types.Uint32
|
|
case data.FieldTypeInt64, data.FieldTypeNullableInt64:
|
|
return types.Int64
|
|
case data.FieldTypeUint64, data.FieldTypeNullableUint64:
|
|
return types.Uint64
|
|
case data.FieldTypeFloat32, data.FieldTypeNullableFloat32:
|
|
return types.Float32
|
|
case data.FieldTypeFloat64, data.FieldTypeNullableFloat64:
|
|
return types.Float64
|
|
case data.FieldTypeString, data.FieldTypeNullableString:
|
|
return types.Text
|
|
case data.FieldTypeBool, data.FieldTypeNullableBool:
|
|
return types.Boolean
|
|
case data.FieldTypeTime, data.FieldTypeNullableTime:
|
|
return types.Timestamp
|
|
case data.FieldTypeJSON, data.FieldTypeNullableJSON: //nolint:staticcheck
|
|
return types.JSON
|
|
default:
|
|
fmt.Printf("------- Unsupported field type: %v", fieldType)
|
|
return types.JSON
|
|
}
|
|
}
|