“INSERT INTO …” with SparkSQL HiveContext

前端 未结 6 1336
你的背包
你的背包 2021-02-05 05:32

I\'m trying to run an insert statement with my HiveContext, like this:

hiveContext.sql(\'insert into my_table (id, score) values (1, 10)\')

Th

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 05:43

    The accepted answer saveAsTable fails for me with an AnalysisException (I don't understand why). What works for me instead is:

    data = hc.sql("select 1 as id, 10 as score")
    data.write.mode("append").insertInto("my_table")
    

    I'm using Spark v2.1.0.

提交回复
热议问题