Skip to content

Commit d0f5754

Browse files
committed
added Java doc
Signed-off-by: Kaituo Li <[email protected]>
1 parent 7bde55d commit d0f5754

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

spark-sql-application/src/main/scala/org/apache/spark/sql/util/EnvironmentProvider.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
package org.apache.spark.sql.util
77

8+
/**
9+
* Trait defining an interface for fetching environment variables.
10+
*/
811
trait EnvironmentProvider {
12+
/**
13+
* Retrieves the value of an environment variable.
14+
*
15+
* @param name The name of the environment variable.
16+
* @param default The default value to return if the environment variable is not set.
17+
* @return The value of the environment variable if it exists, otherwise the default value.
18+
*/
919
def getEnvVar(name: String, default: String): String
1020
}

spark-sql-application/src/main/scala/org/apache/spark/sql/util/RealEnvironment.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
package org.apache.spark.sql.util
77

8+
/**
9+
* An implementation of `EnvironmentProvider` that fetches actual environment variables from the system.
10+
*/
811
class RealEnvironment extends EnvironmentProvider {
12+
/**
13+
* Retrieves the value of an environment variable from the system or returns a default value if not present.
14+
*
15+
* @param name The name of the environment variable.
16+
* @param default The default value to return if the environment variable is not set in the system.
17+
* @return The value of the environment variable if it exists in the system, otherwise the default value.
18+
*/
919
def getEnvVar(name: String, default: String): String = sys.env.getOrElse(name, default)
1020
}

spark-sql-application/src/test/scala/org/apache/spark/sql/util/MockEnvironment.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
package org.apache.spark.sql.util
77

8+
/**
9+
* A mock implementation of `EnvironmentProvider` for use in tests, where environment variables can be predefined.
10+
*
11+
* @param inputMap A map representing the environment variables (name -> value).
12+
*/
813
class MockEnvironment(inputMap: Map[String, String]) extends EnvironmentProvider {
14+
/**
15+
* Retrieves the value of an environment variable from the input map or returns a default value if not present.
16+
*
17+
* @param name The name of the environment variable.
18+
* @param default The default value to return if the environment variable is not set in the input map.
19+
* @return The value of the environment variable from the input map if it exists, otherwise the default value.
20+
*/
921
def getEnvVar(name: String, default: String): String = inputMap.getOrElse(name, default)
1022
}

0 commit comments

Comments
 (0)