Skip to content

Commit

Permalink
HIVE-28324: HIVE_CLUSTER_ID in env: unified way to mark a cluster (#5314
Browse files Browse the repository at this point in the history
) - addendum empty string default (#5314)
  • Loading branch information
abstractdog authored Jun 20, 2024
1 parent d2ae8a3 commit 5114a8e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ql/src/java/org/apache/hadoop/hive/ql/ServiceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ public ServiceContext(Supplier<String> host, Supplier<Integer> port) {
}

/**
* Logic for finding cluster id if any. Can be used as a utility.
* Logic for finding cluster id if any. Default value is empty string instead of null to stay safe
* with HiveConf.set().
* Precedence order: cli opt, env var, empty string
* Can be used as a utility.
*
* @return cluster id found from environment of system props
*/
public static String findClusterId() {
return System.getProperty(Constants.CLUSTER_ID_CLI_OPT_NAME, System.getenv(Constants.CLUSTER_ID_ENV_VAR_NAME));
return System.getProperty(Constants.CLUSTER_ID_CLI_OPT_NAME,
getClusterIdFromEnv());
}

private static String getClusterIdFromEnv() {
return System.getenv(Constants.CLUSTER_ID_ENV_VAR_NAME) == null ? "" : System.getenv(
Constants.CLUSTER_ID_ENV_VAR_NAME);
}

public void setClusterIdInConf(HiveConf hiveConf) {
Expand Down

0 comments on commit 5114a8e

Please sign in to comment.