Executing mutiple queries in a single transaction of a notebook on databricks

Gabriel-2005 365 Reputation points
2024-11-15T07:43:37.5033333+00:00

I'm working on executing multiple queries within a single transaction on Databricks using Golang. However, I'm encountering a 'not implemented' error. Upon reviewing the library code, I found the following:

 

// Not supported in Databricks.

func (c *conn) Begin() (driver.Tx, error) {

    return nil, dbsqlerrint.NewDriverError(context.TODO(), dbsqlerr.ErrNotImplemented, nil)

}

 

// Not supported in Databricks.

func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {

    return nil, dbsqlerrint.NewDriverError(context.TODO(), dbsqlerr.ErrNotImplemented, nil)

}

 

 

Is there an available method or workaround to execute multiple queries within a single transaction in Databricks?

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,236 questions
0 comments No comments
{count} votes

Accepted answer
  1. Smaran Thoomu 17,520 Reputation points Microsoft Vendor
    2024-11-15T17:45:12.72+00:00

    Hi @Gabriel-2005

    Welcome to Microsoft Q&A platform and thanks for posting your query here.

    This functionality is not supported by Databricks. For more details, refer to the guide on How are transactions scoped on Databricks?

    Databricks manages transactions at the table level, meaning that each transaction operates on a single table. When it comes to handling concurrent transactions, Databricks employs optimistic concurrency control. This approach avoids locking mechanisms on table reads or writes, ensuring that deadlocks cannot occur.

    By default, Databricks offers snapshot isolation for read operations and write-serializable isolation for write operations. While write-serializable isolation provides stronger guarantees than snapshot isolation, these guarantees are specifically applied to write transactions.

    For read operations that involve multiple tables, Databricks returns the current version of each table as of the time they are accessed. This behavior does not interfere with other concurrent transactions that may be modifying the tables in question.

    It’s important to note that Databricks does not support BEGIN/END constructs for grouping multiple operations into a single transaction.

    When applications need to modify multiple tables, transactions are committed individually to each table in a sequential manner. However, you can use the MERGE INTO command to combine inserts, updates, and deletes into a single write transaction for a table. Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.