Skip to content

feat(extensions): Enhances SQL Lab API#37642

Merged
michael-s-molina merged 4 commits intoapache:masterfrom
michael-s-molina:sqllab-api
Feb 4, 2026
Merged

feat(extensions): Enhances SQL Lab API#37642
michael-s-molina merged 4 commits intoapache:masterfrom
michael-s-molina:sqllab-api

Conversation

@michael-s-molina
Copy link
Member

@michael-s-molina michael-s-molina commented Feb 3, 2026

Summary

This PR extends the SQL Lab API with new capabilities for tab management, query execution, and editor manipulation.

New APIs

Editor Access (now available via Tab.getEditor())

  • Tab.getEditor() - Async method to get the editor handle
  • Editor.getValue() - Get the current SQL content
  • Editor.setValue(sql) - Replace the editor content
  • Editor.insertText(text) - Insert text at cursor position
  • Editor.focus() - Focus the editor
  • Editor.getCursorPosition() - Get current cursor position
  • Editor.getSelections() - Get current selections
  • Editor.setAnnotations(annotations) - Set error/warning markers
  • Editor.registerCompletionProvider(provider) - Register custom autocomplete

Tab Management

  • createTab(options?) - Create a new query editor tab with optional SQL, title, database, catalog, and schema
  • closeTab(tabId) - Close a specific tab
  • setActiveTab(tabId) - Switch to a specific tab
  • onDidCreateTab - Event fired when a new tab is created

Query Execution

  • executeQuery(options?) - Execute the SQL query in the current tab
  • cancelQuery(queryId) - Cancel a running query

Tab Context

  • setDatabase(databaseId) - Set the database for the current tab
  • setCatalog(catalog) - Set the catalog for the current tab
  • setSchema(schema) - Set the schema for the current tab
  • Tab.databaseId, Tab.catalog, Tab.schema - Direct access to tab context

API Changes

Tab Interface

// Before
interface Tab {
  id: string;
  title: string;
  editor: Editor;  // sync property with content, databaseId, catalog, schema
  panels: Panel[];
}

// After
interface Tab {
  id: string;
  title: string;
  databaseId: number;
  catalog: string | null;
  schema: string | null;
  getEditor(): Promise<Editor>;  // async method returning EditorHandle
  panels: Panel[];
}

Editor Interface

// Before
interface Editor {
  content: string;
  databaseId: number;
  catalog: string | null;
  schema: string;
  table: string | null;
}

// After - extends EditorHandle with full editor manipulation
interface Editor extends EditorHandle {
  // Inherited: getValue(), setValue(), insertText(), focus(),
  // getCursorPosition(), getSelections(), setAnnotations(), etc.
}

Migration Example

// Before
const tab = sqlLab.getCurrentTab();
const sql = tab.editor.content;
const dbId = tab.editor.databaseId;

// After
const tab = sqlLab.getCurrentTab();
const editor = await tab.getEditor();
const sql = editor.getValue();
const dbId = tab.databaseId;

Documentation

Improved JSDoc documentation for the Editor API in packages/superset-core/src/api/editors.ts:

  • EditorHandle - Comprehensive documentation for all methods including behavior details, edge cases, and parameter descriptions
  • Position, Range, Selection - Added examples and clarified zero-based indexing
  • EditorAnnotation - Added example and severity color explanations
  • EditorHotkey - Documented key combination format with example
  • CompletionProvider - Added example showing async table completion
  • executeCommand() - Noted that command names are editor-specific (Ace vs Monaco)

Test Plan

  • Create new tabs via createTab() with various options
  • Verify default tab naming "Untitled Query N"
  • Close and switch tabs via API
  • Execute and stop queries via API
  • Change database/catalog/schema via API
  • Access editor via getEditor() and manipulate content

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@michael-s-molina michael-s-molina self-assigned this Feb 3, 2026
@michael-s-molina michael-s-molina moved this from To Do to In Review in Superset Extensions Feb 3, 2026
@dosubot dosubot bot added api Related to the REST API sqllab Namespace | Anything related to the SQL Lab labels Feb 3, 2026
@netlify
Copy link

