Class DatabricksBatchExecutor
java.lang.Object
com.databricks.jdbc.api.impl.batch.DatabricksBatchExecutor
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
ConstructorsConstructorDescriptionDatabricksBatchExecutor(Statement parentStatement, int maxBatchSize) Constructs aDatabricksBatchExecutorwith the specified parentStatementand maximum batch size. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommand(String sql) Adds a new SQL command to the batch.voidClears all the commands from the batch.long[]Executes all the commands in the batch sequentially.
-
Constructor Details
-
DatabricksBatchExecutor
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 Details
-
addCommand
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
Executes 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
-