Class AbstractRemoteChunkProvider<T extends AbstractArrowResultChunk>
java.lang.Object
com.databricks.jdbc.api.impl.arrow.AbstractRemoteChunkProvider<T>
- Type Parameters:
T- The specific type of AbstractArrowResultChunk this provider manages
- All Implemented Interfaces:
ChunkProvider
- Direct Known Subclasses:
RemoteChunkProvider,RemoteChunkProviderV2
public abstract class AbstractRemoteChunkProvider<T extends AbstractArrowResultChunk>
extends Object
implements ChunkProvider
Abstract base implementation of both
ChunkProvider and ChunkDownloadManager
interfaces.
The provider maintains a concurrent map of chunks and implements a sliding window approach or memory management, releasing consumed chunks and downloading new ones as needed. It ensures that the number of chunks in memory never exceeds the configured parallel download limit.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longprotected longprotected final ConcurrentMap<Long, T> protected final intprotected final CompressionCodecprotected longprotected final IDatabricksHttpClientprotected booleanprotected final ChunkLinkDownloadService<T> protected final intMaximum number of parallel chunk downloads allowed per query.protected longprotected longprotected final IDatabricksSessionprotected final StatementIdprotected long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractRemoteChunkProvider(IDatabricksStatementInternal parentStatement, TFetchResultsResp resultsResp, IDatabricksSession session, IDatabricksHttpClient httpClient, int maxParallelChunkDownloadsPerQuery, CompressionCodec compressionCodec) protectedAbstractRemoteChunkProvider(StatementId statementId, ResultManifest resultManifest, ResultData resultData, IDatabricksSession session, IDatabricksHttpClient httpClient, int maxParallelChunkDownloadsPerQuery, CompressionCodec compressionCodec) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Closes the chunk provider and releases any resources associated with it.protected abstract TcreateChunk(StatementId statementId, long chunkIndex, TSparkArrowResultLink resultLink) Creates chunkAbstractRemoteChunkProviderbased on theTSparkArrowResultLink.protected abstract TcreateChunk(StatementId statementId, long chunkIndex, com.databricks.sdk.service.sql.BaseChunkInfo chunkInfo) Creates chunkAbstractRemoteChunkProviderbased on theBaseChunkInfo.protected voiddoClose()Subclasses should override this method to perform their specific cleanup.voidDownloads the next set of chunks based on the current memory constraints and chunk availability.longgetChunk()Retrieves the current chunk of data after a successful call toChunkProvider.next().longlongbooleanChecks if there are more chunks available to iterate over.booleanisClosed()booleannext()Advances to the next available chunk.
-
Field Details
-
session
-
statementId
-
httpClient
-
compressionCodec
-
chunkIndexToChunksMap
-
chunkCount
protected long chunkCount -
rowCount
protected long rowCount -
currentChunkIndex
protected long currentChunkIndex -
nextChunkToDownload
protected long nextChunkToDownload -
totalChunksInMemory
protected long totalChunksInMemory -
allowedChunksInMemory
protected long allowedChunksInMemory -
isClosed
protected boolean isClosed -
maxParallelChunkDownloadsPerQuery
protected final int maxParallelChunkDownloadsPerQueryMaximum number of parallel chunk downloads allowed per query. -
linkDownloadService
-
chunkReadyTimeoutSeconds
protected final int chunkReadyTimeoutSeconds
-
-
Constructor Details
-
AbstractRemoteChunkProvider
protected AbstractRemoteChunkProvider(StatementId statementId, ResultManifest resultManifest, ResultData resultData, IDatabricksSession session, IDatabricksHttpClient httpClient, int maxParallelChunkDownloadsPerQuery, CompressionCodec compressionCodec) throws DatabricksSQLException - Throws:
DatabricksSQLException
-
AbstractRemoteChunkProvider
protected AbstractRemoteChunkProvider(IDatabricksStatementInternal parentStatement, TFetchResultsResp resultsResp, IDatabricksSession session, IDatabricksHttpClient httpClient, int maxParallelChunkDownloadsPerQuery, CompressionCodec compressionCodec) throws DatabricksSQLException - Throws:
DatabricksSQLException
-
-
Method Details
-
createChunk
protected abstract T createChunk(StatementId statementId, long chunkIndex, com.databricks.sdk.service.sql.BaseChunkInfo chunkInfo) throws DatabricksSQLException Creates chunkAbstractRemoteChunkProviderbased on theBaseChunkInfo. Used in SQL Execution API flow.- Throws:
DatabricksSQLException
-
createChunk
protected abstract T createChunk(StatementId statementId, long chunkIndex, TSparkArrowResultLink resultLink) throws DatabricksSQLException Creates chunkAbstractRemoteChunkProviderbased on theTSparkArrowResultLink. Used in Thrift CLI flow.- Throws:
DatabricksSQLException
-
getCompressionCodec
-
hasNextChunk
public boolean hasNextChunk()Checks if there are more chunks available to iterate over.- Specified by:
hasNextChunkin interfaceChunkProvider- Returns:
trueif there are additional chunks to be retrieved;falseotherwise.
-
getRowCount
public long getRowCount()- Specified by:
getRowCountin interfaceChunkProvider
-
getChunkCount
public long getChunkCount()- Specified by:
getChunkCountin interfaceChunkProvider
-
getChunk
Retrieves the current chunk of data after a successful call toChunkProvider.next().Retrieves and waits for the current chunk to be ready.
- Specified by:
getChunkin interfaceChunkProvider- Returns:
- The current
AbstractArrowResultChunkcontaining the data. - Throws:
DatabricksSQLException- if an error occurs while fetching the chunk.
-
next
Advances to the next available chunk. This method should be called before callingChunkProvider.getChunk()to retrieve the data from the next chunk.- Specified by:
nextin interfaceChunkProvider- Returns:
trueif the next chunk was successfully moved to;falseif there are no more chunks.- Throws:
DatabricksSQLException
-
close
public final void close()Closes the chunk provider and releases any resources associated with it. After calling this method, the chunk provider should not be used again.This method is final to ensure proper cleanup order. Subclasses should override doClose() instead.
- Specified by:
closein interfaceChunkProvider
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceChunkProvider
-
getAllowedChunksInMemory
public long getAllowedChunksInMemory() -
doClose
protected void doClose()Subclasses should override this method to perform their specific cleanup. -
downloadNextChunks
Downloads the next set of chunks based on the current memory constraints and chunk availability. This method manages the download process by respecting:- The total number of chunks allowed in memory
- Whether the provider has been closed
- The availability of more chunks to download
- Throws:
DatabricksSQLException- If there's an error during the chunk download process
-