Skip to content

Commit 5217f44

Browse files
committed
Add test for PIVOT with SELECT *
1 parent 9480b28 commit 5217f44

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

test/test490.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
} else {
5+
// Assume running in browser with alasql loaded globally
6+
var assert = chai.assert;
7+
}
8+
9+
describe.skip('Test 490 - PIVOT with SELECT *', function () {
10+
const test = '490';
11+
12+
// Define the test data once
13+
const data = [
14+
{ VendorId: 'SPIKE', IncomeDay: 'FRI', IncomeAmount: 100 },
15+
{ VendorId: 'SPIKE', IncomeDay: 'MON', IncomeAmount: 300 },
16+
{ VendorId: 'FREDS', IncomeDay: 'SUN', IncomeAmount: 400 },
17+
{ VendorId: 'SPIKE', IncomeDay: 'WED', IncomeAmount: 500 },
18+
{ VendorId: 'SPIKE', IncomeDay: 'TUE', IncomeAmount: 200 },
19+
{ VendorId: 'JOHNS', IncomeDay: 'WED', IncomeAmount: 900 },
20+
{ VendorId: 'SPIKE', IncomeDay: 'FRI', IncomeAmount: 100 },
21+
{ VendorId: 'JOHNS', IncomeDay: 'MON', IncomeAmount: 300 },
22+
{ VendorId: 'SPIKE', IncomeDay: 'SUN', IncomeAmount: 400 },
23+
{ VendorId: 'JOHNS', IncomeDay: 'FRI', IncomeAmount: 300 },
24+
{ VendorId: 'FREDS', IncomeDay: 'TUE', IncomeAmount: 500 },
25+
{ VendorId: 'FREDS', IncomeDay: 'TUE', IncomeAmount: 200 },
26+
{ VendorId: 'SPIKE', IncomeDay: 'MON', IncomeAmount: 900 },
27+
{ VendorId: 'FREDS', IncomeDay: 'FRI', IncomeAmount: 900 },
28+
{ VendorId: 'FREDS', IncomeDay: 'MON', IncomeAmount: 500 },
29+
{ VendorId: 'JOHNS', IncomeDay: 'SUN', IncomeAmount: 600 },
30+
{ VendorId: 'SPIKE', IncomeDay: 'FRI', IncomeAmount: 300 },
31+
{ VendorId: 'SPIKE', IncomeDay: 'WED', IncomeAmount: 500 },
32+
{ VendorId: 'SPIKE', IncomeDay: 'FRI', IncomeAmount: 300 },
33+
{ VendorId: 'JOHNS', IncomeDay: 'THU', IncomeAmount: 800 },
34+
{ VendorId: 'JOHNS', IncomeDay: 'SAT', IncomeAmount: 800 },
35+
{ VendorId: 'SPIKE', IncomeDay: 'TUE', IncomeAmount: 100 },
36+
{ VendorId: 'SPIKE', IncomeDay: 'THU', IncomeAmount: 300 },
37+
{ VendorId: 'FREDS', IncomeDay: 'WED', IncomeAmount: 500 },
38+
{ VendorId: 'SPIKE', IncomeDay: 'SAT', IncomeAmount: 100 },
39+
{ VendorId: 'FREDS', IncomeDay: 'SAT', IncomeAmount: 500 },
40+
{ VendorId: 'FREDS', IncomeDay: 'THU', IncomeAmount: 800 },
41+
{ VendorId: 'JOHNS', IncomeDay: 'TUE', IncomeAmount: 600 },
42+
];
43+
44+
before(function () {
45+
alasql('CREATE DATABASE test' + test);
46+
alasql('USE test' + test);
47+
});
48+
49+
after(function () {
50+
alasql('DROP DATABASE test' + test);
51+
});
52+
53+
it('A) PIVOT with SELECT * and AVG aggregation', function () {
54+
var res = alasql('SELECT * FROM ? PIVOT (AVG(IncomeAmount) FOR IncomeDay)', [data]);
55+
56+
var expectedResult = [
57+
{ VendorId: 'SPIKE', FRI: 200, MON: 600, WED: 500, TUE: 150, SUN: 400, THU: 300, SAT: 100 },
58+
{ VendorId: 'FREDS', SUN: 400, TUE: 350, FRI: 900, MON: 500, WED: 500, SAT: 500, THU: 800 },
59+
{ VendorId: 'JOHNS', WED: 900, MON: 300, FRI: 300, SUN: 600, THU: 800, SAT: 800, TUE: 600 },
60+
];
61+
62+
assert.deepEqual(
63+
res,
64+
expectedResult,
65+
'PIVOT with SELECT * and AVG should produce the correct aggregated table'
66+
);
67+
});
68+
69+
it('B) PIVOT with SELECT * and SUM aggregation', function () {
70+
var res = alasql('SELECT * FROM ? PIVOT (SUM(IncomeAmount) FOR IncomeDay)', [data]);
71+
72+
var expectedResult = [
73+
{ VendorId: 'SPIKE', FRI: 800, MON: 1200, SUN: 400, WED: 1000, TUE: 300, THU: 300, SAT: 100 },
74+
{ VendorId: 'FREDS', SUN: 400, TUE: 700, FRI: 900, MON: 500, WED: 500, SAT: 500, THU: 800 },
75+
{ VendorId: 'JOHNS', WED: 900, MON: 300, FRI: 300, SUN: 600, THU: 800, SAT: 800, TUE: 600 },
76+
];
77+
78+
assert.deepEqual(
79+
res,
80+
expectedResult,
81+
'PIVOT with SELECT * and SUM should produce the correct aggregated table'
82+
);
83+
});
84+
});

0 commit comments

Comments
 (0)