Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hadoop 实时设置环境变量。谷歌大查询_Hadoop_Apache Spark_Google Bigquery - Fatal编程技术网

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

Hadoop 实时设置环境变量。谷歌大查询,hadoop,apache-spark,google-bigquery,Hadoop,Apache Spark,Google Bigquery,我正在为spark编写一个google大查询连接器,它下面使用google hadoop连接器 目前,google hadoop连接器需要一个指向creds json文件的google env变量 当您在dataproc世界之外启动集群时,这可能会很烦人 在代码中实时设置它是否不好?或者,是否有一种变通方法可以告诉hadoop连接器忽略env变量,因为它是在“fs.gs.auth.service.account.json.keyfile”hadoop配置中设置的 既然你是这个项目的贡献者,也许这

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

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

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

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


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

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

但这是代码,以防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()
    }
}
trait-EnvHacker{
/**
*用于在*nix和Windows上设置环境变量的可移植方法。
*@见http://stackoverflow.com/a/7201825/293064
*/
def setEnv(newEnv:Map[String,String]):单位={
试一试{
val processEnvironmentClass=Class.forName(“java.lang.ProcessEnvironment”)
val theEnvironmentField=processEnvironmentClass.getDeclaredField(“theEnvironment”)
环境字段。设置可访问(true)
val env=theEnvironmentField.get(null).asInstanceOf[JavaMap[String,String]]
环境putAll(新环境)
val theCaseInsensitiveEnvironmentField=processEnvironmentClass.getDeclaredField(“theCaseInsensitiveEnvironment”)
CaseInsensitiveEnvironmentField.setAccessible(true)
val cienv=theCaseInsensitiveEnvironmentField.get(null).asInstanceOf[JavaMap[String,String]]
cienv.putAll(新环境)
}抓住{
案例e:NoSuchFieldException=>
试一试{
val classes=classOf[Collections].getDeclaredClasses()
val env=System.getenv()
对于(cl e2.printStackTrace()
}
案例e1:Exception=>e1.printStackTrace()
}
}

}

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

但这是代码,以防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()
    }
}
trait-EnvHacker{
/**
*用于在*nix和Windows上设置环境变量的可移植方法。
*@见http://stackoverflow.com/a/7201825/293064
*/
def setEnv(newEnv:Map[String,String]):单位={
试一试{
val processEnvironmentClass=Class.forName(“java.lang.ProcessEnvironment”)
val theEnvironmentField=processEnvironmentClass.getDeclaredField(“theEnvironment”)
环境字段。设置可访问(true)
val env=theEnvironmentField.get(null).asInstanceOf[JavaMap[String,String]]
环境putAll(新环境)
val theCaseInsensitiveEnvironmentField=processEnvironmentClass.getDeclaredField(“theCaseInsensitiveEnvironment”)
CaseInsensitiveEnvironmentField.setAccessible(true)
val cienv=theCaseInsensitiveEnvironmentField.get(null).asInstanceOf[JavaMap[String,String]]
cienv.putAll(新环境)
}抓住{
案例e:NoSuchFieldException=>
试一试{
val classes=classOf[Collections].getDeclaredClasses()
val env=System.getenv()
对于(cl e2.printStackTrace()
}
案例e1:Exception=>e1.printStackTrace()
}
}

}

@dennis Hoo有人提到过你。嗯,我不记得环境变量是在哪里使用的;它应该只使用Hadoop配置键。你有一个指向代码中使用环境变量的地方的指针吗?@DennisHuo在创建客户端val bigquery时使用它={val credential=GoogleCredential.getApplicationDefault.createScoped(SCOPES)new Bigquery.Builder(new NetHttpTransport,new JacksonFactory,credential).setApplicationName(“spark Bigquery”).build()@dennis Hoo有人提到过你嗯,我不记得环境变量是在哪里使用的;它应该只使用Hadoop配置键。你有一个指针指向代码中使用环境变量的地方吗?@DennisHuo在创建客户端val bigquery时使用它={val credential=GoogleCredential.getApplicationDefault.createScoped(SCOPES)new Bigquery.Builder(new NetHttpTransport,new JacksonFactory,credential).setApplicationName(“spark Bigquery”).build()