Skip to content

feat: Abort query in CreateTableForm#321

Merged
ilyabo merged 3 commits intomainfrom
feat--Abort-query-in-CreateTableForm
Jan 26, 2026
Merged

feat: Abort query in CreateTableForm#321
ilyabo merged 3 commits intomainfrom
feat--Abort-query-in-CreateTableForm

Conversation

@ilyabo
Copy link
Collaborator

@ilyabo ilyabo commented Jan 26, 2026

No description provided.

Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR adds query cancellation support to the CreateTableModal component, allowing users to abort long-running queries when creating tables or views.

Key Changes:

  • Added AbortController to CreateTableForm to manage query cancellation
  • Modified addOrUpdateSqlQueryDataSource in RoomShellSlice to accept and forward an optional abortSignal parameter
  • Implemented a confirmation dialog that appears when users try to close the modal while a query is running
  • Updated the submit button to transform into a cancel button during query execution, with a "Cancelling..." state
  • Added proper cleanup in useEffect to abort ongoing queries when the form unmounts
  • Implemented isAbortError helper to distinguish abort errors from actual query errors

Implementation Details:

  • The abort signal is passed through the call chain: CreateTableFormaddOrUpdateSqlQueryDataSourcecreateTableFromQueryconnector.query
  • When a query is aborted, the error is silently caught to avoid showing error messages to the user
  • The "Close" button is always enabled and triggers a confirmation dialog when a query is running
  • Both the legacy (onAddOrUpdateSqlQuery) and new (direct createTableFromQuery) code paths support cancellation

Minor Issue:

  • Empty <DialogHeader> element added at line 659 that serves no purpose and can be removed

Confidence Score: 4/5

  • This PR is safe to merge with one minor style issue
  • The implementation is well-structured and follows React best practices for managing async operations with AbortController. The abort signal is properly propagated through all layers, cleanup is handled correctly, and the UX flow prevents accidental query cancellation. Confidence reduced by 1 point due to the empty DialogHeader element that should be removed, though this is purely cosmetic
  • No files require special attention - the empty DialogHeader in CreateTableModal.tsx is a minor cosmetic issue

Important Files Changed

Filename Overview
packages/room-shell/src/RoomShellSlice.ts Added optional abortSignal parameter to addOrUpdateSqlQueryDataSource and passed it to db.createTableFromQuery for query cancellation support
packages/sql-editor/src/components/CreateTableModal.tsx Implemented query cancellation with AbortController, added confirmation dialog for closing during query execution, and updated UI to show cancel button while query runs

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateTableModal
    participant CreateTableForm
    participant AbortController
    participant RoomShellSlice
    participant DuckDbSlice
    participant DuckDbConnector

    User->>CreateTableModal: Opens modal & enters query
    User->>CreateTableForm: Clicks Create/Update button
    CreateTableForm->>AbortController: new AbortController()
    CreateTableForm->>CreateTableForm: setIsCancelling(false)
    
    alt Legacy path (onAddOrUpdateSqlQuery provided)
        CreateTableForm->>RoomShellSlice: addOrUpdateSqlQueryDataSource(tableName, query, oldTableName, signal)
        RoomShellSlice->>DuckDbSlice: createTableFromQuery(tableName, query, {abortSignal})
    else New path (direct call)
        CreateTableForm->>DuckDbSlice: createTableFromQuery(tableName, query, {replace, temp, view, allowMultipleStatements, abortSignal})
    end
    
    DuckDbSlice->>DuckDbConnector: query(sql, {signal: abortSignal})
    
    alt User clicks Cancel during execution
        User->>CreateTableForm: Clicks Cancel button
        CreateTableForm->>CreateTableForm: setIsCancelling(true)
        CreateTableForm->>AbortController: abort()
        AbortController->>DuckDbConnector: Aborts query
        DuckDbConnector-->>DuckDbSlice: Throws AbortError
        DuckDbSlice-->>CreateTableForm: Throws AbortError
        CreateTableForm->>CreateTableForm: isAbortError() returns true
        Note over CreateTableForm: Silently ignores abort error
    else User tries to close dialog during execution
        User->>CreateTableModal: Clicks Close or ESC
        CreateTableModal->>CreateTableModal: setIsConfirmOpen(true)
        CreateTableModal->>User: Shows confirmation dialog
        alt User confirms cancellation
            User->>CreateTableModal: Clicks "Cancel & close"
            CreateTableModal->>AbortController: abort() via cancelRef
            CreateTableModal->>CreateTableModal: onClose()
        else User keeps running
            User->>CreateTableModal: Clicks "Keep running"
            CreateTableModal->>CreateTableModal: setIsConfirmOpen(false)
        end
    else Query completes successfully
        DuckDbConnector-->>DuckDbSlice: Returns result
        DuckDbSlice-->>CreateTableForm: Returns {tableName, rowCount}
        CreateTableForm->>DuckDbSlice: refreshTableSchemas()
        CreateTableForm->>CreateTableForm: form.reset()
        CreateTableForm->>CreateTableModal: onClose()
    end
    
    CreateTableForm->>AbortController: Clear abortControllerRef
    CreateTableForm->>CreateTableForm: setIsCancelling(false)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>
Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>
@ilyabo ilyabo merged commit ff16aad into main Jan 26, 2026
2 checks passed
@ilyabo ilyabo deleted the feat--Abort-query-in-CreateTableForm branch January 26, 2026 21:41
dmitriy-kostianetskiy pushed a commit that referenced this pull request Jan 28, 2026
* feat: Abort query in CreateTableForm

Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>

* fixes

Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>

* fixes

Signed-off-by: Ilya Boyandin <ilyabo@gmail.com>

---------

Signed-off-by: Ilya Boyandin <ilyabo@gmail.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.

2 participants

Comments