Skip to content

Commit

Permalink
Regression of "SELECT query (a AS b, b AS c)" to fix #1820 (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrutter committed Nov 13, 2023
1 parent e54b224 commit 37ffe88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/38query.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ function queryfn3(query) {
var d = query.selectgfn(g, query.params, alasql);

for (const key in query.groupColumns) {
if (query.groupColumns[key] !== key && d[query.groupColumns[key]])
// ony remove columns where the alias is also not a column in the result
if (query.groupColumns[key] !== key && d[query.groupColumns[key]] && !query.groupColumns[query.groupColumns[key]]){
delete d[query.groupColumns[key]];
}
}
query.data.push(d);
}
Expand Down
26 changes: 26 additions & 0 deletions test/test1820.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
} else {
__dirname = '.';
}

describe('Test 1820 - SELECT query (a AS b, b AS c)', function () {

it('1. Select query where alias of one column is also a column name in the result set', function (done) {
let item1 = { a: 1, b: "hello" };
let item2 = { a: 2, b: "" };

var res = alasql('SELECT a as b, b as c FROM ? GROUP BY a,b', [[item1, item2]]);

assert.deepEqual(res, [{
b: 1,
c: "hello"
}, {
b: 2,
c: ""
}]);

done();
});
});

0 comments on commit 37ffe88

Please sign in to comment.