sqlContext.sql返回计数为0的表,pyspark

sqlContext.sql返回计数为0的表,pyspark,pyspark,pyspark-sql,Pyspark,Pyspark Sql,我正在运行一个spark应用程序,通过pyspark交互式shell使用EMR 我正在尝试连接到一个名为:content\u publisher\u events\u log的配置单元表,通过我的色调控制台使用完全相同的查询,我知道该表不是空的,但当我尝试通过pyspark读取它时,我得到count=0,如下所示: from pyspark.sql import HiveContext Query=""" select dt from default.content_publisher_eve

我正在运行一个spark应用程序,通过pyspark交互式shell使用EMR

我正在尝试连接到一个名为:content\u publisher\u events\u log的配置单元表,通过我的色调控制台使用完全相同的查询,我知道该表不是空的,但当我尝试通过pyspark读取它时,我得到count=0,如下所示:

from pyspark.sql import HiveContext 
Query=""" select dt
from default.content_publisher_events_log 
where  dt  between  '20170415'  and '20170419' 
"""
hive_context = HiveContext(sc)
user_data = hive_context.sql(Query)
user_data.count()
0 #that's the result
此外,从控制台中,我可以看到此表存在:

    >>> sqlContext.sql("show tables").show()
+--------+--------------------+-----------+
|database|           tableName|isTemporary|
+--------+--------------------+-----------+
| default|content_publisher...|      false|
| default|  feed_installer_log|      false|
| default|keyword_based_ads...|      false|
| default|search_providers_log|      false|
+--------+--------------------+-----------+

>>> user_data.printSchema()
root
 |-- dt: string (nullable = true)
也在spark history服务器上进行了检查-似乎运行计数的作业没有任何错误,是否知道会出现什么问题


谢谢,这是事先准备好的

dt列不是日期时间格式。正确地将列本身更改为datetime格式,或者将查询本身更改为将字符串转换为时间戳

Query=""" select dt
from default.content_publisher_events_log 
where  dt  between  
unix_timestamp('20170415','yyyyMMdd')  and 
unix_timestamp('20170419','yyyyMMdd') 
"""

似乎我们的数据团队将每个分区的拼花地板文件移动到了一个子文件夹中,他们对其进行了修复,从4月25日开始,它工作得非常完美

据我所知,如果有人面临这样的问题,请尝试类似的方法:

sqlContext.sql("SET hive.mapred.supports.subdirectories=true")
sqlContext.sql("SET mapreduce.input.fileinputformat.input.dir.recursive=true")
sc._jsc.hadoopConfiguration().set("mapreduce.input.fileinputformat.input.dir.recursive","true") 
或者这个:

sqlContext.sql("SET hive.mapred.supports.subdirectories=true")
sqlContext.sql("SET mapreduce.input.fileinputformat.input.dir.recursive=true")
sc._jsc.hadoopConfiguration().set("mapreduce.input.fileinputformat.input.dir.recursive","true") 

谢谢您的回答,我将使用此调整,尽管这不是问题: