2016-07-04 79 views
0

有谁知道是什么原因导致了这个错误?看起来很基本。Spark set_hadoop_config错误

在:

def set_hadoop_config(credentials): 
prefix = "fs.swift.service." + credentials['name'] 
hconf = sc._jsc.hadoopConfiguration() 
hconf.set(prefix + ".auth.url", credentials['auth_url']+'/v2.0/tokens') 
hconf.set(prefix + ".auth.endpoint.prefix", "endpoints") 
hconf.set(prefix + ".tenant", credentials['project_id']) 
hconf.set(prefix + ".username", credentials['user_id']) 
hconf.set(prefix + ".password", credentials['password']) 
hconf.setInt(prefix + ".http.port", 8080) 
hconf.set(prefix + ".region", credentials['region']) 

日期:

Name: Compile Error Message: :1: error: ':' expected but ')' found. def set_hadoop_config(credentials): ^StackTrace:

谢谢!

+0

听起来像一个语法错误。在代码中的某处,如果您应该放置冒号,则应放置圆括号 –

+0

这是一个新的笔记本,不幸的是第一行代码。 Thx – Tak

+0

当我执行问题中显示的代码时,第二行中会出现关于缺少缩进的错误。当我缩进除第一行以外的所有内容时,它会执行而不会出现问题。我在一个新创建的笔记本上尝试过。 也许你在实际的代码中忽略了一些空白或其他特殊字符? –

回答

0

此代码有两个问题。

  1. 它是一个Python代码片段,但在Scala内核中执行,它需要有效的Scala代码。你可以使用Kernel-> Change Kernel菜单选项来切换内核。这是你看到的CompileError的原因。

  2. 如果使用Python内核执行,您将收到IndentationError,因为函数体没有正确缩进。改用:


    def set_hadoop_config(credentials): 
     prefix = "fs.swift.service." + credentials['name'] 
     hconf = sc._jsc.hadoopConfiguration() 
     hconf.set(prefix + ".auth.url", credentials['auth_url']+'/v2.0/tokens') 
     hconf.set(prefix + ".auth.endpoint.prefix", "endpoints") 
     hconf.set(prefix + ".tenant", credentials['project_id']) 
     hconf.set(prefix + ".username", credentials['user_id']) 
     hconf.set(prefix + ".password", credentials['password']) 
     hconf.setInt(prefix + ".http.port", 8080) 
     hconf.set(prefix + ".region", credentials['region']) 

(提示:在笔记本电脑中,选择完整的函数体和命中Tab一次缩进吧)