Package com.databricks.jdbc.api.impl.batch

## Class DatabricksBatchExecutor

- java.lang.Object
- - com.databricks.jdbc.api.impl.batch.DatabricksBatchExecutor

    public class DatabricksBatchExecutor
    extends Object

The `DatabricksBatchExecutor` class handles the execution of batch SQL commands. It encapsulates batch logic, maintains the list of commands, and manages the execution flow.

This class is responsible for:

- Adding commands to the batch.
- Clearing the batch commands.
- Executing the batch and handling exceptions according to JDBC specifications.
- Tracking telemetry such as execution time for each command and total batch execution time.
- Enforcing a maximum batch size limit.

### Constructor Summary

Constructors
`DatabricksBatchExecutor​(Statement parentStatement, int maxBatchSize)` Constructs a `DatabricksBatchExecutor` with the specified parent `Statement` and maximum batch size.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addCommand​(String sql)` Adds a new SQL command to the batch.
`void` `clearCommands()` Clears all the commands from the batch.
`int[]` `executeBatch()` Executes all the commands in the batch sequentially.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DatabricksBatchExecutor

    public DatabricksBatchExecutor​(Statement parentStatement,
                                   int maxBatchSize)

Constructs a `DatabricksBatchExecutor` with the specified parent `Statement` and maximum batch size.

Parameters:
  `parentStatement` - the parent `Statement` that will execute the commands
  `maxBatchSize` - the maximum number of commands allowed in the batch

### Method Detail

#### addCommand

    public void addCommand​(String sql)
                    throws DatabricksValidationException

Adds a new SQL command to the batch.

Parameters:
  `sql` - the SQL command to be added
Throws:
  `DatabricksValidationException` - if the SQL command is null or the batch size limit is exceeded

#### clearCommands

    public void clearCommands()

Clears all the commands from the batch.

#### executeBatch

    public int[] executeBatch()
                       throws DatabricksBatchUpdateException

Executes all the commands in the batch sequentially. If any command fails or attempts to return a `ResultSet`, the execution stops, and a `BatchUpdateException` is thrown.

The driver stops execution upon encountering a failure and does not process subsequent commands. This method also tracks and logs telemetry data such as execution time for each command and total batch time.

Returns:
  an array of update counts for each command in the batch
Throws:
  `DatabricksBatchUpdateException` - if a database access error occurs or batch execution fails