-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprepareQueryExplain.test.ts
127 lines (117 loc) · 3.92 KB
/
prepareQueryExplain.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import type {SimplifiedPlanItem} from '../../store/reducers/query/types';
import type {SimplifiedNode} from '../../types/api/query';
import {prepareSimplifiedPlan} from '../prepareQueryExplain';
describe('prepareSimplifiedPlan', () => {
test('should handle empty input', () => {
const plans: SimplifiedNode[] = [];
const result = prepareSimplifiedPlan(plans);
expect(result).toEqual([]);
});
test('should handle single node without children', () => {
const plans: SimplifiedNode[] = [
{
Operators: [
{
['A-Cpu']: 10,
['A-Rows']: 100,
['E-Cost']: '20',
['E-Rows']: '200',
['E-Size']: '50',
['Name']: 'TestNode',
testParams: {foo: 'bar'},
},
],
},
];
const expected: SimplifiedPlanItem[] = [
{
name: 'TestNode',
operationParams: {testParams: {foo: 'bar'}},
aCpu: 10,
aRows: 100,
eCost: '20',
eRows: '200',
eSize: '50',
children: [],
},
];
const result = prepareSimplifiedPlan(plans);
expect(result).toEqual(expected);
});
test('should handle nested nodes', () => {
const plans: SimplifiedNode[] = [
{
Operators: [
{
['A-Cpu']: 10,
['A-Rows']: 100,
['E-Cost']: '20',
['E-Rows']: '200',
['E-Size']: '50',
['Name']: 'RootNode',
testParams: {foo: 'bar'},
},
],
Plans: [
{
Operators: [
{
['A-Cpu']: 5,
['A-Rows']: 50,
['E-Cost']: '10',
['E-Rows']: '100',
['E-Size']: '25',
['Name']: 'ChildNode',
testParams: {foo: 'bar'},
},
],
},
],
},
];
const expected: SimplifiedPlanItem[] = [
{
name: 'RootNode',
operationParams: {testParams: {foo: 'bar'}},
aCpu: 10,
aRows: 100,
eCost: '20',
eRows: '200',
eSize: '50',
children: [
{
name: 'ChildNode',
operationParams: {testParams: {foo: 'bar'}},
aCpu: 5,
aRows: 50,
eCost: '10',
eRows: '100',
eSize: '25',
children: [],
},
],
},
];
const result = prepareSimplifiedPlan(plans);
expect(result).toEqual(expected);
});
test('should handle nodes without operators', () => {
const plans: SimplifiedNode[] = [
{
PlanNodeId: 0,
'Node Type': 'Query',
PlanNodeType: 'Query',
Plans: [
{
PlanNodeId: 1,
'Node Type': 'TableScan',
PlanNodeType: 'TableScan',
},
],
},
];
const expected: SimplifiedPlanItem[] = [];
const result = prepareSimplifiedPlan(plans);
expect(result).toEqual(expected);
});
});