2016-07-04 38 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一次縮進吧)