Skip to content

Conversation

@shhreya13
Copy link

This PR fixes issue #2070, where
RECORDSET OF SELECT t.*, computed_column FROM ? t
returned only the computed column (rn) in the columns metadata, omitting those from t.*.

🧠 Summary of Fix

  • Ensures that all columns from t.* are correctly included in the columns array
    when additional computed columns are present.
  • Updated logic in src/40select.js to merge both sets of columns.

🧪 Test

Verified manually using:

const data = [{a:1,b:10}, {a:2,b:20}, {a:1,b:30}];
const res = alasql('RECORDSET OF SELECT t.*, 1 as rn FROM ? t', [data]);
console.log(res.columns.map(c => c.columnid));
// Expected output: ['a', 'b', 'rn']

Copy link
Member

@mathiasrw mathiasrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way too many things changed in this PR. But lets lets work with it now that you have created it.

You shuold run yarn test locally to confirm things are working. 4 tests are broken.

The PR also needs to add new test file named test2070 that verifies that the problem in #2070 is not accidentally reintroduced in the future.

}

// ✅ Custom RECORDSET class
yy.Recordset = class Recordset extends yy.Select {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like new code.

When/why are we using this?

return res;
}

// ✅ Custom RECORDSET class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comments. Make the code speak.

}, {});

case 'RECORDSET': {
// ✅ FIX: include all keys from t.* + computed columns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove coments. Let. the code. speak.

const keyIndex = columns?.[0]?.columnid || Object.keys(res[0])[0];
const valIndex = columns?.[1]?.columnid || Object.keys(res[0])[1];
return res.reduce((acc, row) => {
acc[row[keyIndex]] = row[valIndex];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An improvement. Nice.

But not really related to the PR. In the future please make a seperate PR with things not related to the PR. Lets just keep it for now.


return ar;
const key = columns?.[0]?.columnid || Object.keys(res[0])[0];
return res.map(r => r[key]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice with an improvement. But not really related to the PR. In the future please make a seperate PR with things not related to the PR. Lets just keep it for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ?? instead of ||


query.defcols = this.compileDefCols(query, databaseid);

// 1. Compile FROM clause
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep comment

query.modifier = this.modifier;

query.database = db;
// 0. Precompile whereexists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave comment

);
}

// Compile SELECT statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep comment

s += ' UNION ALL ' + (this.corresponding ? 'CORRESPONDING ' : '') + this.unionall.toString();
}
if (this.except) {
if (this.unionall)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid multi line if statement without brackets (even if there is only one statement)

.map(jn => {
let ss = ' ';
if (jn.joinmode) ss += jn.joinmode + ' ';
if (jn.table) ss += 'JOIN ' + jn.table.toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use {...} when involving an else

@mathiasrw
Copy link
Member

Please run yarn format-all and push again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants