gpt4 book ai didi

hadoop - 实时设置环境变量。谷歌大查询

转载 作者:可可西里 更新时间:2023-11-01 15:57:23 25 4
gpt4 key购买 nike

我正在为 spark 编写一个 google 大查询连接器,并在它下面使用 google hadoop 连接器。

目前,google hadoop 连接器需要一个指向 creds json 文件的 Google env 变量。

当您在 dataproc 世界之外启动集群时,这可能会很烦人

在代码中实时设置是不是不好的做法?还是有一种变通方法告诉 hadoop 连接器忽略 env 变量,因为它是在“fs.gs.auth.service.account.json.keyfile”hadoop 配置中设置的?

Dennis既然你是这个项目的贡献者,也许这次你也能帮忙?

最佳答案

对于那些感兴趣的人,我只是在运行时使用以下 scala 中的要点设置它们

https://gist.github.com/jaytaylor/770bc416f0dd5954cf0f

但这里是代码,以防 gist 离线

trait EnvHacker {
/**
* Portable method for setting env vars on both *nix and Windows.
* @see http://stackoverflow.com/a/7201825/293064
*/
def setEnv(newEnv: Map[String, String]): Unit = {
try {
val processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment")
val theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment")
theEnvironmentField.setAccessible(true)
val env = theEnvironmentField.get(null).asInstanceOf[JavaMap[String, String]]
env.putAll(newEnv)
val theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment")
theCaseInsensitiveEnvironmentField.setAccessible(true)
val cienv = theCaseInsensitiveEnvironmentField.get(null).asInstanceOf[JavaMap[String, String]]
cienv.putAll(newEnv)
} catch {
case e: NoSuchFieldException =>
try {
val classes = classOf[Collections].getDeclaredClasses()
val env = System.getenv()
for (cl <- classes) {
if (cl.getName() == "java.util.Collections$UnmodifiableMap") {
val field = cl.getDeclaredField("m")
field.setAccessible(true)
val obj = field.get(env)
val map = obj.asInstanceOf[JavaMap[String, String]]
map.clear()
map.putAll(newEnv)
}
}
} catch {
case e2: Exception => e2.printStackTrace()
}

case e1: Exception => e1.printStackTrace()
}
}

关于hadoop - 实时设置环境变量。谷歌大查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42344121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com