Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
12dc2a49
Commit
12dc2a49
authored
6 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add test for pivot sort inference
parent
1e82a8f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/lib/data_grid.js
+1
-2
1 addition, 2 deletions
frontend/src/metabase/lib/data_grid.js
frontend/test/lib/data_grid.unit.spec.js
+50
-3
50 additions, 3 deletions
frontend/test/lib/data_grid.unit.spec.js
with
51 additions
and
5 deletions
frontend/src/metabase/lib/data_grid.js
+
1
−
2
View file @
12dc2a49
...
...
@@ -29,8 +29,7 @@ export function pivot(data, normalCol, pivotCol, cellCol) {
let
pivotColIdx
=
pivotValues
.
lastIndexOf
(
data
.
rows
[
j
][
pivotCol
]);
pivotedRows
[
normalColIdx
][
0
]
=
data
.
rows
[
j
][
normalCol
];
// NOTE: we are hard coding the expectation that the metric is in the 3rd column
pivotedRows
[
normalColIdx
][
pivotColIdx
]
=
data
.
rows
[
j
][
2
];
pivotedRows
[
normalColIdx
][
pivotColIdx
]
=
data
.
rows
[
j
][
cellCol
];
}
// provide some column metadata to maintain consistency
...
...
This diff is collapsed.
Click to expand it.
frontend/test/lib/data_grid.unit.spec.js
+
50
−
3
View file @
12dc2a49
...
...
@@ -24,8 +24,33 @@ describe("data_grid", () => {
[
"
b
"
,
"
y
"
,
5
],
[
"
b
"
,
"
z
"
,
6
],
]);
let
pivotedData
=
pivot
(
data
);
expect
(
pivotedData
.
cols
.
length
).
toEqual
(
3
);
let
pivotedData
=
pivot
(
data
,
0
,
1
,
2
);
expect
(
pivotedData
.
cols
.
map
(
col
=>
col
.
display_name
)).
toEqual
([
"
Dimension 1
"
,
"
x
"
,
"
y
"
,
"
z
"
,
]);
expect
(
pivotedData
.
rows
.
map
(
row
=>
[...
row
])).
toEqual
([
[
"
a
"
,
1
,
2
,
3
],
[
"
b
"
,
4
,
5
,
6
],
]);
});
it
(
"
should pivot values correctly with columns flipped
"
,
()
=>
{
let
data
=
makeData
([
[
"
a
"
,
"
x
"
,
1
],
[
"
a
"
,
"
y
"
,
2
],
[
"
a
"
,
"
z
"
,
3
],
[
"
b
"
,
"
x
"
,
4
],
[
"
b
"
,
"
y
"
,
5
],
[
"
b
"
,
"
z
"
,
6
],
]);
let
pivotedData
=
pivot
(
data
,
1
,
0
,
2
);
expect
(
pivotedData
.
cols
.
map
(
col
=>
col
.
display_name
)).
toEqual
([
"
Dimension 2
"
,
"
a
"
,
"
b
"
,
]);
expect
(
pivotedData
.
rows
.
map
(
row
=>
[...
row
])).
toEqual
([
[
"
x
"
,
1
,
4
],
[
"
y
"
,
2
,
5
],
...
...
@@ -35,7 +60,8 @@ describe("data_grid", () => {
it
(
"
should not return null column names from null values
"
,
()
=>
{
let
data
=
makeData
([[
null
,
null
,
1
]]);
let
pivotedData
=
pivot
(
data
);
let
pivotedData
=
pivot
(
data
,
0
,
1
,
2
);
console
.
log
(
"
pivotedData
"
,
pivotedData
);
expect
(
pivotedData
.
rows
.
length
).
toEqual
(
1
);
expect
(
pivotedData
.
cols
.
length
).
toEqual
(
2
);
expect
(
pivotedData
.
cols
[
0
].
name
).
toEqual
(
jasmine
.
any
(
String
));
...
...
@@ -43,5 +69,26 @@ describe("data_grid", () => {
expect
(
pivotedData
.
cols
[
1
].
name
).
toEqual
(
jasmine
.
any
(
String
));
expect
(
pivotedData
.
cols
[
1
].
display_name
).
toEqual
(
jasmine
.
any
(
String
));
});
it
(
"
should infer sort order of sparse data correctly
"
,
()
=>
{
let
data
=
makeData
([
[
"
a
"
,
"
x
"
,
1
],
[
"
a
"
,
"
z
"
,
3
],
[
"
b
"
,
"
x
"
,
4
],
[
"
b
"
,
"
y
"
,
5
],
[
"
b
"
,
"
z
"
,
6
],
]);
let
pivotedData
=
pivot
(
data
,
0
,
1
,
2
);
expect
(
pivotedData
.
cols
.
map
(
col
=>
col
.
display_name
)).
toEqual
([
"
Dimension 1
"
,
"
x
"
,
"
y
"
,
"
z
"
,
]);
expect
(
pivotedData
.
rows
.
map
(
row
=>
[...
row
])).
toEqual
([
[
"
a
"
,
1
,
null
,
3
],
[
"
b
"
,
4
,
5
,
6
],
]);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment