spark 2.1配置单元分区添加问题orc格式

vpfxa7rd  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(458)

我使用pyspark2.1从表a到表b动态创建分区。以下是ddl

create table A (
objid bigint,
occur_date timestamp)
STORED AS ORC;

create table B (
objid bigint,
occur_date timestamp)
PARTITIONED BY (
occur_date_pt date)
STORED AS ORC;

然后我使用一个pyspark代码来确定需要合并的分区,下面是代码的一部分

for row in  incremental_df.select(partitioned_column).distinct().collect():
    path            = '/apps/hive/warehouse/B/' + partitioned_column + '=' + format(row[0])
    old_df          = merge_df.where(col(partitioned_column).isin(format(row[0])))
    new_df          = incremental_df.where(col(partitioned_column).isin(format(row[0])))
    output_df       = old_df.subtract(new_df)
    output_df       = output_df.unionAll(new_df)
    output_df.write.option("compression","none").mode("overwrite").format("orc").save(path)
    refresh_metadata_sql = 'MSCK REPAIR TABLE ' + table_name
    sqlContext.sql(refresh_metadata_sql)

在执行代码时,我可以看到hdfs中的分区
找到3个项目drwx------307010265 hdfs 0 2017-06-01 10:31/apps/hive/warehouse/b/occurse\u date\u pt=2017-06-01 drwx------307010265 hdfs 0 2017-06-01 10:31/apps/hive/warehouse/b/occurse\u date\u pt=2017-06-02 drwx------307010265 hdfs 0 2017-06-01 10:31/apps/hive/warehouse/b/occurse\u date\u pt=2017-06-03
但是当我试图访问spark中的表时,我得到了数组越界错误

>> merge_df = sqlContext.sql('select * from B')
DataFrame[]
>>> merge_df.show()
17/06/01 10:33:13 ERROR Executor: Exception in task 0.0 in stage 200.0 (TID 4827)
java.lang.IndexOutOfBoundsException: toIndex = 3
        at java.util.ArrayList.subListRangeCheck(ArrayList.java:1004)
        at java.util.ArrayList.subList(ArrayList.java:996)
        at org.apache.hadoop.hive.ql.io.orc.RecordReaderFactory.getSchemaOnRead(RecordReaderFactory.java:161)
        at org.apache.hadoop.hive.ql.io.orc.RecordReaderFactory.createTreeReader(RecordReaderFactory.java:66)
        at org.apache.hadoop.hive.ql.io.orc.RecordReaderImpl.<init>(RecordReaderImpl.java:202)
        at org.apache.hadoop.hive.ql.io.orc.ReaderImpl.rowsOptions(ReaderImpl.java:539)
        at org.apache.hadoop.hive.ql.io.orc.OrcRawRecordMerger$ReaderPair.<init>(OrcRawRecordMerger.java:183)
        at org.apache.hadoop.hive.ql.io.orc.OrcRawRecordMerger$OriginalReaderPair.<init>(OrcRawRecordMerger.java:226)
        at org.apache.hadoop.hive.ql.io.orc.OrcRawRecordMerger.<init>(OrcRawRecordMerger.java:437)
        at org.apache.hadoop.hive.ql.io.orc.OrcInputFormat.getReader(OrcInputFormat.java:1215)
        at org.apache.hadoop.hive.ql.io.orc.OrcInputFormat.getRecordReader(OrcInputFormat.java:1113)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.liftedTree1$1(HadoopRDD.scala:252)
        at org.apache.spark.rdd.HadoopRDD$$anon$1.<init>(HadoopRDD.scala:251)
        at org.apache.spark.rdd.HadoopRDD.compute(HadoopRDD.scala:211)
        at org.apache.spark.rdd.HadoopRDD.compute(HadoopRDD.scala:102)
        at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)

任何帮助或指点,以解决这个问题将不胜感激

ztmd8pv5

ztmd8pv51#

张贴评论作为一个更容易参考的答案:请确保分区列不包括在Dataframe。

相关问题