Access and Query Amazon Athena via DBI/JDBC
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

76 řádky
3.1KB

  1. #' Simplified Athena JDBC connection helper
  2. #'
  3. #' Handles the up-front JDBC config
  4. #'
  5. #' @md
  6. #' @param default_schema the name of the database schema to use when a schema is
  7. #' not explicitly specified in a query. You can still issue queries on other
  8. #' schemas by explicitly specifying the schema in the query.
  9. #' @param provider JDBC auth provider (defaults to `com.simba.athena.amazonaws.auth.DefaultAWSCredentialsProviderChain`)
  10. #' @param region AWS region (Ref: <http://docs.aws.amazon.com/general/latest/gr/rande.html#athena>)
  11. #' @param s3_staging_dir the Amazon S3 location to which your query output is written.
  12. #' The JDBC driver then asks Athena to read the results and provide rows
  13. #' of data back to the user.
  14. #' @param max_error_retries the maximum number of retries that the JDBC client
  15. #' attempts to make a request to Athena.
  16. #' @param connection_timeout the maximum amount of time, in milliseconds, to
  17. #' make a successful connection to Athena before an attempt is terminated.
  18. #' @param socket_timeout the maximum amount of time, in milliseconds, to wait
  19. #' for a socket in order to send data to Athena.
  20. #' @param log_path local path of the Athena JDBC driver logs. If no log path is
  21. #' provided, then no log files are created.
  22. #' @param log_level log level of the Athena JDBC driver logs. Use names
  23. #' "OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE".
  24. #' @param ... passed on to the driver
  25. #' @export
  26. #' @references [Connect with JDBC](https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html);
  27. #' [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)
  28. #' @examples \dontrun{
  29. #' use_credentials("personal")
  30. #'
  31. #' athena_connect(
  32. #' default_schema = "sampledb",
  33. #' s3_staging_dir = "s3://accessible-bucket",
  34. #' log_path = "/tmp/athena.log",
  35. #' log_level = "DEBUG"
  36. #' ) -> ath
  37. #'
  38. #' dbListTables(ath)
  39. #'
  40. #' dbGetQuery(ath, "SELECT * FROM sampledb.elb_logs LIMIT 1")
  41. #'
  42. #' }
  43. athena_connect <- function(
  44. default_schema = "default",
  45. provider = "com.simba.athena.amazonaws.auth.DefaultAWSCredentialsProviderChain",
  46. region = c("us-east-1", "us-east-2", "us-west-2"),
  47. s3_staging_dir = Sys.getenv("AWS_S3_STAGING_DIR"),
  48. max_error_retries = 10,
  49. connection_timeout = 10000,
  50. socket_timeout = 10000,
  51. log_path = "",
  52. log_level = c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"),
  53. ...
  54. ) {
  55. athena_jdbc <- Athena()
  56. region <- match.arg(region, c("us-east-1", "us-east-2", "us-west-2"))
  57. log_level <- match.arg(log_level, c("OFF", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"))
  58. dbConnect(
  59. athena_jdbc,
  60. Schema = default_schema,
  61. AwsRegion = region,
  62. S3OutputLocation = s3_staging_dir,
  63. MaxErrorRetry = max_error_retries,
  64. ConnectTimeout = connection_timeout,
  65. SocketTimeout = socket_timeout,
  66. LogPath = log_path,
  67. LogLevel = log_level,
  68. AwsCredentialsProviderClass= provider,
  69. ...
  70. ) -> con
  71. }