Package net.snowflake.client.jdbc
Class SnowflakeFileTransferAgent
- java.lang.Object
-
- net.snowflake.client.jdbc.SFBaseFileTransferAgent
-
- net.snowflake.client.jdbc.SnowflakeFileTransferAgent
-
- All Implemented Interfaces:
SnowflakeFixedView
public class SnowflakeFileTransferAgent extends SFBaseFileTransferAgent
Class for uploading/downloading files
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SnowflakeFileTransferAgent.ResultStatus
Result status enum-
Nested classes/interfaces inherited from class net.snowflake.client.jdbc.SFBaseFileTransferAgent
SFBaseFileTransferAgent.CommandType, SFBaseFileTransferAgent.DownloadCommandEncryptionFacade, SFBaseFileTransferAgent.DownloadCommandFacade, SFBaseFileTransferAgent.UploadColumns, SFBaseFileTransferAgent.UploadCommandEncryptionFacade, SFBaseFileTransferAgent.UploadCommandFacade
-
-
Field Summary
Fields Modifier and Type Field Description static String
SRC_FILE_NAME_FOR_STREAM
-
Fields inherited from class net.snowflake.client.jdbc.SFBaseFileTransferAgent
commandType, compressSourceFromStream, destFileNameForStreamSource, destStagePath, showEncryptionParameter, sourceFromStream, sourceStream, statusRows
-
-
Constructor Summary
Constructors Constructor Description SnowflakeFileTransferAgent(String command, SFSession session, SFStatement statement)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
cancel()
InputStream
downloadStream(String fileName)
Download a file from remote, and return an input streamboolean
execute()
Run the PUT/GET command, if a command has been set.static net.snowflake.client.jdbc.SnowflakeFileTransferAgent.remoteLocation
extractLocationAndPath(String stageLocationPath)
A small helper for extracting location name and path from full location pathSFBaseFileTransferAgent.CommandType
getCommandType()
static Callable<Void>
getDownloadFileCallable(StageInfo stage, String srcFilePath, String localLocation, Map<String,net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata> fileMetadataMap, SnowflakeStorageClient client, SFSession session, String command, int parallel, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String presignedUrl)
static Callable<Void>
getDownloadFileCallable(StageInfo stage, String srcFilePath, String localLocation, Map<String,net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata> fileMetadataMap, SnowflakeStorageClient client, SFSession session, String command, int parallel, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String presignedUrl, String queryId)
A callable that can be executed in a separate thread using executor service.List<net.snowflake.common.core.RemoteStoreFileEncryptionMaterial>
getEncryptionMaterial()
List<SnowflakeFileTransferMetadata>
getFileTransferMetadatas()
This is API function to retrieve the File Transfer Metadatas.static List<SnowflakeFileTransferMetadata>
getFileTransferMetadatas(com.fasterxml.jackson.databind.JsonNode jsonNode)
This is API function to parse the File Transfer Metadatas from a supplied PUT call response.static List<SnowflakeFileTransferMetadata>
getFileTransferMetadatas(com.fasterxml.jackson.databind.JsonNode jsonNode, String queryId)
This is API function to parse the File Transfer Metadatas from a supplied PUT call response.Object
getResultSet()
Map<String,net.snowflake.common.core.RemoteStoreFileEncryptionMaterial>
getSrcToMaterialsMap()
Map<String,String>
getSrcToPresignedUrlMap()
Map<?,?>
getStageCredentials()
StageInfo
getStageInfo()
String
getStageLocation()
static Callable<Void>
getUploadFileCallable(StageInfo stage, String srcFilePath, net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata metadata, SnowflakeStorageClient client, SFSession session, String command, InputStream inputStream, boolean sourceFromStream, int parallel, File srcFile, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat)
static Callable<Void>
getUploadFileCallable(StageInfo stage, String srcFilePath, net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata metadata, SnowflakeStorageClient client, SFSession session, String command, InputStream inputStream, boolean sourceFromStream, int parallel, File srcFile, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String queryId)
A callable that can be executed in a separate thread using executor service.static void
renewExpiredToken(SFSession session, String command, SnowflakeStorageClient client)
This static method is called when we are handling an expired token exception It retrieves a fresh token from GS and then calls .renew() on the storage client to refresh itself with the new tokenstatic void
throwJCEMissingError(String operation, Exception ex)
Deprecated.static void
throwJCEMissingError(String operation, Exception ex, String queryId)
Handles an InvalidKeyException which indicates that the JCE component is not installed properlystatic void
throwNoSpaceLeftError(SFSession session, String operation, Exception ex)
Deprecated.static void
throwNoSpaceLeftError(SFSession session, String operation, Exception ex, String queryId)
For handling IOException: No space left on device when attempting to download a file to a location where there is not enough space.static void
uploadWithoutConnection(SnowflakeFileTransferConfig config)
Static API function to upload data without JDBC session.-
Methods inherited from class net.snowflake.client.jdbc.SFBaseFileTransferAgent
describeColumns, getNextRow, getTotalRows, setCompressSourceFromStream, setDestFileNameForStreamSource, setDestStagePath, setSourceStream
-
-
-
-
Field Detail
-
SRC_FILE_NAME_FOR_STREAM
public static final String SRC_FILE_NAME_FOR_STREAM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SnowflakeFileTransferAgent
public SnowflakeFileTransferAgent(String command, SFSession session, SFStatement statement) throws SnowflakeSQLException
- Throws:
SnowflakeSQLException
-
-
Method Detail
-
getStageInfo
public StageInfo getStageInfo()
-
getStageCredentials
public Map<?,?> getStageCredentials()
-
getEncryptionMaterial
public List<net.snowflake.common.core.RemoteStoreFileEncryptionMaterial> getEncryptionMaterial()
-
getSrcToMaterialsMap
public Map<String,net.snowflake.common.core.RemoteStoreFileEncryptionMaterial> getSrcToMaterialsMap()
-
getStageLocation
public String getStageLocation()
-
getUploadFileCallable
@Deprecated public static Callable<Void> getUploadFileCallable(StageInfo stage, String srcFilePath, net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata metadata, SnowflakeStorageClient client, SFSession session, String command, InputStream inputStream, boolean sourceFromStream, int parallel, File srcFile, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat)
A callable that can be executed in a separate thread using executor service.The callable does compression if needed and upload the result to the table's staging area.
- Parameters:
stage
- information about the stagesrcFilePath
- source file pathmetadata
- file metadataclient
- client object used to communicate with c3session
- session objectcommand
- command stringinputStream
- null if upload source is filesourceFromStream
- whether upload source is file or streamparallel
- number of threads for parallel uploadingsrcFile
- source file nameencMat
- not null if encryption is required- Returns:
- a callable that uploading file to the remote store
-
getUploadFileCallable
public static Callable<Void> getUploadFileCallable(StageInfo stage, String srcFilePath, net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata metadata, SnowflakeStorageClient client, SFSession session, String command, InputStream inputStream, boolean sourceFromStream, int parallel, File srcFile, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String queryId)
A callable that can be executed in a separate thread using executor service.The callable does compression if needed and upload the result to the table's staging area.
- Parameters:
stage
- information about the stagesrcFilePath
- source file pathmetadata
- file metadataclient
- client object used to communicate with c3session
- session objectcommand
- command stringinputStream
- null if upload source is filesourceFromStream
- whether upload source is file or streamparallel
- number of threads for parallel uploadingsrcFile
- source file nameencMat
- not null if encryption is requiredqueryId
- last executed query id (for forwarding in possible exceptions)- Returns:
- a callable that uploading file to the remote store
-
getDownloadFileCallable
@Deprecated public static Callable<Void> getDownloadFileCallable(StageInfo stage, String srcFilePath, String localLocation, Map<String,net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata> fileMetadataMap, SnowflakeStorageClient client, SFSession session, String command, int parallel, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String presignedUrl)
A callable that can be executed in a separate thread using executor service.The callable download files from a stage location to a local location
- Parameters:
stage
- stage informationsrcFilePath
- path that stores the downloaded filelocalLocation
- local locationfileMetadataMap
- file metadata mapclient
- remote store clientsession
- session objectcommand
- command stringencMat
- remote store encryption materialparallel
- number of parallel threads for downloadingpresignedUrl
- Presigned URL for file download- Returns:
- a callable responsible for downloading files
-
getDownloadFileCallable
public static Callable<Void> getDownloadFileCallable(StageInfo stage, String srcFilePath, String localLocation, Map<String,net.snowflake.client.jdbc.SnowflakeFileTransferAgent.FileMetadata> fileMetadataMap, SnowflakeStorageClient client, SFSession session, String command, int parallel, net.snowflake.common.core.RemoteStoreFileEncryptionMaterial encMat, String presignedUrl, String queryId)
A callable that can be executed in a separate thread using executor service.The callable download files from a stage location to a local location
- Parameters:
stage
- stage informationsrcFilePath
- path that stores the downloaded filelocalLocation
- local locationfileMetadataMap
- file metadata mapclient
- remote store clientsession
- session objectcommand
- command stringencMat
- remote store encryption materialparallel
- number of parallel threads for downloadingpresignedUrl
- Presigned URL for file downloadqueryId
- the query ID- Returns:
- a callable responsible for downloading files
-
getFileTransferMetadatas
public List<SnowflakeFileTransferMetadata> getFileTransferMetadatas() throws SnowflakeSQLException
This is API function to retrieve the File Transfer Metadatas.NOTE: It only supports PUT on S3/AZURE/GCS
- Returns:
- The file transfer metadatas for to-be-transferred files.
- Throws:
SnowflakeSQLException
- if any error occurs
-
getFileTransferMetadatas
public static List<SnowflakeFileTransferMetadata> getFileTransferMetadatas(com.fasterxml.jackson.databind.JsonNode jsonNode) throws SnowflakeSQLException
This is API function to parse the File Transfer Metadatas from a supplied PUT call response.NOTE: It only supports PUT on S3/AZURE/GCS (i.e. NOT LOCAL_FS)
It also assumes there is no active SFSession
- Parameters:
jsonNode
- JSON doc returned by GS from PUT call- Returns:
- The file transfer metadatas for to-be-transferred files.
- Throws:
SnowflakeSQLException
- if any error occurs
-
getFileTransferMetadatas
public static List<SnowflakeFileTransferMetadata> getFileTransferMetadatas(com.fasterxml.jackson.databind.JsonNode jsonNode, String queryId) throws SnowflakeSQLException
This is API function to parse the File Transfer Metadatas from a supplied PUT call response.NOTE: It only supports PUT on S3/AZURE/GCS (i.e. NOT LOCAL_FS)
It also assumes there is no active SFSession
- Parameters:
jsonNode
- JSON doc returned by GS from PUT callqueryId
- String last executed query id if available- Returns:
- The file transfer metadatas for to-be-transferred files.
- Throws:
SnowflakeSQLException
- if any error occurs
-
execute
public boolean execute() throws SQLException
Description copied from class:SFBaseFileTransferAgent
Run the PUT/GET command, if a command has been set.- Specified by:
execute
in classSFBaseFileTransferAgent
- Returns:
- Whether the operation was completed successfully, and completely.
- Throws:
SQLException
- for SQL or upload errors
-
downloadStream
public InputStream downloadStream(String fileName) throws SnowflakeSQLException
Download a file from remote, and return an input stream- Specified by:
downloadStream
in classSFBaseFileTransferAgent
- Parameters:
fileName
- A file on a stage to download.- Returns:
- An InputStream for the requested file.
- Throws:
SnowflakeSQLException
- If the file does not exist, or if an error occurred during transport.
-
cancel
public void cancel()
-
uploadWithoutConnection
@SnowflakeOrgInternalApi public static void uploadWithoutConnection(SnowflakeFileTransferConfig config) throws Exception
Static API function to upload data without JDBC session.NOTE: This function is developed based on getUploadFileCallable().
- Parameters:
config
- Configuration to upload a file to cloud storage- Throws:
Exception
- if error occurs while data upload.
-
renewExpiredToken
public static void renewExpiredToken(SFSession session, String command, SnowflakeStorageClient client) throws SnowflakeSQLException
This static method is called when we are handling an expired token exception It retrieves a fresh token from GS and then calls .renew() on the storage client to refresh itself with the new token- Parameters:
session
- a session objectcommand
- a command to be retriedclient
- a Snowflake Storage client object- Throws:
SnowflakeSQLException
- if any error occurs
-
extractLocationAndPath
public static net.snowflake.client.jdbc.SnowflakeFileTransferAgent.remoteLocation extractLocationAndPath(String stageLocationPath)
A small helper for extracting location name and path from full location path- Parameters:
stageLocationPath
- stage location- Returns:
- remoteLocation object
-
getResultSet
public Object getResultSet() throws SnowflakeSQLException
- Throws:
SnowflakeSQLException
-
getCommandType
public SFBaseFileTransferAgent.CommandType getCommandType()
-
throwJCEMissingError
@Deprecated public static void throwJCEMissingError(String operation, Exception ex) throws SnowflakeSQLException
Deprecated.Handles an InvalidKeyException which indicates that the JCE component is not installed properly- Parameters:
operation
- a string indicating the operation type, e.g. upload/downloadex
- The exception to be handled- Throws:
SnowflakeSQLException
- throws the error as a SnowflakeSQLException
-
throwJCEMissingError
public static void throwJCEMissingError(String operation, Exception ex, String queryId) throws SnowflakeSQLException
Handles an InvalidKeyException which indicates that the JCE component is not installed properly- Parameters:
operation
- a string indicating the operation type, e.g. upload/downloadex
- The exception to be handledqueryId
- last query id if available- Throws:
SnowflakeSQLException
- throws the error as a SnowflakeSQLException
-
throwNoSpaceLeftError
@Deprecated public static void throwNoSpaceLeftError(SFSession session, String operation, Exception ex) throws SnowflakeSQLLoggedException
Deprecated.For handling IOException: No space left on device when attempting to download a file to a location where there is not enough space. We don't want to retry on this exception.- Parameters:
session
- the current sessionoperation
- the operation i.e. GETex
- the exception caught- Throws:
SnowflakeSQLLoggedException
- if not enough space left on device to download file.
-
throwNoSpaceLeftError
public static void throwNoSpaceLeftError(SFSession session, String operation, Exception ex, String queryId) throws SnowflakeSQLLoggedException
For handling IOException: No space left on device when attempting to download a file to a location where there is not enough space. We don't want to retry on this exception.- Parameters:
session
- the current sessionoperation
- the operation i.e. GETex
- the exception caughtqueryId
- the query ID- Throws:
SnowflakeSQLLoggedException
- if not enough space left on device to download file.
-
-