scala—我试图使用collect操作从dataframe读取以下字段,但它引发了java nullpointer异常

hi3rlvi2  于 2021-06-24  发布在  Hive
关注(0)|答案(0)|浏览(243)
val db_query="(select
                 a.id,
                 conn_owner,
                 applicationname,
                 IsDuplicateConnection
              from ingestion.connections_metadata
              a inner join ingestion.connectionlnk_data b on
              a.id=b.connection_id inner join ingestion.application c on 
              b.application_id = c.id where a.id =23)db_query"

//为此创建df

val dbname= spark.read.format("jdbc")
            .option("driver",com.microsoft.sqlserver.jdbc.SQLServerDriver)
            .option("url",jdbc:sqlserver://sjmnb008hv.in.com:1433/ompm)
            .option("user",MysqlUser)
            .option("password", Password)
            .option("dbtable", db_query)
            .load()

//然后在此数据框上应用collect

dbname.collect.foreach{ x=>
    var owner_name=x.get(1)

    if(x.get(3).toString()=='Y'){
        hive_db = hive_db.tolowerCase() + "_" 
                  + x.get(2).tostring().toLowerCase()
                     .replace(" ","").replace("-","_")
    }
}

所以这里的x.get(3)将取空值,默认值是n。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题