Skip to content

Commit 9f9ae8f

Browse files
authored
fix: Validating object store configs should not throw exception (#2308)
1 parent d67ef7a commit 9f9ae8f

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

spark/src/main/scala/org/apache/comet/rules/CometScanRule.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,18 @@ object CometScanRule extends Logging {
434434
configValidityMap.get(cacheKey) match {
435435
case Some(Some(reason)) =>
436436
fallbackReasons += reason
437-
throw new CometNativeException(reason)
438437
case Some(None) =>
439438
// previously validated
440439
case _ =>
441440
try {
442441
val objectStoreOptions = JavaConverters.mapAsJavaMap(objectStoreConfigMap)
443442
Native.validateObjectStoreConfig(filePath, objectStoreOptions)
444443
} catch {
445-
case e: Exception =>
444+
case e: CometNativeException =>
446445
val reason = "Object store config not supported by " +
447446
s"$SCAN_NATIVE_ICEBERG_COMPAT: ${e.getMessage}"
448447
fallbackReasons += reason
449448
configValidityMap.put(cacheKey, Some(reason))
450-
throw e
451449
}
452450
}
453451

spark/src/test/scala/org/apache/comet/objectstore/NativeConfigSuite.scala

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ package org.apache.comet.objectstore
2222
import java.net.URI
2323

2424
import scala.collection.mutable
25-
import scala.util.Try
2625

2726
import org.scalatest.BeforeAndAfterEach
2827
import org.scalatest.funsuite.AnyFunSuite
2928
import org.scalatest.matchers.should.Matchers
3029

3130
import org.apache.hadoop.conf.Configuration
3231

33-
import org.apache.comet.CometNativeException
3432
import org.apache.comet.rules.CometScanRule
3533

3634
class NativeConfigSuite extends AnyFunSuite with Matchers with BeforeAndAfterEach {
@@ -98,23 +96,20 @@ class NativeConfigSuite extends AnyFunSuite with Matchers with BeforeAndAfterEac
9896
test("validate object store config - invalid provider") {
9997
val hadoopConf = new Configuration()
10098
hadoopConf.set("fs.s3a.aws.credentials.provider", "invalid")
101-
val e = intercept[CometNativeException] {
102-
validate(hadoopConf)
103-
}
104-
assert(e.getMessage.contains("Unsupported credential provider: invalid"))
99+
val fallbackReasons = validate(hadoopConf)
100+
val expectedError = "Unsupported credential provider: invalid"
101+
assert(fallbackReasons.exists(_.contains(expectedError)))
105102
}
106103

107104
test("validate object store config - mixed anonymous providers") {
108105
val hadoopConf = new Configuration()
109106
val provider1 = "com.amazonaws.auth.AnonymousAWSCredentials"
110107
val provider2 = "software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider"
111108
hadoopConf.set("fs.s3a.aws.credentials.provider", Seq(provider1, provider2).mkString(","))
112-
val e = intercept[CometNativeException] {
113-
validate(hadoopConf)
114-
}
109+
val fallbackReasons = validate(hadoopConf)
115110
val expectedError =
116111
"Anonymous credential provider cannot be mixed with other credential providers"
117-
assert(e.getMessage.contains(expectedError))
112+
assert(fallbackReasons.exists(_.contains(expectedError)))
118113
}
119114

120115
test("validity cache") {
@@ -125,19 +120,20 @@ class NativeConfigSuite extends AnyFunSuite with Matchers with BeforeAndAfterEac
125120

126121
assert(CometScanRule.configValidityMap.isEmpty)
127122
for (_ <- 0 until 5) {
128-
assert(Try(validate(hadoopConf)).isFailure)
123+
assert(validate(hadoopConf).nonEmpty)
129124
assert(CometScanRule.configValidityMap.size == 1)
130125
}
131126

132127
// set the same providers but in a different order
133128
hadoopConf.set("fs.s3a.aws.credentials.provider", Seq(provider2, provider1).mkString(","))
134-
assert(Try(validate(hadoopConf)).isFailure)
129+
assert(validate(hadoopConf).nonEmpty)
135130
assert(CometScanRule.configValidityMap.size == 2)
136131
}
137132

138-
private def validate(hadoopConf: Configuration): Unit = {
133+
private def validate(hadoopConf: Configuration): Set[String] = {
139134
val path = "s3a://path/to/file.parquet"
140135
val fallbackReasons = mutable.ListBuffer[String]()
141136
CometScanRule.validateObjectStoreConfig(path, hadoopConf, fallbackReasons)
137+
fallbackReasons.toSet
142138
}
143139
}

0 commit comments

Comments
 (0)