-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sriram <153843+yesoreyeram@users.noreply.github.com> Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Co-authored-by: Ward Bekker <ward@equanimity.nl>
- Loading branch information
1 parent
6d58f49
commit e6b5890
Showing
46 changed files
with
2,949 additions
and
2,723 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
"countif", | ||
"csvframer", | ||
"dataframe", | ||
"dataplane", | ||
"datapoints", | ||
"dataproxy", | ||
"datasource", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package dataplane | ||
|
||
import "github.com/grafana/grafana-plugin-sdk-go/data" | ||
|
||
type fieldTypeCount struct { | ||
nullableFields int | ||
nonNullableFields int | ||
unknownFields int | ||
numericFields int | ||
boolFields int | ||
stringFields int | ||
timeFields int | ||
jsonFields int | ||
enumFields int | ||
} | ||
|
||
func getFieldTypesCount(frame *data.Frame) fieldTypeCount { | ||
res := fieldTypeCount{ | ||
nullableFields: 0, | ||
nonNullableFields: 0, | ||
unknownFields: 0, | ||
numericFields: 0, | ||
boolFields: 0, | ||
stringFields: 0, | ||
timeFields: 0, | ||
jsonFields: 0, | ||
} | ||
for _, field := range frame.Fields { | ||
if field == nil { | ||
continue | ||
} | ||
if field.Nullable() { | ||
res.nullableFields++ | ||
} | ||
if !field.Nullable() { | ||
res.nonNullableFields++ | ||
} | ||
if field.Type().Numeric() { | ||
res.numericFields++ | ||
continue | ||
} | ||
if field.Type().Time() { | ||
res.timeFields++ | ||
continue | ||
} | ||
if field.Type().JSON() { | ||
res.jsonFields++ | ||
continue | ||
} | ||
switch field.Type() { | ||
case data.FieldTypeBool, | ||
data.FieldTypeNullableBool: | ||
res.boolFields++ | ||
case data.FieldTypeString, | ||
data.FieldTypeNullableString: | ||
res.stringFields++ | ||
case data.FieldTypeEnum, | ||
data.FieldTypeNullableEnum: | ||
res.enumFields++ | ||
default: | ||
res.unknownFields++ | ||
} | ||
} | ||
return res | ||
} | ||
|
||
// CanBeNumericWide asserts if the data frame comply with numeric wide type | ||
// https://grafana.com/developers/dataplane/numeric#numeric-wide-format-numericwide | ||
func CanBeNumericWide(frame *data.Frame) bool { | ||
if frame == nil { | ||
return false | ||
} | ||
ftCount := getFieldTypesCount(frame) | ||
rowLen, err := frame.RowLen() | ||
if err != nil { | ||
return false | ||
} | ||
if rowLen <= 1 && (ftCount.numericFields+ftCount.boolFields) > 0 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// CanBeNumericLong asserts if the data frame comply with numeric long type | ||
// https://grafana.com/developers/dataplane/numeric#numeric-long-format-numericlong-sql-table-like | ||
func CanBeNumericLong(frame *data.Frame) bool { | ||
if frame == nil { | ||
return false | ||
} | ||
ftCount := getFieldTypesCount(frame) | ||
rowLen, err := frame.RowLen() | ||
if err != nil { | ||
return false | ||
} | ||
if rowLen == 1 && ftCount.numericFields > 0 && ftCount.stringFields == 0 { | ||
return true | ||
} | ||
if rowLen > 1 && ftCount.numericFields > 0 && ftCount.stringFields > 0 { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.