Class DatabricksBatchExecutor
- java.lang.Object
-
- com.databricks.jdbc.api.impl.batch.DatabricksBatchExecutor
-
public class DatabricksBatchExecutor extends Object
TheDatabricksBatchExecutorclass 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 Constructor Description DatabricksBatchExecutor(Statement parentStatement, int maxBatchSize)Constructs aDatabricksBatchExecutorwith the specified parentStatementand maximum batch size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCommand(String sql)Adds a new SQL command to the batch.voidclearCommands()Clears all the commands from the batch.long[]executeBatch()Executes all the commands in the batch sequentially.
-
-
-
Constructor Detail
-
DatabricksBatchExecutor
public DatabricksBatchExecutor(Statement parentStatement, int maxBatchSize)
Constructs aDatabricksBatchExecutorwith the specified parentStatementand maximum batch size.- Parameters:
parentStatement- the parentStatementthat will execute the commandsmaxBatchSize- 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 long[] executeBatch() throws DatabricksBatchUpdateExceptionExecutes all the commands in the batch sequentially. If any command fails or attempts to return aResultSet, the execution stops, and aBatchUpdateExceptionis 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
-
-