Skip to content

Fix: preserve query input when switching dataverse; replace leading USE statement (ASTERIXDB-3124)#44

Open
shishir-kuet wants to merge 1 commit intoapache:masterfrom
shishir-kuet:fix/ASTERIXDB-3124-schema-selection
Open

Fix: preserve query input when switching dataverse; replace leading USE statement (ASTERIXDB-3124)#44
shishir-kuet wants to merge 1 commit intoapache:masterfrom
shishir-kuet:fix/ASTERIXDB-3124-schema-selection

Conversation

@shishir-kuet
Copy link
Copy Markdown

This PR fixes an issue where selecting a different dataverse from the dropdown would overwrite the current query in the editor with a USE statement, causing loss of user input.

With this change, the query editor now preserves the existing query text when the dataverse selection changes. Instead of replacing the query, the logic updates or prepends the appropriate USE statement only when necessary.

🔧 Changes Made
Updated the dataverseSelected() handler in the Angular dashboard.
Preserved the existing query string instead of overwriting it.
Replaced the leading USE statement if present, otherwise prepended it.
Removed the USE statement when switching to Default or None.

✅ How to Test
Open the AsterixDB dashboard (Angular UI).
Enter a query in the editor (e.g., SELECT * FROM Metadata.Dataset;).
Change the dataverse using the dropdown.
Verify:
The existing query is preserved.
The USE ; statement is correctly updated or inserted.
Switching to Default removes any existing USE statement.

Copilot AI review requested due to automatic review settings March 26, 2026 20:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Angular dashboard query editor’s dataverse-switching behavior to avoid overwriting the user’s in-progress query, by updating (or removing) a leading USE <dataverse>; statement instead.

Changes:

  • Preserve existing queryString when changing the selected dataverse.
  • Replace an existing leading USE ...; statement if present, otherwise prepend a new one.
  • Remove a leading USE ...; when switching back to Default/None.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +537 to +549
const useStmt = 'USE ' + this.selected + ';\n';
let qs = this.queryString || '';
const leadingUseRegex = /^\s*USE\s+[^;]+;\s*/i;

if (this.selected === 'None' || this.selected === 'Default') {
qs = qs.replace(leadingUseRegex, '');
this.selected = 'Default';
} else {
this.queryString = 'USE ' + this.selected + '; \n' + this.queryString;
if (leadingUseRegex.test(qs)) {
qs = qs.replace(leadingUseRegex, useStmt);
} else {
qs = useStmt + qs;
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

leadingUseRegex only matches a USE ...; that appears at the very start of the query (ignoring whitespace). If the user has a leading SQL++ comment/header (e.g., -- ... or /* ... */) before the USE statement, the regex won’t match and switching dataverses will prepend a new USE while leaving the old one in place, potentially resulting in the query still running under the old dataverse (since the later USE can override). Consider expanding the match to allow leading comments before the first USE, or stripping/replacing the first USE statement that occurs before any non-comment tokens.

Copilot uses AI. Check for mistakes.
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