Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
688cf75
Add support for configuring HTTP connection pool size
gopalldb Feb 12, 2025
2e6bfaa
Changes for default value
gopalldb Feb 12, 2025
8ee0fa1
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Feb 21, 2025
5f7d0c1
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Feb 24, 2025
2e28c9e
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Feb 25, 2025
a720802
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Feb 25, 2025
e88657b
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Feb 26, 2025
2670e43
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 1, 2025
c4925ee
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 2, 2025
5a5f1de
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 4, 2025
bf41453
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 5, 2025
b81f4ad
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 6, 2025
1e790a4
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 6, 2025
5ed0c08
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 17, 2025
73029b4
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 19, 2025
ffc2aae
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 27, 2025
7cf9cc8
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Mar 30, 2025
f55ca04
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 2, 2025
ceb2fcb
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 7, 2025
77552fc
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 7, 2025
0690dea
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 7, 2025
638a11a
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 10, 2025
5da3b1e
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 25, 2025
8dbee51
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb Apr 30, 2025
5c72ef9
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb May 8, 2025
b769422
Merge branch 'main' of github.com:databricks/databricks-jdbc
gopalldb May 12, 2025
89e0242
Add implementation for fetching execution status for async execution
gopalldb May 12, 2025
7da658f
Addres feedbacks for renaming class
gopalldb May 14, 2025
980b0ab
rename variable
gopalldb May 14, 2025
47a7fbe
cleanup redundant pkg name
gopalldb May 14, 2025
b936507
address feedbacks and fix deprecated typo
gopalldb May 14, 2025
2feeba2
fix lint
gopalldb May 14, 2025
b1263ca
add changelog
gopalldb May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added
- Support for fetching tables and views across all catalogs using SHOW TABLES FROM/IN ALL CATALOGS in the SQL Exec API.
- Support for Token Exchange in OAuth flows where in third party tokens are exchanged for InHouse tokens.
- Added support for polling of statementStatus and sqlState for async SQL execution.

### Updated
-
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/databricks/jdbc/api/ExecutionState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.databricks.jdbc.api;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move to com.databricks.jdbc.common?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to keep public facing and public documented interfaces and enums in a single place.


