apache-spark - 在 pyspark 中激活 HIVE 上的 ACID 缺少什么?
问题描述
我想更新配置单元表中的一些行。由于 pyspark 根本无法识别 UPDATE,因此我选择了 DELETE 和 INSERT,但在 DELETE 操作中却出现“不允许操作”。
为了解决这个问题,我将表指定为 orc 并尝试了此站点上提到的其余要求:https ://cwiki.apache.org/confluence/display/Hive/Hive+Transactions#HiveTransactions-Limitations
我还设置了tableproperty“transactional”=“true”。下面你会看到一些我如何尝试设置属性的代码
sqlCtx.sql("""SET spark.hadoop.hive.support.concurrency=true""")
sqlCtx.sql("""SET spark.hadoop.hive.enforce.bucketing=true""")
sqlCtx.sql("""SET spark.hadoop.hive.exec.dynamic.partition.mode=nonstrict""")
sqlCtx.sql("""SET spark.hadoop.hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager""")
sqlCtx.sql("""SET spark.hadoop.hive.lock.manager=org.apache.hadoop.hive.ql.lockmgr.zookeeper.ZooKeeperHiveLockManager""")
sqlCtx.sql("""SET spark.hadoop.hive.compactor.initiator.on=true""")
sqlCtx.sql("""SET spark.hadoop.hive.compactor.worker.threads=1""")
# Some other stuff happens creating the values etc
# Then I create the table from another table as orc
sqlCtx.sql("CREATE TABLE " + name + " AS SELECT * FROM new_base AS orc")
sqlCtx.sql("ALTER TABLE " + name + """ SET TBLPROPERTIES("transactional"="true")""")
# This will now result in Operation not allowed
sqlCtx.sql("DELETE FROM " + name) # I didn't keep the Where clause as it makes no difference so the error is not in the missing Where clause
我希望 DELETE 子句能做点什么,至少由于缺少 Where 子句而引发错误,但我只得到 pyspark.sql.utils.ParseException: '\nOperation not allowed: DELETE FROM ...
如果创建表的完整代码示例更有用,请写在评论中,我将添加它,我将其保留以提高可读性。我还应该注意,这是完全在本地运行的。
解决方案
我认为您应该在文件 hive-site.xml 中添加相应的配置单元配置
此外,只有在您运行单独的配置单元服务器并且您必须针对配置单元服务器触发查询时,配置单元事务功能才会起作用。spark中的hive只是嵌入的metastore(用于存储spark完成的元数据处理)。由于嵌入式 Metastore 没有配置单元服务器,它不会工作。
要使用事务,您需要安装 hive 并在 hive-site.xml 中设置这些属性,然后使用 spark 连接到 hive 服务器 url 参考 https://github.com/Gowthamsb12/Spark/blob/master/Spark_ACID 如何访问 HIVE ACID Spark sql中的表?
例如对应的配置单元属性
spark.hadoop.hive.support.concurrency=true
为
<property>
<name>hive.support.concurrency</name>
<value>true</value>
</property>
推荐阅读
- firebase - Firebase pod 未正确安装
- java - 在不更改错误响应正文或状态码的情况下记录 Spring Boot 控制器异常
- python - Python 中的类型错误:'function' 对象在 Python 中不可支持
- c - 在标头中使用来自不同文件的结构
- azure - 您如何将 user_impersonation {scope} 的 api 权限授予另一个 azure 广告应用
- assembly - 让自定义操作系统在 Virtualbox 上启动
- mongodb - 变量“形式”不存在。Symfony 4
- javascript - 使用 fromNow() 时的区域设置
- hadoop - unixODBC isql 设置配置单元配置变量
- ruby - Ruby 在处理大文件时搜索和合并 CSV 文件