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 bothChunkProviderandChunkDownloadManagerinterfaces.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
Fields Modifier and Type Field Description protected longallowedChunksInMemoryprotected longchunkCountprotected ConcurrentMap<Long,T>chunkIndexToChunksMapprotected intchunkReadyTimeoutSecondsprotected CompressionCodeccompressionCodecprotected longcurrentChunkIndexprotected IDatabricksHttpClienthttpClientprotected booleanisClosedprotected ChunkLinkDownloadService<T>linkDownloadServiceprotected intmaxParallelChunkDownloadsPerQueryMaximum number of parallel chunk downloads allowed per query.protected longnextChunkToDownloadprotected longrowCountprotected IDatabricksSessionsessionprotected StatementIdstatementIdprotected longtotalChunksInMemory
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRemoteChunkProvider(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.voiddownloadNextChunks()Downloads the next set of chunks based on the current memory constraints and chunk availability.longgetAllowedChunksInMemory()TgetChunk()Retrieves the current chunk of data after a successful call toChunkProvider.next().longgetChunkCount()CompressionCodecgetCompressionCodec()longgetRowCount()booleanhasNextChunk()Checks if there are more chunks available to iterate over.booleanisClosed()booleannext()Advances to the next available chunk.
-
-
-
Field Detail
-
session
protected final IDatabricksSession session
-
statementId
protected final StatementId statementId
-
httpClient
protected final IDatabricksHttpClient httpClient
-
compressionCodec
protected final CompressionCodec compressionCodec
-
chunkIndexToChunksMap
protected final ConcurrentMap<Long,T extends AbstractArrowResultChunk> 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 maxParallelChunkDownloadsPerQuery
Maximum number of parallel chunk downloads allowed per query.
-
linkDownloadService
protected final ChunkLinkDownloadService<T extends AbstractArrowResultChunk> linkDownloadService
-
chunkReadyTimeoutSeconds
protected final int chunkReadyTimeoutSeconds
-
-
Constructor Detail
-
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 Detail
-
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
public CompressionCodec 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
public T getChunk() throws DatabricksSQLException
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
public boolean next() throws DatabricksSQLExceptionAdvances 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
public abstract void downloadNextChunks() throws DatabricksSQLExceptionDownloads 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
-
-