netlify bot commented Feb 3, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit bbc5ccd
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69823a220b7e3a00080062e7
😎 Deploy Preview https://deploy-preview-37642--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

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

Code Review Agent Run #07fa32

Actionable Suggestions - 5
  • superset-frontend/packages/superset-core/src/api/sqlLab.ts - 2
  • superset-frontend/src/core/sqlLab/index.ts - 2
  • superset-frontend/packages/superset-core/src/api/editors.ts - 1
    • Incorrect zero-based indexing in JSDoc example · Line 94-101
Additional Suggestions - 1
  • superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx - 1
    • Missing handle re-registration · Line 257-279
      If queryEditorId changes after the editor is ready, the handle isn't re-registered under the new ID, potentially breaking SQL Lab API access. The added useEffect ensures re-registration.
      Code suggestion
       @@ -278,1 +278,6 @@
      - 
      +   // Re-register editor handle when queryEditorId changes
      +   useEffect(() => {
      +     if (editorHandleRef.current) {
      +       registerEditorHandle(queryEditorId, editorHandleRef.current);
      +     }
      +   }, [queryEditorId]);
      + 
Review Details
  • Files reviewed - 6 · Commit Range: bbc5ccd..bbc5ccd
    • superset-frontend/packages/superset-core/src/api/editors.ts
    • superset-frontend/packages/superset-core/src/api/sqlLab.ts
    • superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx
    • superset-frontend/src/core/sqlLab/index.ts
    • superset-frontend/src/core/sqlLab/models.ts
    • superset-frontend/src/core/utils.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions bot removed the api Related to the REST API label Feb 3, 2026
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 3, 2026

Code Review Agent Run #a6163f

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: bbc5ccd..00ea913
    • superset-frontend/packages/superset-core/src/api/editors.ts
    • superset-frontend/packages/superset-core/src/api/sqlLab.ts
    • superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx
    • superset-frontend/src/core/sqlLab/index.ts
    • superset-frontend/src/core/sqlLab/models.ts
    • superset-frontend/src/core/utils.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Copy link
Member

@msyavuz msyavuz left a comment

Choose a reason for hiding this comment

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

Looks good with a small nit! Curious to see how this changes your example editor implementations?

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Feb 4, 2026

Curious to see how this changes your example editor implementations?

@msyavuz It does not change the editor implementations as the editor API didn't change. What changed was that the editor handle API is now available for extensions and built-in features.

@msyavuz
Copy link
Member

msyavuz commented Feb 4, 2026

@michael-s-molina Yeah, i am using your extensions repo as a documentation so i was curious to see how you would use the handle api

@michael-s-molina
Copy link
Member Author

@michael-s-molina Yeah, i am using your extensions repo as a documentation so i was curious to see how you would use the handle api

Oh, got it! We'll need an extension idea that manipulates the editor 😉 The only one I have is the SQL Snippets which uses insertText from the handle API.

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 4, 2026

Code Review Agent Run #dcffda

Actionable Suggestions - 0
Review Details
  • Files reviewed - 6 · Commit Range: 00ea913..fa54712
    • superset-frontend/packages/superset-core/src/api/editors.ts
    • superset-frontend/packages/superset-core/src/api/sqlLab.ts
    • superset-frontend/src/SqlLab/components/EditorWrapper/index.tsx
    • superset-frontend/src/core/sqlLab/index.ts
    • superset-frontend/src/core/sqlLab/models.ts
    • superset-frontend/src/core/utils.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@michael-s-molina michael-s-molina merged commit 9243832 into apache:master Feb 4, 2026
69 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Superset Extensions Feb 4, 2026
@michael-s-molina
Copy link
Member Author

@msyavuz I updated my extensions to reflect the latest changes.

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

Labels

packages size/XXL sqllab Namespace | Anything related to the SQL Lab

Projects

Development

Successfully merging this pull request may close these issues.

3 participants