Access and Query Amazon Athena via DBI/JDBC
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

69 linhas
2.9KB

  1. #' Simplified Athena JDBC connection helper
  2. #'
  3. #' Handles the up-front JDBC config
  4. #'
  5. #' @md
  6. #' @param default_schema default schema (you'll still need to fully qualify non-default schema table names)
  7. #' @param region AWS region (Ref: <http://docs.aws.amazon.com/general/latest/gr/rande.html#athena>)
  8. #' @param s3_staging_dir the Amazon S3 location to which your query output is written. The JDBC driver then asks Athena to read the results and provide rows of data back to the user.
  9. #' @param max_error_retries the maximum number of retries that the JDBC client attempts to make a request to Athena.
  10. #' @param connection_timeout the maximum amount of time, in milliseconds, to make a successful connection to Athena before an attempt is terminated.
  11. #' @param socket_timeout the maximum amount of time, in milliseconds, to wait for a socket in order to send data to Athena.
  12. # @param retry_base_delay minimum delay amount, in milliseconds, between retrying attempts to connect Athena.
  13. # @param retry_max_backoff_time maximum delay amount, in milliseconds, between retrying attempts to connect Athena.
  14. #' @param log_path local path of the Athena JDBC driver logs. If no log path is provided, then no log files are created.
  15. #' @param log_level log level of the Athena JDBC driver logs. Use names
  16. #' "OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE".
  17. #' @param ... passed on to the driver
  18. #' @export
  19. #' @references [Connect with JDBC](https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html);
  20. #' [Simba Athena JDBC Driver with SQL Connector Installation and Configuration Guide](https://s3.amazonaws.com/athena-downloads/drivers/JDBC/SimbaAthenaJDBC_2.0.6/docs/Simba+Athena+JDBC+Driver+Install+and+Configuration+Guide.pdf)
  21. #' @examples \dontrun{
  22. #' use_credentials("personal")
  23. #'
  24. #' athena_connect(
  25. #' default_schema = "sampledb",
  26. #' s3_staging_dir = "s3://accessible-bucket",
  27. #' log_path = "/tmp/athena.log",
  28. #' log_level = "DEBUG"
  29. #' ) -> ath
  30. #'
  31. #' dbListTables(ath)
  32. #'
  33. #' dbGetQuery(ath, "SELECT * FROM sampledb.elb_logs LIMIT 1")
  34. #'
  35. #' }
  36. athena_connect <- function(
  37. default_schema = "default",
  38. region = c("us-east-1", "us-east-2", "us-west-2"),
  39. s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
  40. max_error_retries = 10,
  41. connection_timeout = 10000,
  42. socket_timeout = 10000,
  43. log_path = "",
  44. log_level = c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"),
  45. ...
  46. ) {
  47. athena_jdbc <- Athena()
  48. region <- match.arg(region, c("us-east-1", "us-east-2", "us-west-2"))
  49. log_level <- match.arg(log_level, c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"))
  50. dbConnect(
  51. athena_jdbc,
  52. schema_name = default_schema,
  53. region = region,
  54. s3_staging_dir = s3_staging_dir,
  55. max_error_retries = max_error_retries,
  56. connection_timeout = connection_timeout,
  57. socket_timeout = socket_timeout,
  58. log_path = log_path,
  59. log_level = log_level,
  60. ...
  61. ) -> con
  62. con
  63. }