Skip to content

Conversation

@inhouseaccman
Copy link

Fix DDL transaction handling to resolve error 5305

Problem

When running dbt unit tests, StarRocks throws error 5305:

5305 (25P01): Getting analyzing error. Detail message: Explicit transaction only support begin/commit/rollback/insert/update/delete/set/select statements.

This occurs because StarRocks does not support DDL statements (CREATE, DROP, ALTER, TRUNCATE) within explicit transactions. The current implementation sends COMMIT after DDL execution, which triggers this error.

Root Cause

  • add_commit_query() was not overridden, using parent class which sends COMMIT ✗

When DDL statements are executed, the COMMIT causes StarRocks to fail.

Solution

  1. Add _is_ddl_statement() static method - Detects DDL statements using regex patterns:

    • CREATE TABLE/VIEW/DATABASE/SCHEMA/INDEX/MATERIALIZED VIEW
    • DROP TABLE/VIEW/DATABASE/SCHEMA/INDEX/MATERIALIZED VIEW
    • ALTER TABLE/VIEW/DATABASE/SCHEMA
    • TRUNCATE TABLE
  2. Override add_commit_query() - Skip COMMIT for DDL context, send COMMIT for DML

Changes

File Changes
dbt/adapters/starrocks/connections.py Add _is_ddl_statement() and add_commit_query()
tests/unit/test_connections.py Add unit tests for DDL/DML transaction handling

Behavior

Statement Type BEGIN COMMIT
DDL (CREATE, DROP, etc.) ✗ Empty ✗ Empty
DML (INSERT, UPDATE, etc.) ✗ Empty ✓ COMMIT

Testing

  • Added 23 new unit tests
  • All 28 unit tests pass
$ python -m pytest tests/unit -v
======================= 28 passed, 2 warnings =======================

Test Cases

  • DDL detection (21 parameterized tests)
  • DDL execution flow (no BEGIN/COMMIT)
  • DML execution flow (with COMMIT)

Checklist

  • Code follows project style
  • Unit tests added
  • All tests pass
  • No breaking changes to DML behavior

@CLAassistant
Copy link

CLAassistant commented Dec 4, 2025

CLA assistant check
All committers have signed the CLA.

@inhouseaccman inhouseaccman force-pushed the fix/ddl-transaction-handling branch from 20ef84b to 64b863d Compare December 4, 2025 08:01
StarRocks does not support DDL statements in explicit transactions,
causing error 5305 when running dbt unit tests.

Changes:
- Add _is_ddl_statement() to detect DDL statements
- Override add_commit_query() to skip COMMIT for DDL
- Add unit tests for DDL/DML transaction handling

Signed-off-by: wkho <wkho@smg.gov.mo>
@jaogoy
Copy link
Collaborator

jaogoy commented Dec 6, 2025

@inhouseaccman Is it complete to solve the problem?

@inhouseaccman
Copy link
Author

@inhouseaccman Is it complete to solve the problem?

Yes.

@chris-celerdata
Copy link
Collaborator

I cannot reproduce the bug this PR is supposed to fix on the current version. These lines were added in v1.10.

def add_begin_query(self):
        return self.add_query("", auto_begin=False)

Can you try updating to v1.10 to confirm whether these changes are needed?

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.

4 participants