2017-09-13 80 views
2

我在含有COLUMNNAMES我HDFS一个配置文件从JSON文件选择火花阶读取配置文件

JSON

{ 
    a:string 
    b:int 
    c struct 
    { 
     id: string 
     count : integer 
    } 
    } 


Config.txt 
"a","b","c.id" 

的架构在代码

val df = sqlcontext.read.json("jsonfile" 
val config_file = "Config.txt" 
val config = scala.io.Source.fromFile(config_file).mkString 
val df_contents=df.selectExpr(config) 
df_contents.printSchema() 
df_cust_att_contents.show() 

我在df.selectExpr(config)中出现错误。它不被承认。它的投掷错误。如何将列名从配置文件传递给selectExpr。请帮忙

回答

0

selectExpr每一列需要一个参数。您试图将所有列放在一个参数中。

尝试:

df.selectExpr(config.replaceAll("\"", "").split(","): _*) 
+0

嗨Gaweda,其现在的工作,非常感谢。保持摇摆人! – gayathri

+0

@gayathri所以请接受它并投票表决:) –

+0

是的,我已经投了票 – gayathri