Class SnowflakeClient


  • public class SnowflakeClient
    extends Object
    Class that uses the snowflake jdbc to connect to snowflake. Executes the commands TODO: modify exception handling
    • Constructor Detail

      • SnowflakeClient

        public SnowflakeClient()
    • Method Detail

      • createAndExecuteCommandForSnowflake

        public static void createAndExecuteCommandForSnowflake​(org.apache.hadoop.hive.metastore.events.ListenerEvent event,
                                                               SnowflakeConf snowflakeConf)
        Creates and executes an event for snowflake. Events may be processed in the background, but events on the same table will be processed in order.
        Parameters:
        event - - the hive event details
        snowflakeConf - - the configuration for Snowflake Hive metastore
      • generateAndExecuteSnowflakeStatements

        public static void generateAndExecuteSnowflakeStatements​(Command command,
                                                                 SnowflakeConf snowflakeConf)
        Helper method. Generates commands for an event and executes those commands. Synchronous.
        Parameters:
        command - - the command to generate statements from
        snowflakeConf - - the configuration for Snowflake Hive metastore
      • executeStatements

        public static void executeStatements​(List<String> commandList,
                                             SnowflakeConf snowflakeConf,
                                             String schema)
        Helper method to connect to Snowflake and execute a list of queries
        Parameters:
        commandList - - The list of queries to execute
        snowflakeConf - - the configuration for Snowflake Hive metastore listener
        schema - - the schema to use for the jdbc connection
      • executeStatement

        public static ResultSet executeStatement​(Connection connection,
                                                 String commandStr,
                                                 SnowflakeConf snowflakeConf)
                                          throws SQLException
        (Deprecated) Utility method to connect to Snowflake and execute a query.
        Parameters:
        connection - - The connection to use
        commandStr - - The query to execute
        snowflakeConf - - the configuration for Snowflake Hive metastore listener
        Returns:
        The result of the executed query
        Throws:
        SQLException - Thrown if there was an error executing the statement or forming a connection.
      • getConnection

        public static Connection getConnection​(SnowflakeConf snowflakeConf,
                                               String schema)
                                        throws SQLException
        Get the connection to the Snowflake account. First finds a Snowflake driver and connects to Snowflake using the given properties.
        Parameters:
        snowflakeConf - - the configuration for Snowflake Hive metastore listener
        schema - - the schema to use for the connection
        Returns:
        The JDBC connection
        Throws:
        SQLException - Exception thrown when initializing the connection
      • retry

        public static <T,​E extends Throwable> T retry​(SnowflakeClient.ThrowableSupplier<T,​E> method,
                                                            SnowflakeConf snowflakeConf)
                                                     throws E extends Throwable
        Helper method for simple retries. Overload for default arguments.
        Type Parameters:
        T - The type of object returned by the supplier
        E - The type of exception thrown by the supplier
        Parameters:
        method - The method to be executed and retried on.
        snowflakeConf - The snowflake configuration to use.
        Returns:
        The result of the method.
        Throws:
        E extends Throwable