Interface SnowflakeConnectionService
-
- All Known Implementing Classes:
SnowflakeConnectionServiceV1
public interface SnowflakeConnectionService
-
-
Method Summary
All Methods Instance Methods Abstract 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 emptyConnectiongetConnection()StringgetConnectorName()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 subdirectoryvoidmoveToTableStage(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
-
-
-
Method Detail
-
createTable
void createTable(String tableName, boolean overwrite)
Create a table with two variant columns: RECORD_METADATA and RECORD_CONTENT- Parameters:
tableName- a string represents table nameoverwrite- if true, execute "create or replace table" query; otherwise, run "create table if not exists"
-
createTable
void createTable(String tableName)
create table is not exists- Parameters:
tableName- table name
-
createPipe
void createPipe(String tableName, String stageName, String pipeName, boolean overwrite)
create a snowpipe- Parameters:
pipeName- pipe nametableName- table namestageName- stage nameoverwrite- if true, execute "create or replace pipe" statement, otherwise, run "create pipe if not exists"
-
createPipe
void createPipe(String tableName, String stageName, String pipeName)
create a snowpipe if not exists- Parameters:
pipeName- pipe nametableName- table namestageName- stage name
-
createStage
void createStage(String stageName, boolean overwrite)
create a stage- Parameters:
stageName- stage nameoverwrite- if true, execute "create or replace stage" statement; otherwise, run "create stage if not exists"
-
createStage
void createStage(String stageName)
create stage if not exists- Parameters:
stageName- stage name
-
tableExist
boolean tableExist(String tableName)
check table existence- Parameters:
tableName- table name- Returns:
- true if table exists, false otherwise
-
stageExist
boolean stageExist(String stageName)
check stage existence- Parameters:
stageName- stage name- Returns:
- true if stage exists, false otherwise
-
pipeExist
boolean pipeExist(String pipeName)
check pipe existence- Parameters:
pipeName- pipe name- Returns:
- true if pipe exists, false otherwise
-
isTableCompatible
boolean isTableCompatible(String tableName)
Check the given table has correct schema correct schema: (record_metadata variant, record_content variant)- Parameters:
tableName- table name- Returns:
- true if schema is correct, false is schema is incorrect or table does not exist
-
hasSchemaEvolutionPermission
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- Parameters:
tableName- the name of the tablerole- the role of the user- Returns:
- whether table and role has the required permission to perform schema evolution
-
appendColumnsToTable
void appendColumnsToTable(String tableName, Map<String,String> columnToType)
Alter table to add columns according to a map from columnNames to their types- Parameters:
tableName- the name of the tablecolumnToType- the mapping from the columnNames to their types
-
alterNonNullableColumns
void alterNonNullableColumns(String tableName, List<String> columnNames)
Alter table to drop non-nullability of a list of columns- Parameters:
tableName- the name of the tablecolumnNames- the list of columnNames
-
isStageCompatible
boolean isStageCompatible(String stageName)
Examine all file names matches our pattern- Parameters:
stageName- stage name- Returns:
- true is stage is compatible, false if stage does not exist or file name invalid
-
isPipeCompatible
boolean isPipeCompatible(String tableName, String stageName, String pipeName)
check snowpipe definition- Parameters:
pipeName- pipe nametableName- table namestageName- stage name- Returns:
- true if definition is correct, false if it is incorrect or pipe does not exists
-
databaseExists
void databaseExists(String databaseName)
check if a given database exists- Parameters:
databaseName- database name
-
schemaExists
void schemaExists(String schemaName)
check if a given schema exists- Parameters:
schemaName- schema name
-
dropPipe
void dropPipe(String pipeName)
drop snowpipe- Parameters:
pipeName- pipe name
-
dropStageIfEmpty
boolean dropStageIfEmpty(String stageName)
drop stage if the given stage is empty- Parameters:
stageName- stage name- Returns:
- true if stage dropped, otherwise false
-
dropStage
void dropStage(String stageName)
drop stage- Parameters:
stageName- stage name
-
purgeStage
void purgeStage(String stageName, List<String> files)
purge files from given stage- Parameters:
stageName- stage namefiles- list of file names
-
moveToTableStage
void moveToTableStage(String tableName, String stageName, String prefix)
move all files on stage related to given pipe to table stage- Parameters:
stageName- stage nametableName- table nameprefix- prefix name
-
listStage
List<String> listStage(String stageName, String prefix, boolean isTableStage)
list a stage and return a list of file names contained in given subdirectory- 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
List<String> listStage(String stageName, String prefix)
list a non table stage and return a list of file names contained in given subdirectory- Parameters:
stageName- stage nameprefix- prefix name- Returns:
- a list of file names in given subdirectory, file name = "{prefix}filename"
-
put
@Deprecated void put(String stageName, String fileName, String content)
Deprecated.put a file to stage- Parameters:
fileName- file namecontent- file contentstageName- stage name
-
putWithCache
void putWithCache(String stageName, String fileName, String content)
put a file to stage. Cache credential for AWS, Azure and GCS storage.- Parameters:
fileName- file name which is of format (stageName/connectorName/tableName/partition/offsetStart_offsetEnd_timestamp)content- file contentstageName- stage name
-
putToTableStage
void putToTableStage(String tableName, String fileName, byte[] content)
put a file to table stage- Parameters:
tableName- table namefileName- file namecontent- file content
-
getTelemetryClient
SnowflakeTelemetryService getTelemetryClient()
- Returns:
- telemetry client
-
close
void close()
Close Connection
-
isClosed
boolean isClosed()
- Returns:
- true is connection is closed
-
getConnectorName
String getConnectorName()
- Returns:
- name of Kafka Connector instance
-
buildIngestService
SnowflakeIngestionService buildIngestService(String stageName, String pipeName)
build ingest service instance for given stage and pipe- Parameters:
stageName- stage namepipeName- pipe name- Returns:
- an instance of SnowflakeIngestService
-
getConnection
Connection getConnection()
- Returns:
- the raw jdbc connection
-
appendMetaColIfNotExist
void appendMetaColIfNotExist(String tableName)
Append a VARIANT type column "RECORD_METADATA" to the table if it is not present.This method is only called when schematization is enabled
- Parameters:
tableName- table name
-
createTableWithOnlyMetadataColumn
void createTableWithOnlyMetadataColumn(String tableName)
Create 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
- Parameters:
tableName- table name
-
-