Class SnowflakeConnectionServiceV1
- java.lang.Object
-
- com.snowflake.kafka.connector.internal.SnowflakeConnectionServiceV1
-
- All Implemented Interfaces:
SnowflakeConnectionService
public class SnowflakeConnectionServiceV1 extends Object implements SnowflakeConnectionService
Implementation of Snowflake Connection Service interface which includes all handshake between KC and SF through JDBC connection.
-
-
Field Summary
Fields Modifier and Type Field Description static StringUSER_AGENT_SUFFIX_FORMAT
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidalterNonNullableColumns(String tableName, List<String> columnNames)Alter table to drop non-nullability of a list of columnsvoidappendColumnsToTable(String tableName, Map<String,String> columnToType)Alter table to add columns according to a map from columnNames to their typesvoidappendMetaColIfNotExist(String tableName)Append a VARIANT type column "RECORD_METADATA" to the table if it is not present.SnowflakeIngestionServicebuildIngestService(String stageName, String pipeName)build ingest service instance for given stage and pipevoidclose()Close ConnectionvoidcreatePipe(String tableName, String stageName, String pipeName)create a snowpipe if not existsvoidcreatePipe(String tableName, String stageName, String pipeName, boolean overwrite)create a snowpipevoidcreateStage(String stageName)create stage if not existsvoidcreateStage(String stageName, boolean overwrite)create a stagevoidcreateTable(String tableName)create table is not existsvoidcreateTable(String tableName, boolean overwrite)Create a table with two variant columns: RECORD_METADATA and RECORD_CONTENTvoidcreateTableWithOnlyMetadataColumn(String tableName)Create a table with only the RECORD_METADATA column.voiddatabaseExists(String databaseName)check if a given database existsvoiddropPipe(String pipeName)drop snowpipevoiddropStage(String stageName)drop stagebooleandropStageIfEmpty(String stageName)drop stage if the given stage is emptyprotected ChannelMigrateOffsetTokenResponseDTOgetChannelMigrateOffsetTokenResponseDTO(String migrateOffsetTokenResultFromSysFunc)ConnectiongetConnection()StringgetConnectorName()SnowflakeInternalStagegetInternalStage()SnowflakeTelemetryServicegetTelemetryClient()booleanhasSchemaEvolutionPermission(String tableName, String role)Check whether the user has the role privilege to do schema evolution and whether the schema evolution option is enabled on the tablebooleanisClosed()booleanisPipeCompatible(String tableName, String stageName, String pipeName)check snowpipe definitionbooleanisStageCompatible(String stageName)Examine all file names matches our patternbooleanisTableCompatible(String tableName)Check the given table has correct schema correct schema: (record_metadata variant, record_content variant)List<String>listStage(String stageName, String prefix)list a non table stage and return a list of file names contained in given subdirectoryList<String>listStage(String stageName, String prefix, boolean isTableStage)list a stage and return a list of file names contained in given subdirectoryChannelMigrateOffsetTokenResponseDTOmigrateStreamingChannelOffsetToken(String tableName, String sourceChannelName, String destinationChannelName)Migrate Streaming Channel offsetToken from a source Channel to a destination channel.voidmoveToTableStage(String tableName, String stageName, String prefix)move all files on stage related to given pipe to table stagevoidmoveToTableStage(String tableName, String stageName, List<String> files)booleanpipeExist(String pipeName)check pipe existencevoidpurgeStage(String stageName, List<String> files)purge files from given stagevoidput(String stageName, String fileName, String content)Deprecated.voidputToTableStage(String tableName, String fileName, byte[] content)put a file to table stagevoidputWithCache(String stageName, String fileName, String content)put a file to stage.voidschemaExists(String schemaName)check if a given schema existsbooleanstageExist(String stageName)check stage existencebooleantableExist(String tableName)check table existence
-
-
-
Field Detail
-
USER_AGENT_SUFFIX_FORMAT
public static final String USER_AGENT_SUFFIX_FORMAT
- See Also:
- Constant Field Values
-
-
Method Detail
-
createTable
public void createTable(String tableName, boolean overwrite)
Description copied from interface:SnowflakeConnectionServiceCreate a table with two variant columns: RECORD_METADATA and RECORD_CONTENT- Specified by:
createTablein interfaceSnowflakeConnectionService- Parameters:
tableName- a string represents table nameoverwrite- if true, execute "create or replace table" query; otherwise, run "create table if not exists"
-
createTable
public void createTable(String tableName)
Description copied from interface:SnowflakeConnectionServicecreate table is not exists- Specified by:
createTablein interfaceSnowflakeConnectionService- Parameters:
tableName- table name
-
createTableWithOnlyMetadataColumn
public void createTableWithOnlyMetadataColumn(String tableName)
Description copied from interface:SnowflakeConnectionServiceCreate a table with only the RECORD_METADATA column. The rest of the columns might be added through schema evolutionIn the beginning of the function we will check if we have the permission to do schema evolution, and we will error out if we don't
- Specified by:
createTableWithOnlyMetadataColumnin interfaceSnowflakeConnectionService- Parameters:
tableName- table name
-
createPipe
public void createPipe(String tableName, String stageName, String pipeName, boolean overwrite)
Description copied from interface:SnowflakeConnectionServicecreate a snowpipe- Specified by:
createPipein interfaceSnowflakeConnectionService- Parameters:
tableName- table namestageName- stage namepipeName- pipe nameoverwrite- if true, execute "create or replace pipe" statement, otherwise, run "create pipe if not exists"
-
createPipe
public void createPipe(String tableName, String stageName, String pipeName)
Description copied from interface:SnowflakeConnectionServicecreate a snowpipe if not exists- Specified by:
createPipein interfaceSnowflakeConnectionService- Parameters:
tableName- table namestageName- stage namepipeName- pipe name
-
createStage
public void createStage(String stageName, boolean overwrite)
Description copied from interface:SnowflakeConnectionServicecreate a stage- Specified by:
createStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage nameoverwrite- if true, execute "create or replace stage" statement; otherwise, run "create stage if not exists"
-
createStage
public void createStage(String stageName)
Description copied from interface:SnowflakeConnectionServicecreate stage if not exists- Specified by:
createStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage name
-
tableExist
public boolean tableExist(String tableName)
Description copied from interface:SnowflakeConnectionServicecheck table existence- Specified by:
tableExistin interfaceSnowflakeConnectionService- Parameters:
tableName- table name- Returns:
- true if table exists, false otherwise
-
stageExist
public boolean stageExist(String stageName)
Description copied from interface:SnowflakeConnectionServicecheck stage existence- Specified by:
stageExistin interfaceSnowflakeConnectionService- Parameters:
stageName- stage name- Returns:
- true if stage exists, false otherwise
-
pipeExist
public boolean pipeExist(String pipeName)
Description copied from interface:SnowflakeConnectionServicecheck pipe existence- Specified by:
pipeExistin interfaceSnowflakeConnectionService- Parameters:
pipeName- pipe name- Returns:
- true if pipe exists, false otherwise
-
isTableCompatible
public boolean isTableCompatible(String tableName)
Description copied from interface:SnowflakeConnectionServiceCheck the given table has correct schema correct schema: (record_metadata variant, record_content variant)- Specified by:
isTableCompatiblein interfaceSnowflakeConnectionService- Parameters:
tableName- table name- Returns:
- true if schema is correct, false is schema is incorrect or table does not exist
-
appendMetaColIfNotExist
public void appendMetaColIfNotExist(String tableName)
Description copied from interface:SnowflakeConnectionServiceAppend a VARIANT type column "RECORD_METADATA" to the table if it is not present.This method is only called when schematization is enabled
- Specified by:
appendMetaColIfNotExistin interfaceSnowflakeConnectionService- Parameters:
tableName- table name
-
hasSchemaEvolutionPermission
public boolean hasSchemaEvolutionPermission(String tableName, String role)
Check whether the user has the role privilege to do schema evolution and whether the schema evolution option is enabled on the table- Specified by:
hasSchemaEvolutionPermissionin interfaceSnowflakeConnectionService- Parameters:
tableName- the name of the tablerole- the role of the user- Returns:
- whether schema evolution has the required permission to be performed
-
appendColumnsToTable
public void appendColumnsToTable(String tableName, Map<String,String> columnToType)
Alter table to add columns according to a map from columnNames to their types- Specified by:
appendColumnsToTablein interfaceSnowflakeConnectionService- Parameters:
tableName- the name of the tablecolumnToType- the mapping from the columnNames to their types
-
alterNonNullableColumns
public void alterNonNullableColumns(String tableName, List<String> columnNames)
Alter table to drop non-nullability of a list of columns- Specified by:
alterNonNullableColumnsin interfaceSnowflakeConnectionService- Parameters:
tableName- the name of the tablecolumnNames- the list of columnNames
-
isStageCompatible
public boolean isStageCompatible(String stageName)
Description copied from interface:SnowflakeConnectionServiceExamine all file names matches our pattern- Specified by:
isStageCompatiblein interfaceSnowflakeConnectionService- Parameters:
stageName- stage name- Returns:
- true is stage is compatible, false if stage does not exist or file name invalid
-
isPipeCompatible
public boolean isPipeCompatible(String tableName, String stageName, String pipeName)
Description copied from interface:SnowflakeConnectionServicecheck snowpipe definition- Specified by:
isPipeCompatiblein interfaceSnowflakeConnectionService- Parameters:
tableName- table namestageName- stage namepipeName- pipe name- Returns:
- true if definition is correct, false if it is incorrect or pipe does not exists
-
databaseExists
public void databaseExists(String databaseName)
Description copied from interface:SnowflakeConnectionServicecheck if a given database exists- Specified by:
databaseExistsin interfaceSnowflakeConnectionService- Parameters:
databaseName- database name
-
schemaExists
public void schemaExists(String schemaName)
Description copied from interface:SnowflakeConnectionServicecheck if a given schema exists- Specified by:
schemaExistsin interfaceSnowflakeConnectionService- Parameters:
schemaName- schema name
-
dropPipe
public void dropPipe(String pipeName)
Description copied from interface:SnowflakeConnectionServicedrop snowpipe- Specified by:
dropPipein interfaceSnowflakeConnectionService- Parameters:
pipeName- pipe name
-
dropStageIfEmpty
public boolean dropStageIfEmpty(String stageName)
Description copied from interface:SnowflakeConnectionServicedrop stage if the given stage is empty- Specified by:
dropStageIfEmptyin interfaceSnowflakeConnectionService- Parameters:
stageName- stage name- Returns:
- true if stage dropped, otherwise false
-
dropStage
public void dropStage(String stageName)
Description copied from interface:SnowflakeConnectionServicedrop stage- Specified by:
dropStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage name
-
purgeStage
public void purgeStage(String stageName, List<String> files)
Description copied from interface:SnowflakeConnectionServicepurge files from given stage- Specified by:
purgeStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage namefiles- list of file names
-
moveToTableStage
public void moveToTableStage(String tableName, String stageName, List<String> files)
- Specified by:
moveToTableStagein interfaceSnowflakeConnectionService
-
moveToTableStage
public void moveToTableStage(String tableName, String stageName, String prefix)
Description copied from interface:SnowflakeConnectionServicemove all files on stage related to given pipe to table stage- Specified by:
moveToTableStagein interfaceSnowflakeConnectionService- Parameters:
tableName- table namestageName- stage nameprefix- prefix name
-
listStage
public List<String> listStage(String stageName, String prefix, boolean isTableStage)
Description copied from interface:SnowflakeConnectionServicelist a stage and return a list of file names contained in given subdirectory- Specified by:
listStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage nameprefix- prefix nameisTableStage- true if it is a table stage- Returns:
- a list of file names in given subdirectory, file name = "{prefix}filename"
-
listStage
public List<String> listStage(String stageName, String prefix)
Description copied from interface:SnowflakeConnectionServicelist a non table stage and return a list of file names contained in given subdirectory- Specified by:
listStagein interfaceSnowflakeConnectionService- Parameters:
stageName- stage nameprefix- prefix name- Returns:
- a list of file names in given subdirectory, file name = "{prefix}filename"
-
put
@Deprecated public void put(String stageName, String fileName, String content)
Deprecated.Description copied from interface:SnowflakeConnectionServiceput a file to stage- Specified by:
putin interfaceSnowflakeConnectionService- Parameters:
stageName- stage namefileName- file namecontent- file content
-
putWithCache
public void putWithCache(String stageName, String fileName, String content)
Description copied from interface:SnowflakeConnectionServiceput a file to stage. Cache credential for AWS, Azure and GCS storage.- Specified by:
putWithCachein interfaceSnowflakeConnectionService- Parameters:
stageName- stage namefileName- file name which is of format (stageName/connectorName/tableName/partition/offsetStart_offsetEnd_timestamp)content- file content
-
putToTableStage
public void putToTableStage(String tableName, String fileName, byte[] content)
Description copied from interface:SnowflakeConnectionServiceput a file to table stage- Specified by:
putToTableStagein interfaceSnowflakeConnectionService- Parameters:
tableName- table namefileName- file namecontent- file content
-
getTelemetryClient
public SnowflakeTelemetryService getTelemetryClient()
- Specified by:
getTelemetryClientin interfaceSnowflakeConnectionService- Returns:
- telemetry client
-
close
public void close()
Description copied from interface:SnowflakeConnectionServiceClose Connection- Specified by:
closein interfaceSnowflakeConnectionService
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceSnowflakeConnectionService- Returns:
- true is connection is closed
-
getConnectorName
public String getConnectorName()
- Specified by:
getConnectorNamein interfaceSnowflakeConnectionService- Returns:
- name of Kafka Connector instance
-
buildIngestService
public SnowflakeIngestionService buildIngestService(String stageName, String pipeName)
Description copied from interface:SnowflakeConnectionServicebuild ingest service instance for given stage and pipe- Specified by:
buildIngestServicein interfaceSnowflakeConnectionService- Parameters:
stageName- stage namepipeName- pipe name- Returns:
- an instance of SnowflakeIngestService
-
getConnection
public Connection getConnection()
- Specified by:
getConnectionin interfaceSnowflakeConnectionService- Returns:
- the raw jdbc connection
-
getInternalStage
public SnowflakeInternalStage getInternalStage()
-
migrateStreamingChannelOffsetToken
public ChannelMigrateOffsetTokenResponseDTO migrateStreamingChannelOffsetToken(String tableName, String sourceChannelName, String destinationChannelName)
Description copied from interface:SnowflakeConnectionServiceMigrate Streaming Channel offsetToken from a source Channel to a destination channel.Here, source channel is the new channel format we created here * @see Commit
Destination channel is the original Format containing only topicName and partition number.
We catch SQLException and JsonProcessingException that might happen in this method. The caller should always open the Old Channel format. This old channel format will also be the key to many HashMaps we will create. (For instance
SnowflakeSinkServiceV2.partitionsToChannel)- Specified by:
migrateStreamingChannelOffsetTokenin interfaceSnowflakeConnectionService- Parameters:
tableName- Name of the tablesourceChannelName- sourceChannel name from where the offset Token will be fetched. Channel with this name will also be deleted.destinationChannelName- destinationChannel name to where the offsetToken will be copied over.- Returns:
- The DTO serialized from the migration response.
-
getChannelMigrateOffsetTokenResponseDTO
protected ChannelMigrateOffsetTokenResponseDTO getChannelMigrateOffsetTokenResponseDTO(String migrateOffsetTokenResultFromSysFunc) throws com.fasterxml.jackson.core.JsonProcessingException
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
-