简体   繁体   English

Hive 表计数通过 java JDBC 驱动程序显示为 0

[英]Hive table count is showing 0 via java JDBC driver

I am getting 0 record when i am accessing hive table from JDBC via java.当我通过 java 从 JDBC 访问 hive 表时,我得到了 0 条记录。 But the same query from beeline it is working fine and showing some number.但是来自 beeline 的相同查询工作正常并显示了一些数字。 what could be the reason.?可能是什么原因。?

The behaviour you are seeing may be due to stale stats for certain tables in HiveMetastore and if these are referred by the queries.您看到的行为可能是由于 HiveMetastore 中某些表的陈旧统计信息以及这些是否由查询引用。

To test this, you can check by running set hive.compute.query.using.stats;要对此进行测试,您可以通过运行set hive.compute.query.using.stats;来检查set hive.compute.query.using.stats; on both Beeline-Hive and JDBC Client session to see if the value set for the property is TRUE or FALSE.在 Beeline-Hive 和 JDBC Client 会话上查看为该属性设置的值是 TRUE 还是 FALSE。

If TRUE, the query would fetch the statistics from HiveMetastore.如果为 TRUE,则查询将从 HiveMetastore 获取统计信息。 (this is usually faster since it fetches the count from HiveMetastore and not by executing a MapReduce job. But it may return incorrect/stale count if the statistics are not updated in HiveMetastore for the table) (这通常更快,因为它从 HiveMetastore 获取计数,而不是通过执行 MapReduce 作业。但如果没有在 HiveMetastore 中为表更新统计信息,它可能会返回不正确/过时的计数)

If FALSE, the query runs a MapReduce as a part of the execution and performs the count from the records present in the data files in HDFS.如果为 FALSE,则查询运行 MapReduce 作为执行的一部分,并根据 HDFS 中数据文件中的记录执行计数。 This is time consuming when compared to the previous one but returns accurate results.与前一个相比,这很耗时,但会返回准确的结果。

Solution:解决方案:

  1. You can set the property hive.compute.query.using.stats to false by running the below statement in Beeline-Hive and JDBC Client sessions.您可以通过在 Beeline-Hive 和 JDBC Client 会话中运行以下语句将属性hive.compute.query.using.stats设置为 false。 This way, Hive would perform count on the basis of data present in HDFS through a MapReduce job.这样,Hive 将通过 MapReduce 作业根据 HDFS 中存在的数据执行计数。
set hive.compute.query.using.stats=false;

OR或者

  1. Compute statistics for the tables manually by running the below statement in either Beeline-Hive or JDBC Client sessions.通过在 Beeline-Hive 或 JDBC Client 会话中运行以下语句,手动计算表的统计信息。 This will update the HiveMetastore with updated statistics.这将使用更新的统计信息更新 HiveMetastore。 After this count(*) should return correct results in any Hive sessions for that table.在此之后count(*)应该在该表的任何 Hive 会话中返回正确的结果。
ANALYZE TABLE <database_name>.<table_name> COMPUTE STATISTICS;

Hope this helps!希望这可以帮助!

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

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