Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
cf6adb8b
Unverified
Commit
cf6adb8b
authored
Mar 11, 2020
by
Ryan McKinley
Committed by
GitHub
Mar 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support duplicate field names in arrow format (#22705)
parent
9824219a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
packages/grafana-data/src/dataframe/ArrowDataFrame.test.ts
+21
-1
packages/grafana-data/src/dataframe/ArrowDataFrame.ts
+21
-3
packages/grafana-data/src/dataframe/__snapshots__/ArrowDataFrame.test.ts.snap
+1
-1
packages/grafana-data/src/dataframe/__snapshots__/all_types.golden.arrow
+0
-0
No files found.
packages/grafana-data/src/dataframe/ArrowDataFrame.test.ts
View file @
cf6adb8b
...
...
@@ -71,7 +71,27 @@ describe('Read/Write arrow Table to DataFrame', () => {
expect
(
after
).
toEqual
(
before
);
});
test
(
'should parse output with dataframe'
,
()
=>
{
test
(
'should support duplicate field names'
,
()
=>
{
const
frame
=
toDataFrame
({
name
:
'Hello'
,
refId
:
'XYZ'
,
fields
:
[
{
name
:
'time'
,
config
:
{},
type
:
FieldType
.
time
,
values
:
[
1
,
2
,
3
]
},
{
name
:
'a'
,
values
:
[
1
,
2
,
3
]
},
{
name
:
'a'
,
values
:
[
'a'
,
'b'
,
'c'
]
},
],
});
const
table
=
grafanaDataFrameToArrowTable
(
frame
);
expect
(
table
.
length
).
toEqual
(
frame
.
length
);
// Now back to DataFrame
const
before
=
JSON
.
stringify
(
toDataFrameDTO
(
frame
),
null
,
2
);
const
after
=
JSON
.
stringify
(
toDataFrameDTO
(
arrowTableToDataFrame
(
table
)),
null
,
2
);
expect
(
after
).
toEqual
(
before
);
});
test
(
'should read all types'
,
()
=>
{
const
fullpath
=
path
.
resolve
(
__dirname
,
'./__snapshots__/all_types.golden.arrow'
);
const
arrow
=
fs
.
readFileSync
(
fullpath
);
const
table
=
Table
.
from
([
arrow
]);
...
...
packages/grafana-data/src/dataframe/ArrowDataFrame.ts
View file @
cf6adb8b
...
...
@@ -72,7 +72,7 @@ export function arrowTableToDataFrame(table: Table): ArrowDataFrame {
}
fields
.
push
({
name
:
col
.
name
,
name
:
stripFieldNamePrefix
(
col
.
name
)
,
type
,
values
,
config
:
parseOptionalMeta
(
col
.
metadata
.
get
(
'config'
))
||
{},
...
...
@@ -91,6 +91,17 @@ export function arrowTableToDataFrame(table: Table): ArrowDataFrame {
};
}
// fieldNamePrefixSep is the delimiter used with fieldNamePrefix.
const
fieldNamePrefixSep
=
'🦥: '
;
function
stripFieldNamePrefix
(
name
:
string
):
string
{
const
idx
=
name
.
indexOf
(
fieldNamePrefixSep
);
if
(
idx
>
0
)
{
return
name
.
substring
(
idx
+
fieldNamePrefixSep
.
length
);
}
return
name
;
}
function
toArrowVector
(
field
:
Field
):
ArrowVector
{
// OR: Float64Vector.from([1, 2, 3]));
...
...
@@ -117,10 +128,17 @@ export function grafanaDataFrameToArrowTable(data: DataFrame): Table {
if
(
table
instanceof
Table
)
{
return
table
as
Table
;
}
// Make sure the names are unique
const
names
=
new
Set
<
string
>
();
table
=
Table
.
new
(
data
.
fields
.
map
(
field
=>
{
const
column
=
Column
.
new
(
field
.
name
,
toArrowVector
(
field
));
data
.
fields
.
map
((
field
,
index
)
=>
{
let
name
=
field
.
name
;
if
(
names
.
has
(
field
.
name
))
{
name
=
`
${
index
}${
fieldNamePrefixSep
}${
field
.
name
}
`
;
}
names
.
add
(
name
);
const
column
=
Column
.
new
(
name
,
toArrowVector
(
field
));
if
(
field
.
labels
)
{
column
.
metadata
.
set
(
'labels'
,
JSON
.
stringify
(
field
.
labels
));
}
...
...
packages/grafana-data/src/dataframe/__snapshots__/ArrowDataFrame.test.ts.snap
View file @
cf6adb8b
...
...
@@ -103,7 +103,7 @@ Array [
]
`;
exports[`Read/Write arrow Table to DataFrame should
parse output with dataframe
1`] = `
exports[`Read/Write arrow Table to DataFrame should
read all types
1`] = `
Object {
"fields": Array [
Object {
...
...
packages/grafana-data/src/dataframe/__snapshots__/all_types.golden.arrow
View file @
cf6adb8b
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment