我正在尝试从配置单元表中读取数据,然后添加具有空值的加法列。通过使用此选项,我得到以下错误:
Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve '`address_1`' given input columns: [postalcode, first_name, organization_name, application_number, type, last_name, country];;
实际上,地址\u 1不是配置单元中的列,正在尝试使用默认值“null”添加此列。
到目前为止我尝试的是:
val ipa_agent = hiveContext.sql("select * from agent")
val df1 = ipa_agent.withColumn("address_1",lit("null"))
除了withcolumn,还有其他方法添加列吗?
2条答案
按热度按时间htrmnn0y1#
列出查询中的所有列+附加列:
htrmnn0y2#
我尝试使用withcolumn添加一个新列,它对我来说很好
另一个选项是,您可以尝试leftjoin提到的方法,即提及所有列的名称,并在末尾添加address1作为null。