Spark 无法在分区和追加模式下写入新的 Hive 表


  1. Hive 中创建了一个partitionedORC格式的新表。
  2. 使用appendorcpartitioned模式使用 Spark 写入此表。

它失败,但出现异常:

org.apache.spark.sql.AnalysisException: The format of the existing table test.table1 is `HiveFileFormat`. It doesn't match the specified format `OrcFileFormat`.;
  1. 我在编写时将格式从"兽人"更改为"hive"。它仍然失败,但异常: Spark无法理解表的底层结构。

所以这个问题的发生是因为spark is not able to write into hive table in append mode , because it cant create a new table.我能够做overwrite successfully because spark creates a table again.

但我的用例是从开始写入追加模式。InsertInto also does not work specifically for partitioned tables.我的用例几乎被阻止了。任何帮助都会很棒。

编辑1:在HDP 3.1.0环境中工作。

火花版本是2.3.2

蜂巢版本是 3.1.0

编辑 2:

// Reading the table 
val inputdf=spark.sql("select id,code,amount from t1")
//writing into table
inputdf.write.mode(SaveMode.Append).partitionBy("code").format("orc").saveAsTable("test.t2")

编辑 3:使用 insertInto((

val df2 =spark.sql("select id,code,amount from t1")
df2.write.format("orc").mode("append").insertInto("test.t2");

我得到的错误是:

20/05/17 19:15:12 WARN SessionState: METASTORE_FILTER_HOOK will be ignored, since hive.security.authorization.manager is set to instance of HiveAuthorizerFactory.
20/05/17 19:15:12 WARN SessionState: METASTORE_FILTER_HOOK will be ignored, since hive.security.authorization.manager is set to instance of HiveAuthorizerFactory.
20/05/17 19:15:13 WARN AcidUtils: Cannot get ACID state for test.t1 from null
20/05/17 19:15:13 WARN AcidUtils: Cannot get ACID state for test.t1 from null
20/05/17 19:15:13 WARN HiveMetastoreCatalog: Unable to infer schema for table test.t1 from file format ORC (inference mode: INFER_AND_SAVE). Using metastore schema.

如果我重新运行插入命令,我得到以下异常:

20/05/17 19:16:37 ERROR Hive: MetaException(message:The transaction for alter partition did not commit successfully.)
at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$alter_partitions_req_result$alter_partitions_req_resultStandardScheme.read(ThriftHiveMetastore.java)
at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$alter_partitions_req_result$alter_partitions_req_resultStandardScheme.read(ThriftHiveMetastore.java)

Hive 元存储日志中的错误:

2020-05-17T21:17:43,891 INFO  [pool-8-thread-198]: metastore.HiveMetaStore (HiveMetaStore.java:logInfo(907)) - 163: alter_partitions : tbl=hive.test.t1
2020-05-17T21:17:43,891 INFO  [pool-8-thread-198]: HiveMetaStore.audit (HiveMetaStore.java:logAuditEvent(349)) - ugi=X@A.ORG  ip=10.10.1.36   cmd=alter_partitions : tbl=hive.test.t1
2020-05-17T21:17:43,891 INFO  [pool-8-thread-198]: metastore.HiveMetaStore (HiveMetaStore.java:alter_partitions_with_environment_context(5119)) - New partition values:[BR]
2020-05-17T21:17:43,913 ERROR [pool-8-thread-198]: metastore.ObjectStore (ObjectStore.java:alterPartitions(4397)) - Alter failed
org.apache.hadoop.hive.metastore.api.MetaException: Cannot change stats state for a transactional table without providing the transactional write state for verification (new write ID -1, valid write IDs null; current state null; new state {}

我能够通过在我的用例中使用外部表来解决问题。我们目前在火花中有一个悬而未决的问题,这与蜂巢的酸性有关。一旦我在外部模式下创建 hive 表,我就可以在分区/非分区表中执行追加操作。 https://issues.apache.org/jira/browse/SPARK-15348

相关内容

  • 没有找到相关文章

最新更新