From d0f5754f6e491c92deba88d9042e26ac60eb978f Mon Sep 17 00:00:00 2001 From: Kaituo Li Date: Thu, 8 Feb 2024 13:50:32 -0800 Subject: [PATCH] added Java doc Signed-off-by: Kaituo Li --- .../apache/spark/sql/util/EnvironmentProvider.scala | 10 ++++++++++ .../org/apache/spark/sql/util/RealEnvironment.scala | 10 ++++++++++ .../org/apache/spark/sql/util/MockEnvironment.scala | 12 ++++++++++++ 3 files changed, 32 insertions(+) diff --git a/spark-sql-application/src/main/scala/org/apache/spark/sql/util/EnvironmentProvider.scala b/spark-sql-application/src/main/scala/org/apache/spark/sql/util/EnvironmentProvider.scala index ff167444e..e053e23fe 100644 --- a/spark-sql-application/src/main/scala/org/apache/spark/sql/util/EnvironmentProvider.scala +++ b/spark-sql-application/src/main/scala/org/apache/spark/sql/util/EnvironmentProvider.scala @@ -5,6 +5,16 @@ package org.apache.spark.sql.util +/** + * Trait defining an interface for fetching environment variables. + */ trait EnvironmentProvider { + /** + * Retrieves the value of an environment variable. + * + * @param name The name of the environment variable. + * @param default The default value to return if the environment variable is not set. + * @return The value of the environment variable if it exists, otherwise the default value. + */ def getEnvVar(name: String, default: String): String } diff --git a/spark-sql-application/src/main/scala/org/apache/spark/sql/util/RealEnvironment.scala b/spark-sql-application/src/main/scala/org/apache/spark/sql/util/RealEnvironment.scala index b01a2fdec..6121c20c7 100644 --- a/spark-sql-application/src/main/scala/org/apache/spark/sql/util/RealEnvironment.scala +++ b/spark-sql-application/src/main/scala/org/apache/spark/sql/util/RealEnvironment.scala @@ -5,6 +5,16 @@ package org.apache.spark.sql.util +/** + * An implementation of `EnvironmentProvider` that fetches actual environment variables from the system. + */ class RealEnvironment extends EnvironmentProvider { + /** + * Retrieves the value of an environment variable from the system or returns a default value if not present. + * + * @param name The name of the environment variable. + * @param default The default value to return if the environment variable is not set in the system. + * @return The value of the environment variable if it exists in the system, otherwise the default value. + */ def getEnvVar(name: String, default: String): String = sys.env.getOrElse(name, default) } diff --git a/spark-sql-application/src/test/scala/org/apache/spark/sql/util/MockEnvironment.scala b/spark-sql-application/src/test/scala/org/apache/spark/sql/util/MockEnvironment.scala index 637c7d91c..9b9d00821 100644 --- a/spark-sql-application/src/test/scala/org/apache/spark/sql/util/MockEnvironment.scala +++ b/spark-sql-application/src/test/scala/org/apache/spark/sql/util/MockEnvironment.scala @@ -5,6 +5,18 @@ package org.apache.spark.sql.util +/** + * A mock implementation of `EnvironmentProvider` for use in tests, where environment variables can be predefined. + * + * @param inputMap A map representing the environment variables (name -> value). + */ class MockEnvironment(inputMap: Map[String, String]) extends EnvironmentProvider { + /** + * Retrieves the value of an environment variable from the input map or returns a default value if not present. + * + * @param name The name of the environment variable. + * @param default The default value to return if the environment variable is not set in the input map. + * @return The value of the environment variable from the input map if it exists, otherwise the default value. + */ def getEnvVar(name: String, default: String): String = inputMap.getOrElse(name, default) }