Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/main/scala/scalikejdbc/athena/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.collection.JavaConverters._
import scala.util.Try

class Config(dbName: Any) {

import Config._

private[this] val prefix = "athena." + (dbName match {
Expand Down Expand Up @@ -36,11 +37,16 @@ class Config(dbName: Any) {

private[athena] lazy val options: Properties = {
val p = new Properties()
(map.get(S3OutputLocation), map.get(S3OutputLocationPrefix)) match {
case (Some(d), Some(p)) => throw new ConfigException(s"duplicate settings: $prefix.$S3OutputLocation=$d, $prefix.$S3OutputLocationPrefix=$p")
case (Some(v), _) => p.setProperty(S3OutputLocation, v)
case (_, Some(v)) => p.setProperty(S3OutputLocation, s"$v/${UUID.randomUUID()}")
case _ => throw new ConfigException(s"no configuration setting: key=$prefix.$S3OutputLocation, $prefix.$S3OutputLocationPrefix")
// driver v3:WorkGroup, v2:Workgroup
// If workgroups is missing (fallback to primary workgroup), S3OutputLocation is mandatory.
// However, if any user-defined workgroup is specified, S3OutputLocation is optional.
if (!map.get("WorkGroup").orElse(map.get("Workgroup")).exists(_ != "primary")) {
(map.get(S3OutputLocation), map.get(S3OutputLocationPrefix)) match {
case (Some(d), Some(p)) => throw new ConfigException(s"duplicate settings: $prefix.$S3OutputLocation=$d, $prefix.$S3OutputLocationPrefix=$p")
case (Some(v), _) => p.setProperty(S3OutputLocation, v)
case (_, Some(v)) => p.setProperty(S3OutputLocation, s"$v/${UUID.randomUUID()}")
case _ => throw new ConfigException(s"no configuration setting: key=$prefix.$S3OutputLocation, $prefix.$S3OutputLocationPrefix")
}
}
map.foreach { entry =>
val (name, value) = entry
Expand Down
18 changes: 17 additions & 1 deletion src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ athena {
S3OutputLocation="s3://query-results-bucket/folder/"
LogPath="logs/application.log"
}
workgroup-only {
driver="com.amazon.athena.jdbc.AthenaDriver"
url="jdbc:athena://AwsRegion=us-east-2"
readOnly="false"
AwsCredentialsProviderClass="DefaultChain"
LogPath="logs/application.log"
WorkGroup="my-own-workgroup"
}
workgroup-primary {
driver="com.amazon.athena.jdbc.AthenaDriver"
url="jdbc:athena://AwsRegion=us-east-2"
readOnly="false"
AwsCredentialsProviderClass="DefaultChain"
LogPath="logs/application.log"
WorkGroup="primary"
}
athena {
driver="com.amazon.athena.jdbc.AthenaDriver"
url="jdbc:athena://AwsRegion=ap-southeast-1"
Expand Down Expand Up @@ -44,7 +60,7 @@ athena {
driver="com.simba.athena.jdbc.Driver"
url="jdbc:awsathena://AwsRegion=us-east-2"
readOnly="false"
S3OutputLocation="s3://query-results-bucket/folder/"
Workgroup="my-own-workgroup"
AwsCredentialsProviderClass="com.simba.athena.amazonaws.auth.profile.ProfileCredentialsProvider"
LogPath="logs/application.log"
LogLevel=3
Expand Down
16 changes: 15 additions & 1 deletion src/test/scala/scalikejdbc/athena/ConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ class ConfigSpec extends AnyFunSpec with OptionValues {
assert(config.readOnly.value === false)
assert(config.timeZone.isEmpty)
}
it("workgropup") {
val config = new Config("workgroup-only")
assert(config.url === "jdbc:athena://AwsRegion=us-east-2")
assert(config.options.getProperty("S3OutputLocation") === null)
assert(config.options.getProperty("WorkGroup") === "my-own-workgroup")
assert(config.options.getProperty("LogPath") === "logs/application.log")
assert(config.getTmpStagingDir.isEmpty)
assert(config.readOnly.value === false)
assert(config.timeZone.isEmpty)
}
it("primary workgroupRequires S3OutputLocation") {
assertThrows[ConfigException](new Config("workgroup-primary").options)
}
it("named db") {
val config = new Config("athena")
assert(config.url === "jdbc:athena://AwsRegion=ap-southeast-1")
Expand All @@ -35,7 +48,8 @@ class ConfigSpec extends AnyFunSpec with OptionValues {
it("v2") {
val config = new Config("v2.default")
assert(config.url === "jdbc:awsathena://AwsRegion=us-east-2")
assert(config.options.getProperty("S3OutputLocation") === "s3://query-results-bucket/folder/")
assert(config.options.getProperty("S3OutputLocation") === null)
assert(config.options.getProperty("Workgroup") === "my-own-workgroup")
assert(config.options.getProperty("LogPath") === "logs/application.log")
assert(config.getTmpStagingDir.isEmpty)
assert(config.readOnly.value === false)
Expand Down
Loading