Skip to content

[WIP] Implement LET clause similar to OrientDB - #2535

Draft
mathiasrw with Copilot wants to merge 3 commits into
developfrom
copilot/implement-let-clause
Draft

[WIP] Implement LET clause similar to OrientDB#2535
mathiasrw with Copilot wants to merge 3 commits into
developfrom
copilot/implement-let-clause

Conversation

Copilot AI commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
  • Inspect contribution guidance, test conventions, and the SELECT execution pipeline
  • Add a focused regression test for issue Implement LET clause (like in OrientDB) #210 covering LET before WHERE/SELECT
  • Implement minimal parser and execution support for SELECT ... LET ...
  • Run targeted tests and format touched files
  • Run review, security checks, and secret scanning before finalizing

@mathiasrw

Copy link
Copy Markdown
Member

@copilot continue

Copilot AI commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot continue

Addressed in a5ce153.

@mathiasrw

Copy link
Copy Markdown
Member

@copilot the inital comment indicates that some tasks are not completed. Can you please confirm?

Copilot AI commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the inital comment indicates that some tasks are not completed. Can you please confirm?

The original checklist is stale. The regression test, SELECT LET support, targeted validation, secret scan, and final review/security checks were completed in a5ce153.

Comment thread src/39dojoin.js Outdated
Comment on lines +16 to +26
try {
if (query.wherefn(scope, query.params, alasql)) {
// If there is a GROUP BY then pipe to grouping function
if (query.groupfn) {
query.groupfn(scope, query.params, alasql);
} else {
query.data.push(query.selectfn(scope, query.params, alasql));
}
}
} finally {
query.params = originalParams;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we expecting the commands to error? What is the concern? There is a performance hit on this BUT worse, it seems like we dont trust our data structure of our logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in ee4e5e7: LET now restores only the touched variables after evaluation instead of cloning/swapping the whole params object.

Comment thread src/40select.js Outdated
Comment on lines +97 to +101
.map(function (assignment) {
return (
assignment.method + assignment.variable + ' = ' + assignment.expression.toString()
);
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the most efficient way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tightened in ee4e5e7 to a small shared formatter helper.

Comment thread src/40select.js
Comment on lines +640 to 668

compileLet(query) {
if (!this.let || this.let.length === 0) return;

const lets = this.let
.map(assignment => {
const target =
assignment.method === '@'
? `alasql.vars[${JSON.stringify(assignment.variable)}]`
: `params[${JSON.stringify(assignment.variable)}]`;
return `${target}=${assignment.expression.toJS('p', query.defaultTableid, query.defcols)};`;
})
.join('');

query.letfn = new Function(
'p,params,alasql',
`var y;
if(Array.isArray(params)) {
params = Object.assign([], params);
} else if(params && typeof params === 'object') {
params = Object.assign({}, params);
} else {
params = {};
}
${lets}
return params;`
);
}
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we normally move things out of the main loop? Also, seems like a lot of code for such a change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reduced in ee4e5e7: LET now precompiles only the value expressions and applies/restores touched variables at evaluation time.

Comment thread test/test210.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need many more exampled and edgecases covered.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Expanded in ee4e5e7 with coverage for filtering/selection, restoring existing named params, GROUP BY/HAVING, and cleanup of temporary @ variables.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
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.

Implement LET clause (like in OrientDB)

2 participants