Class Utils


  • public class Utils
    extends Object
    Various arbitrary helper functions
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • quoteNameIfNeeded

        public static String quoteNameIfNeeded​(String name)
        Quote the column name if needed: When there is quote already, we do nothing; otherwise we convert the name to upper case and add quote
      • stageName

        public static String stageName​(String appName,
                                       String table)
        generate stage name by given table
        Parameters:
        appName - connector name
        table - table name
        Returns:
        stage name
      • pipeName

        public static String pipeName​(String appName,
                                      String table,
                                      int partition)
        generate pipe name by given table and partition
        Parameters:
        appName - connector name
        table - table name
        partition - partition name
        Returns:
        pipe name
      • setJDBCLoggingDirectory

        public static void setJDBCLoggingDirectory()
        Read JDBC logging directory from environment variable JDBC_LOG_DIR and set that in System property
      • convertAppName

        public static void convertAppName​(Map<String,​String> config)
        modify invalid application name in config and return the generated application name
        Parameters:
        config - input config object
      • tableName

        public static String tableName​(String topic,
                                       Map<String,​String> topic2table)
        verify topic name, and generate valid table name
        Parameters:
        topic - input topic name
        topic2table - topic to table map
        Returns:
        valid table name
      • generateValidName

        public static String generateValidName​(String topic,
                                               Map<String,​String> topic2table)
        verify topic name, and generate valid table/application name
        Parameters:
        topic - input topic name
        topic2table - topic to table map
        Returns:
        valid table/application name
      • isSingleFieldValid

        public static boolean isSingleFieldValid​(org.apache.kafka.common.config.Config result)
      • validateConfigToMap

        public static Map<String,​org.apache.kafka.common.config.ConfigValue> validateConfigToMap​(org.apache.kafka.common.config.Config result)
      • updateConfigErrorMessage

        public static void updateConfigErrorMessage​(org.apache.kafka.common.config.Config result,
                                                    String key,
                                                    String msg)
      • formatLogMessage

        public static String formatLogMessage​(String format,
                                              Object... vars)
        the following method wraps log messages with Snowflake tag. For example,

        [SF_KAFKA_CONNECTOR] this is a log message

        [SF_KAFKA_CONNECTOR] this is the second line

        All log messages should be wrapped by Snowflake tag. Then user can filter out log messages output from Snowflake Kafka connector by these tags.

        Parameters:
        format - log message format string
        vars - variable list
        Returns:
        log message wrapped by snowflake tag
      • getSnowflakeOAuthAccessToken

        public static String getSnowflakeOAuthAccessToken​(SnowflakeURL url,
                                                          String clientId,
                                                          String clientSecret,
                                                          String refreshToken)
        Get OAuth access token given refresh token
        Parameters:
        url - OAuth server url
        clientId - OAuth clientId
        clientSecret - OAuth clientSecret
        refreshToken - OAuth refresh token
        Returns:
        OAuth access token
      • getSnowflakeOAuthToken

        public static String getSnowflakeOAuthToken​(SnowflakeURL url,
                                                    String clientId,
                                                    String clientSecret,
                                                    String credential,
                                                    String grantType,
                                                    String credentialType,
                                                    String tokenType)
        Get OAuth token given integration info Snowflake OAuth Overview
        Parameters:
        url - OAuth server url
        clientId - OAuth clientId
        clientSecret - OAuth clientSecret
        credential - OAuth credential, either az code or refresh token
        grantType - OAuth grant type, either authorization_code or refresh_token
        credentialType - OAuth credential key, either code or refresh_token
        tokenType - type of OAuth token to get, either access_token or refresh_token
        Returns:
        OAuth token
      • buildOAuthHttpPostRequest

        public static net.snowflake.client.jdbc.internal.apache.http.client.methods.HttpPost buildOAuthHttpPostRequest​(SnowflakeURL url,
                                                                                                                       String path,
                                                                                                                       Map<String,​String> headers,
                                                                                                                       net.snowflake.client.jdbc.internal.apache.http.entity.StringEntity entity)
        Build OAuth http post request base on headers and payload
        Parameters:
        url - target url
        headers - headers key value pairs
        entity - payload entity
        Returns:
        HttpPost request for OAuth
      • getExceptionMessage

        public static String getExceptionMessage​(String customMessage,
                                                 Exception ex)
        Get the message and cause of a missing exception, handling the null or empty cases of each
        Parameters:
        customMessage - A custom message to prepend to the exception
        ex - The message to parse through
        Returns:
        A string with the custom message and the exceptions message or cause, if exists