Class StreamingChunkProvider
- java.lang.Object
-
- com.databricks.jdbc.api.impl.arrow.StreamingChunkProvider
-
- All Implemented Interfaces:
ChunkProvider
public class StreamingChunkProvider extends Object implements ChunkProvider
A streaming chunk provider that fetches chunk links proactively and downloads chunks in parallel.Key features:
- No dependency on total chunk count - streams until end of data
- Proactive link prefetching with configurable window
- Memory-bounded parallel downloads
- Automatic link refresh on expiration
This provider uses two key windows:
- Link prefetch window: How many links to fetch ahead of consumption
- Download window: How many chunks to keep in memory (downloading or ready)
-
-
Constructor Summary
Constructors Constructor Description StreamingChunkProvider(ChunkLinkFetcher linkFetcher, IDatabricksHttpClient httpClient, CompressionCodec compressionCodec, StatementId statementId, int maxChunksInMemory, int linkPrefetchWindow, int chunkReadyTimeoutSeconds, double cloudFetchSpeedThreshold, IDatabricksConnectionContext connectionContext, ChunkLinkFetchResult initialLinks)Creates a new StreamingChunkProvider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the chunk provider and releases any resources associated with it.AbstractArrowResultChunkgetChunk()Retrieves the current chunk of data after a successful call toChunkProvider.next().longgetChunkCount()Returns the total chunk count only when all chunks have been discovered.longgetRowCount()booleanhasNextChunk()Checks if there are more chunks available to iterate over.booleanisClosed()booleannext()Advances to the next available chunk.
-
-
-
Constructor Detail
-
StreamingChunkProvider
public StreamingChunkProvider(ChunkLinkFetcher linkFetcher, IDatabricksHttpClient httpClient, CompressionCodec compressionCodec, StatementId statementId, int maxChunksInMemory, int linkPrefetchWindow, int chunkReadyTimeoutSeconds, double cloudFetchSpeedThreshold, IDatabricksConnectionContext connectionContext, ChunkLinkFetchResult initialLinks) throws DatabricksParsingException
Creates a new StreamingChunkProvider.- Parameters:
linkFetcher- Fetcher for chunk linkshttpClient- HTTP client for downloadscompressionCodec- Codec for decompressing chunk datastatementId- Statement ID for logging and chunk creationmaxChunksInMemory- Maximum chunks to keep in memory (download window)linkPrefetchWindow- How many links to fetch aheadchunkReadyTimeoutSeconds- Timeout waiting for chunk to be readycloudFetchSpeedThreshold- Speed threshold for logging warningsinitialLinks- Initial links provided with result data (avoids extra fetch), may be null- Throws:
DatabricksParsingException
-
-
Method Detail
-
hasNextChunk
public boolean hasNextChunk()
Description copied from interface:ChunkProviderChecks if there are more chunks available to iterate over.- Specified by:
hasNextChunkin interfaceChunkProvider- Returns:
trueif there are additional chunks to be retrieved;falseotherwise.
-
next
public boolean next() throws DatabricksSQLExceptionDescription copied from interface:ChunkProviderAdvances 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
-
getChunk
public AbstractArrowResultChunk getChunk() throws DatabricksSQLException
Description copied from interface:ChunkProviderRetrieves the current chunk of data after a successful call toChunkProvider.next().- Specified by:
getChunkin interfaceChunkProvider- Returns:
- The current
AbstractArrowResultChunkcontaining the data. - Throws:
DatabricksSQLException- if an error occurs while fetching the chunk.
-
close
public void close()
Description copied from interface:ChunkProviderCloses the chunk provider and releases any resources associated with it. After calling this method, the chunk provider should not be used again.- Specified by:
closein interfaceChunkProvider
-
getRowCount
public long getRowCount()
- Specified by:
getRowCountin interfaceChunkProvider
-
getChunkCount
public long getChunkCount()
Returns the total chunk count only when all chunks have been discovered.In streaming mode, the total chunk count is unknown until we reach the end of the stream. This method returns -1 if chunks are still being discovered, and the actual count once all chunks have been fetched.
- Specified by:
getChunkCountin interfaceChunkProvider- Returns:
- the total chunk count if all chunks have been discovered, or -1 if still streaming
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceChunkProvider
-
-