/**
* Represents the possible states of a SQL statement execution in Databricks. This enum is used to
* track the progress and status of SQL statements executed through the Databricks JDBC API.
*/
public enum ExecutionState {
// The statement is in a pending state and has not yet started executing.
PENDING,
// The statement is currently executing.
RUNNING,
// The statement has completed successfully.
SUCCEEDED,
// The statement has completed with an error.
FAILED,
// The statement has been closed and is no longer available.
CLOSED,
// The statement has been cancelled by the user.
ABORTED;
}
10 changes: 10 additions & 0 deletions src/main/java/com/databricks/jdbc/api/IDatabricksResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ public interface IDatabricksResultSet extends ResultSet {
* to monitor the execution progress and state of the statement.
*
* @return The current {@link StatementStatus} of the statement
* @deprecated Use {@link #getExecutionStatus()} instead.
*/
@Deprecated
StatementStatus getStatementStatus();

/**
* Retrieves the current status of the statement associated with this result set. This can be used
* to monitor the execution progress and state of the statement.
*
* @return The current {@link StatementStatus} of the statement
*/
IExecutionStatus getExecutionStatus();

/**
* Retrieves the number of rows affected by the SQL statement. For SELECT statements or statements
* that don't modify data, this will return 0.
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/databricks/jdbc/api/IExecutionStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.databricks.jdbc.api;

public interface IExecutionStatus {
/**
* Returns the error message if the statement execution failed.
*
* @return the error message, or null if there was no error
*/
String getErrorMessage();

/**
* Returns the SQL state code if the statement execution failed.
*
* @return the SQL state code, or null if there was no error
*/
String getSqlState();

/**
* Returns the current state of the statement execution.
*
* @return the current state of the statement execution
*/
ExecutionState getExecutionState();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.databricks.jdbc.common.util.DatabricksTypeUtil.STRUCT;

import com.databricks.jdbc.api.IDatabricksResultSet;
import com.databricks.jdbc.api.IExecutionStatus;
import com.databricks.jdbc.api.impl.arrow.ArrowStreamResult;
import com.databricks.jdbc.api.impl.converters.ConverterHelper;
import com.databricks.jdbc.api.impl.converters.ObjectConverter;
Expand Down Expand Up @@ -56,7 +57,7 @@ enum ResultSetType {

private static final JdbcLogger LOGGER = JdbcLoggerFactory.getLogger(DatabricksResultSet.class);
protected static final String AFFECTED_ROWS_COUNT = "num_affected_rows";
private final StatementStatus statementStatus;
private final ExecutionStatus executionStatus;
private final StatementId statementId;
private final IExecutionResult executionResult;
private final DatabricksResultSetMetaData resultSetMetaData;
Expand All @@ -81,7 +82,7 @@ public DatabricksResultSet(
IDatabricksSession session,
IDatabricksStatementInternal parentStatement)
throws DatabricksSQLException {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
if (resultData != null) {
this.executionResult =
Expand Down Expand Up @@ -122,7 +123,7 @@ public DatabricksResultSet(
IExecutionResult executionResult,
DatabricksResultSetMetaData resultSetMetaData,
boolean complexDatatypeSupport) {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
this.executionResult = executionResult;
this.resultSetMetaData = resultSetMetaData;
Expand All @@ -143,7 +144,7 @@ public DatabricksResultSet(
IDatabricksStatementInternal parentStatement,
IDatabricksSession session)
throws SQLException {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
if (resultsResp != null) {
this.executionResult =
Expand Down Expand Up @@ -193,7 +194,7 @@ public DatabricksResultSet(
int[] isNullables,
Object[][] rows,
StatementType statementType) {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
this.executionResult = ExecutionResultFactory.getResultSet(rows);
this.resultSetMetaData =
Expand Down Expand Up @@ -223,7 +224,7 @@ public DatabricksResultSet(
List<Nullable> columnNullables,
List<List<Object>> rows,
StatementType statementType) {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
this.executionResult = ExecutionResultFactory.getResultSet(rows);
this.resultSetMetaData =
Expand All @@ -249,7 +250,7 @@ public DatabricksResultSet(
List<ColumnMetadata> columnMetadataList,
List<List<Object>> rows,
StatementType statementType) {
this.statementStatus = statementStatus;
this.executionStatus = new ExecutionStatus(statementStatus);
this.statementId = statementId;
this.executionResult = ExecutionResultFactory.getResultSet(rows);
this.resultSetMetaData =
Expand Down Expand Up @@ -1734,7 +1735,12 @@ public String getStatementId() {

@Override
public StatementStatus getStatementStatus() {
return statementStatus;
return executionStatus.getSdkStatus();
}

@Override
public IExecutionStatus getExecutionStatus() {
return executionStatus;
}

@Override
Expand Down Expand Up @@ -1837,7 +1843,7 @@ private BigDecimal applyScaleToBigDecimal(BigDecimal bigDecimal, int columnIndex
@Override
public String toString() {
return (new ToStringer(DatabricksResultSet.class))
.add("statementStatus", this.statementStatus)
.add("statementStatus", this.executionStatus)
.add("statementId", this.statementId)
.add("statementType", this.statementType)
.add("updateCount", this.updateCount)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.databricks.jdbc.api.impl;

import com.databricks.jdbc.api.IDatabricksResultSet;
import com.databricks.jdbc.api.IExecutionStatus;
import com.databricks.jdbc.api.internal.IDatabricksResultSetInternal;
import com.databricks.jdbc.exception.DatabricksSQLException;
import com.databricks.jdbc.model.core.StatementStatus;
Expand Down Expand Up @@ -1127,6 +1128,11 @@ public StatementStatus getStatementStatus() {
return new StatementStatus().setState(StatementState.SUCCEEDED);
}

@Override
public IExecutionStatus getExecutionStatus() {
return new ExecutionStatus(new StatementStatus().setState(StatementState.SUCCEEDED));
}

@Override
public long getUpdateCount() throws SQLException {
return 0;
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/databricks/jdbc/api/impl/ExecutionStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.databricks.jdbc.api.impl;

import com.databricks.jdbc.api.ExecutionState;
import com.databricks.jdbc.api.IExecutionStatus;
import com.databricks.jdbc.model.core.StatementStatus;
import com.databricks.sdk.service.sql.StatementState;

/**
* This class implements the IStatementStatus interface and provides a default implementation for
* the methods defined in the interface. It is used to represent the status of a SQL statement
* execution in Databricks.
*/
class ExecutionStatus implements IExecutionStatus {
private final ExecutionState state;
private final String errorMessage;
private final String sqlState;
private final StatementStatus sdkStatus;

public ExecutionStatus(StatementStatus status) {
this.state = getStateFromSdkState(status.getState());
this.errorMessage = status.getError() != null ? status.getError().getMessage() : null;
this.sqlState = status.getSqlState();
this.sdkStatus = status;
}

@Override
public String getErrorMessage() {
return errorMessage;
}

@Override
public String getSqlState() {
return sqlState;
}

@Override
public ExecutionState getExecutionState() {
return state;
}

StatementStatus getSdkStatus() {
return sdkStatus;
}

private ExecutionState getStateFromSdkState(StatementState state) {
if (state == null) {
return ExecutionState.PENDING;
}
// Map the SDK statement state to the JDBC statement state
switch (state) {
case PENDING:
return ExecutionState.PENDING;
case RUNNING:
return ExecutionState.RUNNING;
case SUCCEEDED:
return ExecutionState.SUCCEEDED;
case FAILED:
return ExecutionState.FAILED;
case CANCELED:
return ExecutionState.ABORTED;
case CLOSED:
return ExecutionState.CLOSED;
// should never reach here
default:
throw new IllegalArgumentException("Unknown statement execution state: " + state);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.databricks.jdbc.api.ExecutionState;
import com.databricks.jdbc.api.IDatabricksResultSet;
import com.databricks.jdbc.api.IExecutionStatus;
import com.databricks.jdbc.api.impl.volume.VolumeOperationResult;
import com.databricks.jdbc.api.internal.IDatabricksResultSetInternal;
import com.databricks.jdbc.api.internal.IDatabricksSession;
Expand All @@ -20,6 +22,7 @@
import com.databricks.jdbc.exception.DatabricksSQLFeatureNotSupportedException;
import com.databricks.jdbc.model.client.thrift.generated.*;
import com.databricks.jdbc.model.core.StatementStatus;
import com.databricks.sdk.service.sql.ServiceError;
import com.databricks.sdk.service.sql.StatementState;
import java.io.*;
import java.math.BigDecimal;
Expand Down Expand Up @@ -63,6 +66,18 @@ private DatabricksResultSet getResultSet(
false);
}

private DatabricksResultSet getResultSet(
StatementStatus statementState, IDatabricksStatementInternal statement) {
return new DatabricksResultSet(
statementState,
STATEMENT_ID,
StatementType.METADATA,
statement,
mockedExecutionResult,
mockedResultSetMetadata,
false);
}

private DatabricksResultSet getThriftResultSetMetadata() throws SQLException {
TColumnValue columnValue = new TColumnValue();
columnValue.setStringVal(new TStringValue().setValue("testString"));
Expand Down Expand Up @@ -118,8 +133,20 @@ void testThriftResultSet() throws SQLException {

@Test
void testGetStatementStatus() {
DatabricksResultSet resultSet = getResultSet(StatementState.PENDING, null);
assertEquals(StatementState.PENDING, resultSet.getStatementStatus().getState());
StatementStatus statementStatus =
new StatementStatus()
.setState(StatementState.FAILED)
.setError(new ServiceError().setMessage("error"))
.setSqlState("sqlState");
DatabricksResultSet resultSet = getResultSet(statementStatus, null);
assertEquals(STATEMENT_ID.toString(), resultSet.getStatementId());
assertEquals(StatementState.FAILED, resultSet.getStatementStatus().getState());
assertEquals(statementStatus, resultSet.getStatementStatus());

IExecutionStatus executionStatus = resultSet.getExecutionStatus();
assertEquals(ExecutionState.FAILED, executionStatus.getExecutionState());
assertEquals("error", executionStatus.getErrorMessage());
assertEquals("sqlState", executionStatus.getSqlState());
}

@Test
Expand Down
Loading