简体   繁体   English

我如何使用 pyspark 显示 hive 表

[英]How can i show hive table using pyspark

Hello i created a spark HD insight cluster on azure and i'm trying to read hive tables with pyspark but the proble that its show me only default database你好,我在 azure 上创建了一个 spark HD insight 集群,我正在尝试使用 pyspark 读取 hive 表,但问题是它只显示默认数据库

Anyone have an idea?有人有想法吗?

If you are using HDInsight 4.0, Spark and Hive not share metadata anymore.如果您使用的是 HDInsight 4.0,Spark 和 Hive 将不再共享元数据。

For default you will not see hive tables from pyspark, is a problem that i share on this post: How save/update table in hive, to be readbale on spark .默认情况下,您不会看到 pyspark 中的 hive 表,这是我在这篇文章中分享的一个问题: How save/update table in hive, to be readbale on spark

But, anyway, things you can try:但是,无论如何,您可以尝试的事情:

  1. If you want test only on head node, you can change the hive-site.xml, on property "metastore.catalog.default" , change the value to hive , after that open pyspark from command line.如果只想在头节点上进行测试,可以更改 hive-site.xml,在属性“metastore.catalog.default”上,将值更改为hive ,然后从命令行打开 pyspark。
  2. If you want to apply to all cluster nodes, changes need to be made on Ambari.如果要应用于所有集群节点,需要在 Ambari 上进行更改。
    • Login as admin on ambari以管理员身份登录ambari
    • Go to spark2 > Configs > hive-site-override Go 到 spark2 > Configs > hive-site-override
    • Again, update property "metastore.catalog.default" , to hive value再次,将属性“metastore.catalog.default”更新为hive
    • Restart all required on Ambari panel重新启动 Ambari 面板上的所有必需项

These changes define hive metastore catalog as default.这些更改将 hive 元存储目录定义为默认值。 You can see hive databases and table now, but depending of table structure, you will not see the table data properly.您现在可以看到 hive 个数据库和表,但是根据表结构,您将无法正常看到表数据。

If you have created tables in other databases, try show tables from database_name .如果您在其他数据库中创建了表,请尝试show tables from database_name Replace database_name with the actual name.database_name替换为实际名称。

You are missing details of hive server in SparkSession.您在 SparkSession 中缺少 hive 服务器的详细信息。 If you haven't added any it will create and use default database to run sparksql.如果您没有添加任何内容,它将创建并使用默认数据库来运行 sparksql。

If you've added configuration details in spark default conf file for spark.sql.warehouse.dir and spark.hadoop.hive.metastore.uris then while creating SparkSession add enableHiveSupport().如果您已在spark.sql.warehouse.dir 和 spark.hadoop.hive.metastore.uris的 spark 默认配置文件中添加了配置详细信息,则在创建 SparkSession 时添加 enableHiveSupport()。

Else add configuration details while creating sparksession否则在创建 sparksession 时添加配置详细信息

.config("spark.sql.warehouse.dir","/user/hive/warehouse")
.config("hive.metastore.uris","thrift://localhost:9083")
.enableHiveSupport()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM