Copilot commented on code in PR #44:
URL: https://github.com/apache/asterixdb/pull/44#discussion_r2997442022


##########
asterixdb/asterix-dashboard/src/node/src/app/dashboard/query/input.component.ts:
##########
@@ -532,16 +532,26 @@
     }
 
     dataverseSelected() {
-      if (this.selected == undefined) {
-        this.queryString = 'None';
-      } else if (this.selected === 'None' || this.selected === 'Default') {
-        this.queryString = '';
+      if (this.selected == undefined) return;
+
+      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;
+        }

Review Comment:
   `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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to