【问题标题】:SparkSQL insert into Hive table failedSparkSQL 插入 Hive 表失败
【发布时间】:2016-03-29 18:26:17
【问题描述】:

我是 Spark 的初学者,我尝试通过 SparkSQL 将数据插入 Hive 表,但出现错误 java.lang.ArrayIndexOutOfBoundsException: 0 在 org.apache.spark.sql.catalyst.expressions.GenericRow.isNullAt(rows.scala:79)

请在下面找到我的代码:

public class HiveWriter {

public static class IPCCount implements Serializable {
    public IPCCount(int permid, int year, String ipc, int count) {
        this.permid = permid;
        this.year = year;
        this.ipc = ipc;
        this.count = count;
    }

    public int permid;
    public int year;
    public int count = 0;
    public String ipc;
}

public static void main(String[] args) {
    SparkConf sparkConf = new SparkConf().setAppName("HiveWriter");
    JavaSparkContext sc = new JavaSparkContext(sparkConf);
    HiveContext sqlContext = new org.apache.spark.sql.hive.HiveContext(sc.sc());

    JavaRDD<IPCCount> lines = sc.parallelize(Arrays.asList(new IPCCount(000000000, 2010, "000000000", 10)));
    DataFrame df = sqlContext.createDataFrame(lines, IPCCount.class);
    df.registerTempTable("ipc_codes_new");
    sqlContext.sql("INSERT INTO TABLE xademo.ipc_codes SELECT * FROM ipc_codes_new");

    sc.close();
}}

从 Hive 表中读取效果很好,但我无法插入数据。 我还测试过临时表中的数据是否存在。

我使用 Spark 1.3。

提前致谢!

【问题讨论】:

    标签: java hadoop apache-spark apache-spark-sql


    【解决方案1】:

    如果我没记错的话,registerTempTable 不会使表 ipc_codes_new 可用于配置单元,换句话说,临时表对实际的配置单元表不可见。

    该临时表可以由 Spark 上的 HiveContext(作为临时源)使用,但不能由 Hive 本身使用。您发送的 INSERT 查询直接发送到 Hive 本身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-09
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      相关资源
      最近更新 更多