在 Hive 中无法访问通过 Spark 加载的表 [英] Table loaded through Spark not accessible in Hive

查看:49
本文介绍了在 Hive 中无法访问通过 Spark 加载的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法从 Hive 访问通过 Spark (pyspark) 创建的 Hive 表.

Hive table created through Spark (pyspark) are not accessible from Hive.

df.write.format("orc").mode("overwrite").saveAsTable("db.table")

从 Hive 访问时出错:

Error while accessing from Hive:

错误:java.io.IOException:java.lang.IllegalArgumentException:bucketId 超出范围:-1 (state=,code=0)

Error: java.io.IOException: java.lang.IllegalArgumentException: bucketId out of range: -1 (state=,code=0)

在 Hive 中成功创建表并能够在 spark 中读取此表.表元数据可访问(在 Hive 中)和表中的数据文件(在 hdfs 中).

Table getting created successfully in Hive and able to read this table back in spark. Table metadata is accessible (in Hive) and data file in table (in hdfs) directory.

Hive 表的 TBLPROPERTIES 是:

TBLPROPERTIES of Hive table are :

  'bucketing_version'='2',                         
  'spark.sql.create.version'='2.3.1.3.0.0.0-1634', 
  'spark.sql.sources.provider'='orc',              
  'spark.sql.sources.schema.numParts'='1',

我也尝试使用其他解决方法创建表,但在创建表时出错:

I also tried creating table with other workarounds but getting error while creating table:

df.write.mode("overwrite").saveAsTable("db.table")

df.createOrReplaceTempView("dfTable")
spark.sql("CREATE TABLE db.table AS SELECT * FROM dfTable")

错误:

AnalysisException: u'org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Table default.src failed strict managed table checks 由于以下原因:表被标记为托管表但不是交易.);'

AnalysisException: u'org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:Table default.src failed strict managed table checks due to the following reason: Table is marked as a managed table but is not transactional.);'

堆栈版本详细信息:

Spark2.3

Hive3.1

Hortonworks 数据平台 HDP3.0

Hortonworks Data Platform HDP3.0

推荐答案

从 HDP 3.0 开始,Apache Hive 和 Apache Spark 的目录是分开的,它们使用自己的目录;即它们是互斥的 - Apache Hive 目录只能被 Apache Hive 或这个库访问,而 Apache Spark 目录只能被 Apache Spark 中的现有 API 访问.换句话说,某些功能,例如 ACID 表或带有 Apache Hive 表的 Apache Ranger 只能通过 Apache Spark 中的这个库使用.不应在 Apache Spark API 本身中直接访问 Hive 中的这些表.

From HDP 3.0, catalogs for Apache Hive and Apache Spark are separated, and they use their own catalog; namely, they are mutually exclusive - Apache Hive catalog can only be accessed by Apache Hive or this library, and Apache Spark catalog can only be accessed by existing APIs in Apache Spark . In other words, some features such as ACID tables or Apache Ranger with Apache Hive table are only available via this library in Apache Spark. Those tables in Hive should not directly be accessible within Apache Spark APIs themselves.

  • 下面的文章解释了这些步骤:

集成Apache Hive 与 Apache Spark - Hive 仓库连接器

这篇关于在 Hive 中无法访问通过 Spark 加载的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