【发布时间】: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