From c6b274a1ed6903581097c240e69971dfb0c28a19 Mon Sep 17 00:00:00 2001 From: Chen Dai Date: Fri, 6 Oct 2023 15:43:53 -0700 Subject: [PATCH] Refactor validate method Signed-off-by: Chen Dai --- .../flint/spark/FlintSparkIndexOptions.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexOptions.scala b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexOptions.scala index 4db83cfff..b3e7535c3 100644 --- a/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexOptions.scala +++ b/flint-spark-integration/src/main/scala/org/opensearch/flint/spark/FlintSparkIndexOptions.scala @@ -5,9 +5,7 @@ package org.opensearch.flint.spark -import org.opensearch.flint.spark.FlintSparkIndexOptions.OptionName.{ - AUTO_REFRESH, CHECKPOINT_LOCATION, INDEX_SETTINGS, OptionName, REFRESH_INTERVAL -} +import org.opensearch.flint.spark.FlintSparkIndexOptions.OptionName.{AUTO_REFRESH, CHECKPOINT_LOCATION, INDEX_SETTINGS, OptionName, REFRESH_INTERVAL} import org.opensearch.flint.spark.FlintSparkIndexOptions.validateOptionNames /** @@ -89,12 +87,16 @@ object FlintSparkIndexOptions { val INDEX_SETTINGS: OptionName.Value = Value("index_settings") } - // This method has to be here otherwise Scala compilation failure + /** + * Validate option names and throw exception if any unknown found. + * + * @param options + * options given + */ def validateOptionNames(options: Map[String, String]): Unit = { - val allowedNames = OptionName.values.map(_.toString) - val unknownNames = options.keys.filterNot(allowedNames.contains) + val allOptions = OptionName.values.map(_.toString) + val invalidOptions = options.keys.filterNot(allOptions.contains) - require(unknownNames.isEmpty, - s"option name ${unknownNames.mkString(",")} is invalid") + require(invalidOptions.isEmpty, s"option name ${invalidOptions.mkString(",")} is invalid") } }