简体   繁体   English

从 Spark 向 Hive 表插入记录

[英]Insert record to Hive table from Spark

I am trying to insert records into Hive table from Spark ( Scala ).我正在尝试从Spark ( Scala ) 向Hive表中插入记录。 The values that I am trying to insert are structured data that come as a case class.我尝试插入的值是作为案例类出现的结构化数据。

Here is what I have:这是我所拥有的:

case class rcd(
  request: Int,
  extract_id: Int)
}

Then:然后:

DF.as[rcd].take(DF.count.toInt).foreach(e => { // DF is a dataframe that contains data

if <condition> {
       ss.sql(s"""INSERT INTO mytable select $e.request ,'$e.extract_id'""")
}

I am getting an error:我收到一个错误:

Undefined function: 'rcd'.未定义的函数:'rcd'。 This function is neither a registered temporary function nor a permanent function registered in the database 'default'.;此函数既不是已注册的临时函数,也不是在数据库“default”中注册的永久函数。

Also, what is the 'default' that Spark mentioned in the previous message另外, Spark在上一条消息中提到的'default'是什么

Any comments will be appreciated任何意见将不胜感激

Did you register your udf function?你注册你的udf函数了吗?

If not please register the udf function with the SQLContext's UDF Registry.如果没有,请向 SQLContext 的 UDF 注册表注册 udf 函数。

sqlContext.udf.register("RCD", rcd)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM